Exemplo n.º 1
0
 public function testContainsFiles()
 {
     assertThat($this->itemTreeBounds->containsFiles(), is(true));
     $this->itemTreeBounds = new ItemTreeBounds($this->uploadTreeId, $this->uploadTreeTableName, $this->uploadId, $this->left, $this->left + 2);
     assertThat($this->itemTreeBounds->containsFiles(), is(true));
     $this->itemTreeBounds = new ItemTreeBounds($this->uploadTreeId, $this->uploadTreeTableName, $this->uploadId, $this->left, $this->left + 1);
     assertThat($this->itemTreeBounds->containsFiles(), is(false));
 }
Exemplo n.º 2
0
 private static function getConstraintCondition(ItemTreeBounds $itemTreeBounds, $constraint)
 {
     switch ($constraint) {
         case self::CONDITION_UPLOAD:
             $uploadId = $itemTreeBounds->getUploadId();
             return "upload_fk = {$uploadId}";
         case self::CONDITION_RANGE:
             $left = $itemTreeBounds->getLeft();
             $right = $itemTreeBounds->getRight();
             return "lft BETWEEN {$left} AND {$right}";
         case self::CONDITION_PLAIN_FILES:
             return '((ufile_mode & (3<<28))=0) AND pfile_fk != 0';
         default:
             throw new \InvalidArgumentException("constraint {$constraint} is not defined");
     }
 }
 public function testGetScannerDetectedLicenseDetailsNoLicenseFoundShouldBeSkipped()
 {
     $uploadId = 2;
     list($licenseMatch1, $licenseRef1, $agentRef1) = $this->createLicenseMatch(5, "No_license_found", 23, "nomos", 453, null);
     $licenseMatches = array($licenseMatch1);
     $this->itemTreeBounds->shouldReceive('getUploadId')->withNoArgs()->andReturn($uploadId);
     $this->licenseDao->shouldReceive('getAgentFileLicenseMatches')->once()->withArgs(array($this->itemTreeBounds, LicenseMap::TRIVIAL))->andReturn($licenseMatches);
     // $latestAgentDetectedLicenses = $this->agentLicenseEventProcessor->getScannerDetectedLicenseDetails($this->itemTreeBounds);
     $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
     $method = $reflection->getMethod('getScannerDetectedLicenseDetails');
     $method->setAccessible(true);
     $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor, $this->itemTreeBounds);
     assertThat($latestAgentDetectedLicenses, is(array()));
 }
 public function testMakeDecisionFromLastEventsWithNoLicenseKnownTypeAndAnExistingAddingUserEvent()
 {
     /** @var LicenseRef $licenseRef */
     list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
     $addedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName(), ClearingEventTypes::USER, $isRemoved = false);
     $isGlobal = true;
     $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")->with($this->itemTreeBounds)->andReturn(array());
     $this->clearingDao->shouldReceive("getRelevantClearingEvents")->with($this->itemTreeBounds, $this->groupId)->andReturn(array($licenseRef->getId() => $addedEvent));
     $clearingDecision = M::mock(ClearingDecision::classname());
     $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp - 3600);
     $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IRRELEVANT);
     $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
     $this->clearingDao->shouldReceive("getRelevantClearingDecision")->with($this->itemTreeBounds, $this->groupId)->andReturn($clearingDecision);
     $eventId = 65;
     $this->clearingDao->shouldReceive("insertClearingEvent")->with($this->itemTreeBounds->getItemId(), $this->userId, $this->groupId, $addedEvent->getLicenseId(), true)->andReturn($eventId);
     $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()->with($this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, DecisionScopes::REPO, array($eventId));
     $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
     $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE, $isGlobal);
 }
Exemplo n.º 5
0
 public function getLicenseShortnamesContained(ItemTreeBounds $itemTreeBounds, $latestSuccessfulAgentIds = null, $filterLicenses = array('VOID'))
 {
     $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
     $noLicenseFoundStmt = empty($filterLicenses) ? "" : " AND rf_shortname NOT IN (" . implode(", ", array_map(function ($name) {
         return "'" . $name . "'";
     }, $filterLicenses)) . ")";
     $statementName = __METHOD__ . '.' . $uploadTreeTableName;
     $agentFilter = '';
     if (is_array($latestSuccessfulAgentIds)) {
         $agentIdSet = "{" . implode(',', $latestSuccessfulAgentIds) . "}";
         $statementName .= ".{$agentIdSet}";
         $agentFilter = " AND agent_fk=ANY('{$agentIdSet}')";
     }
     $this->dbManager->prepare($statementName, "SELECT license_ref.rf_shortname\n              FROM license_file JOIN license_ref ON license_file.rf_fk = license_ref.rf_pk\n              INNER JOIN {$uploadTreeTableName} uploadTree ON uploadTree.pfile_fk=license_file.pfile_fk\n              WHERE upload_fk=\$1\n                AND lft BETWEEN \$2 AND \$3\n                {$noLicenseFoundStmt} {$agentFilter}\n              GROUP BY rf_shortname\n              ORDER BY rf_shortname ASC");
     $result = $this->dbManager->execute($statementName, array($itemTreeBounds->getUploadId(), $itemTreeBounds->getLeft(), $itemTreeBounds->getRight()));
     $licenses = array();
     while ($row = $this->dbManager->fetchArray($result)) {
         $licenses[] = $row['rf_shortname'];
     }
     $this->dbManager->freeResult($result);
     return $licenses;
 }
Exemplo n.º 6
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $groupId
  * @param int $userId
  */
 protected function markDirectoryAsIrrelevantIfUserEdited(ItemTreeBounds $itemTreeBounds, $groupId, $userId)
 {
     $statementName = __METHOD__;
     $params = array($itemTreeBounds->getLeft(), $itemTreeBounds->getRight());
     $condition = "ut.lft BETWEEN \$1 AND \$2";
     $decisionsCte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId, $onlyCurrent = true, $statementName, $params, $condition);
     $params[] = $userId;
     $a = count($params);
     $params[] = $groupId;
     $params[] = DecisionTypes::IRRELEVANT;
     $params[] = DecisionScopes::ITEM;
     $this->dbManager->prepare($statementName, $decisionsCte . ' INSERT INTO clearing_decision (uploadtree_fk,pfile_fk,user_fk,group_fk,decision_type,scope) 
       SELECT itemid,pfile_id, $' . $a . ', $' . ($a + 1) . ', $' . ($a + 2) . ', $' . ($a + 3) . ' FROM allDecs ad WHERE type_id!=$' . ($a + 2));
     $res = $this->dbManager->execute($statementName, $params);
     $this->dbManager->freeResult($res);
 }
Exemplo n.º 7
0
 public function testDeciderScanWithTwoEventAndNoAgentShouldMakeADecision()
 {
     $this->setUpTables();
     $this->setUpRepo();
     $dbManager = M::mock(DbManager::classname());
     $agentDao = M::mock(AgentDao::classname());
     $clearingDao = M::mock(ClearingDao::classname());
     $uploadDao = M::mock(UploadDao::classname());
     $highlightDao = M::mock(HighlightDao::classname());
     $decisionProcessor = M::mock(ClearingDecisionProcessor::classname());
     $agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::classname());
     $uploadId = 13243;
     /*mock for Agent class **/
     $agentDao->shouldReceive('arsTableExists')->andReturn(true);
     $agentDao->shouldReceive('getCurrentAgentId')->andReturn($agentId = 24);
     $agentDao->shouldReceive('writeArsRecord')->with(anything(), $agentId, $uploadId)->andReturn($arsId = 2);
     $agentDao->shouldReceive('writeArsRecord')->with(anything(), $agentId, $uploadId, $arsId, true)->andReturn(0);
     $jobId = 42;
     $groupId = 6;
     $userId = 2;
     $itemIds = array(4343, 43);
     $bounds0 = M::mock(ItemTreeBounds::classname());
     $bounds0->shouldReceive('getItemId')->andReturn($itemIds[0]);
     $bounds0->shouldReceive('containsFiles')->andReturn(false);
     $bounds1 = M::mock(ItemTreeBounds::classname());
     $bounds1->shouldReceive('getItemId')->andReturn($itemIds[1]);
     $bounds1->shouldReceive('containsFiles')->andReturn(false);
     $bounds = array($bounds0, $bounds1);
     $uploadDao->shouldReceive('getItemTreeBounds')->with($itemIds[0])->andReturn($bounds[0]);
     $uploadDao->shouldReceive('getItemTreeBounds')->with($itemIds[1])->andReturn($bounds[1]);
     $clearingDao->shouldReceive('getEventIdsOfJob')->with($jobId)->andReturn(array($itemIds[0] => array(), $itemIds[1] => array()));
     $dbManager->shouldReceive('begin')->times(count($itemIds));
     $dbManager->shouldReceive('commit')->times(count($itemIds));
     /* dummy expectations needed for unmockable LicenseMap constructor */
     $dbManager->shouldReceive('prepare');
     $res = M::Mock(DbManager::classname());
     $dbManager->shouldReceive('execute')->andReturn($res);
     $row1 = array('rf_fk' => 2334, 'parent_fk' => 1);
     $row2 = array('rf_fk' => 2333, 'parent_fk' => 1);
     $dbManager->shouldReceive('fetchArray')->with($res)->andReturn($row1, $row2, false);
     $dbManager->shouldReceive('freeResult')->with($res);
     /* /expectations for LicenseMap */
     $decisionProcessor->shouldReceive('hasUnhandledScannerDetectedLicenses')->with($bounds0, $groupId, array(), anything())->andReturn(true);
     $clearingDao->shouldReceive('markDecisionAsWip')->with($itemIds[0], $userId, $groupId);
     $decisionProcessor->shouldReceive('hasUnhandledScannerDetectedLicenses')->with($bounds1, $groupId, array(), anything())->andReturn(false);
     $decisionProcessor->shouldReceive('makeDecisionFromLastEvents')->with($bounds1, $userId, $groupId, DecisionTypes::IDENTIFIED, false, array());
     $runner = new SchedulerTestRunnerMock($dbManager, $agentDao, $clearingDao, $uploadDao, $highlightDao, $decisionProcessor, $agentLicenseEventProcessor);
     list($success, $output, $retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, $args = "");
     $this->assertTrue($success, 'cannot run decider');
     $this->assertEquals($retCode, 0, 'decider failed: ' . $output);
     assertThat($this->getHeartCount($output), equalTo(count($itemIds)));
     $this->rmRepo();
 }
Exemplo n.º 8
0
 /**
  * @param string[][][] &$filesWithLicenses
  * @param ItemTreeBounds $itemTreeBounds
  */
 protected function addClearingStatus(&$filesWithLicenses, ItemTreeBounds $itemTreeBounds)
 {
     $alreadyClearedUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(), array(UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED, UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " . $itemTreeBounds->getRight() . ")", UploadTreeProxy::OPT_GROUP_ID => $this->groupId), $itemTreeBounds->getUploadTreeTableName(), 'already_cleared_uploadtree' . $itemTreeBounds->getUploadId());
     $alreadyClearedUploadTreeView->materialize();
     $filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->getNonArtifactDescendants($itemTreeBounds);
     $alreadyClearedUploadTreeView->unmaterialize();
     $uploadTreeIds = array_keys($filesWithLicenses);
     foreach ($uploadTreeIds as $uploadTreeId) {
         $filesWithLicenses[$uploadTreeId]['isCleared'] = false == array_key_exists($uploadTreeId, $filesThatShouldStillBeCleared);
     }
 }
 /**
  * @param ItemTreeBounds $itemBounds
  * @param int $userId
  * @param int $groupId
  * @param int $type
  * @param boolean $global
  * @param int[] $additionalEventIds additional event ids to include, indexed by licenseId
  */
 public function makeDecisionFromLastEvents(ItemTreeBounds $itemBounds, $userId, $groupId, $type, $global, $additionalEventIds = array())
 {
     if ($type < self::NO_LICENSE_KNOWN_DECISION_TYPE) {
         return;
     }
     $this->dbManager->begin();
     $itemId = $itemBounds->getItemId();
     $previousEvents = $this->clearingDao->getRelevantClearingEvents($itemBounds, $groupId);
     if ($type === self::NO_LICENSE_KNOWN_DECISION_TYPE) {
         $type = DecisionTypes::IDENTIFIED;
         $clearingEventIds = $this->insertClearingEventsForAgentFindings($itemBounds, $userId, $groupId, true, ClearingEventTypes::USER);
         foreach ($previousEvents as $eventId => $clearingEvent) {
             if (!in_array($eventId, $clearingEventIds) && !$clearingEvent->isRemoved()) {
                 $licenseId = $clearingEvent->getLicenseId();
                 $newEventId = $this->clearingDao->insertClearingEvent($itemBounds->getItemId(), $userId, $groupId, $licenseId, true);
                 $clearingEventIds[$licenseId] = $newEventId;
             }
         }
     } else {
         $clearingEventIds = $this->insertClearingEventsForAgentFindings($itemBounds, $userId, $groupId, false, ClearingEventTypes::AGENT, $previousEvents);
         foreach ($previousEvents as $clearingEvent) {
             $clearingEventIds[$clearingEvent->getLicenseId()] = $clearingEvent->getEventId();
         }
     }
     $currentDecision = $this->clearingDao->getRelevantClearingDecision($itemBounds, $groupId);
     $clearingEventIds = array_unique(array_merge($clearingEventIds, $additionalEventIds));
     $scope = $global ? DecisionScopes::REPO : DecisionScopes::ITEM;
     if (null === $currentDecision || $this->clearingDecisionIsDifferentFrom($currentDecision, $type, $scope, $clearingEventIds)) {
         $this->clearingDao->createDecisionFromEvents($itemBounds->getItemId(), $userId, $groupId, $type, $scope, $clearingEventIds);
     } else {
         $this->clearingDao->removeWipClearingDecision($itemId, $groupId);
     }
     $this->dbManager->commit();
 }
Exemplo n.º 10
0
 public function testDoesNotContainFileTreeItems()
 {
     $this->itemTreeBounds->shouldReceive("containsFiles")->withNoArgs()->andReturn(false);
     $this->assertFalse($this->item->containsFileTreeItems());
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage constraint bar is not defined
  */
 public function testExcpetionWithUnknownConstraint()
 {
     $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
     new UploadTreeViewProxy($this->itemTreeBounds, array('bar'));
 }
Exemplo n.º 12
0
 /**
  * @param string[][][] $filesWithLicenses
  * @param ItemTreeBounds $itemTreeBounds
  */
 protected function addScannerResults(&$filesWithLicenses, $itemTreeBounds)
 {
     $uploadId = $itemTreeBounds->getUploadId();
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->container->get('dao.agent'), $uploadId);
     $scanJobProxy->createAgentStatus($scannerAgents);
     $scannerIds = $scanJobProxy->getLatestSuccessfulAgentIds();
     if (empty($scannerIds)) {
         return;
     }
     $selectedScanners = '{' . implode(',', $scannerIds) . '}';
     $tableName = $itemTreeBounds->getUploadTreeTableName();
     $stmt = __METHOD__ . '.scanner_findings';
     $sql = "SELECT uploadtree_pk,rf_fk FROM {$tableName} ut, license_file\n      WHERE ut.pfile_fk=license_file.pfile_fk AND rf_fk IS NOT NULL AND agent_fk=any(\$1)";
     $param = array($selectedScanners);
     if ($tableName == 'uploadtree_a') {
         $param[] = $uploadId;
         $sql .= " AND upload_fk=\$" . count($param);
         $stmt .= $tableName;
     }
     $sql .= " GROUP BY uploadtree_pk,rf_fk";
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt, $param);
     while ($row = $this->dbManager->fetchArray($res)) {
         $reportedLicenseId = $this->licenseMap->getProjectedId($row['rf_fk']);
         $shortName = $this->licenseMap->getProjectedShortname($reportedLicenseId);
         if ($shortName != 'No_license_found' && $shortName != 'Void') {
             $filesWithLicenses[$row['uploadtree_pk']]['scanner'][] = $shortName;
             $this->includedLicenseIds[$reportedLicenseId] = $reportedLicenseId;
         }
     }
     $this->dbManager->freeResult($res);
     return "licenseInfoInFile determined by Scanners {$selectedScanners}";
 }
Exemplo n.º 13
0
 /**
  * @param $tagId
  * @param ItemTreeBounds $itemTreeBounds
  * @param $UniqueTagArray
  * @param $selectedAgentId
  * @param int $groupId
  * @param ScanJobProxy $scanJobProxy
  * @return array
  */
 private function createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy)
 {
     if (!empty($selectedAgentId)) {
         $agentName = $this->agentDao->getAgentName($selectedAgentId);
         $selectedScanners = array($agentName => $selectedAgentId);
     } else {
         $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
     }
     /** change the license result when selecting one version of nomos */
     $uploadId = $itemTreeBounds->getUploadId();
     $isFlat = isset($_GET['flatten']);
     if ($isFlat) {
         $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
     } else {
         $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->getItemId());
     }
     $searchMap = array();
     foreach (explode(' ', GetParm('sSearch', PARM_RAW)) as $pair) {
         $a = explode(':', $pair);
         if (count($a) == 1) {
             $searchMap['head'] = $pair;
         } else {
             $searchMap[$a[0]] = $a[1];
         }
     }
     if (array_key_exists('ext', $searchMap) && strlen($searchMap['ext']) >= 1) {
         $options[UploadTreeProxy::OPT_EXT] = $searchMap['ext'];
     }
     if (array_key_exists('head', $searchMap) && strlen($searchMap['head']) >= 1) {
         $options[UploadTreeProxy::OPT_HEAD] = $searchMap['head'];
     }
     if (($rfId = GetParm('scanFilter', PARM_INTEGER)) > 0) {
         $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners;
         $options[UploadTreeProxy::OPT_SCAN_REF] = $rfId;
     }
     if (($rfId = GetParm('conFilter', PARM_INTEGER)) > 0) {
         $options[UploadTreeProxy::OPT_GROUP_ID] = Auth::getGroupId();
         $options[UploadTreeProxy::OPT_CONCLUDE_REF] = $rfId;
     }
     $openFilter = GetParm('openCBoxFilter', PARM_RAW);
     if ($openFilter == 'true' || $openFilter == 'checked') {
         $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners;
         $options[UploadTreeProxy::OPT_GROUP_ID] = Auth::getGroupId();
         $options[UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED] = true;
     }
     $descendantView = new UploadTreeProxy($uploadId, $options, $itemTreeBounds->getUploadTreeTableName(), 'uberItems');
     $vars['iTotalDisplayRecords'] = $descendantView->count();
     $columnNamesInDatabase = array($isFlat ? 'ufile_name' : 'lft');
     $defaultOrder = array(array(0, "asc"));
     $orderString = $this->getObject('utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
     $offset = GetParm('iDisplayStart', PARM_INTEGER);
     $limit = GetParm('iDisplayLength', PARM_INTEGER);
     if ($offset) {
         $orderString .= " OFFSET {$offset}";
     }
     if ($limit) {
         $orderString .= " LIMIT {$limit}";
     }
     /* Get ALL the items under this Uploadtree_pk */
     $sql = $descendantView->getDbViewQuery() . " {$orderString}";
     $dbManager = $this->getObject('db.manager');
     $dbManager->prepare($stmt = __METHOD__ . $orderString, $sql);
     $res = $dbManager->execute($stmt, $descendantView->getParams());
     $descendants = $dbManager->fetchAll($res);
     $dbManager->freeResult($res);
     /* Filter out Children that don't have tag */
     if (!empty($tagId)) {
         TagFilter($descendants, $tagId, $itemTreeBounds->getUploadTreeTableName());
     }
     if (empty($descendants)) {
         $vars['fileData'] = array();
         return $vars;
     }
     if ($isFlat) {
         $firstChild = reset($descendants);
         $lastChild = end($descendants);
         $nameRange = array($firstChild['ufile_name'], $lastChild['ufile_name']);
     } else {
         $nameRange = array();
     }
     /*******    File Listing     ************/
     $pfileLicenses = array();
     foreach ($selectedScanners as $agentName => $agentId) {
         $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange);
         foreach ($licensePerPfile as $pfile => $licenseRow) {
             foreach ($licenseRow as $licId => $row) {
                 $lic = $this->licenseProjector->getProjectedShortname($licId);
                 $pfileLicenses[$pfile][$lic][$agentName] = $row;
             }
         }
     }
     $alreadyClearedUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(), $options = array(UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED, UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " . $itemTreeBounds->getRight() . ")", UploadTreeProxy::OPT_GROUP_ID => $groupId), $itemTreeBounds->getUploadTreeTableName(), $viewName = 'already_cleared_uploadtree' . $itemTreeBounds->getUploadId());
     $alreadyClearedUploadTreeView->materialize();
     if (!$isFlat) {
         $this->filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->countMaskedNonArtifactChildren($itemTreeBounds->getItemId());
     } else {
         $this->filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->getNonArtifactDescendants($itemTreeBounds);
     }
     $alreadyClearedUploadTreeView->unmaterialize();
     $noLicenseUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(), $options = array(UploadTreeProxy::OPT_SKIP_THESE => "noLicense", UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " . $itemTreeBounds->getRight() . ")", UploadTreeProxy::OPT_GROUP_ID => $groupId), $itemTreeBounds->getUploadTreeTableName(), $viewName = 'no_license_uploadtree' . $itemTreeBounds->getUploadId());
     $noLicenseUploadTreeView->materialize();
     if (!$isFlat) {
         $this->filesToBeCleared = $noLicenseUploadTreeView->countMaskedNonArtifactChildren($itemTreeBounds->getItemId());
     } else {
         $this->filesToBeCleared = $noLicenseUploadTreeView->getNonArtifactDescendants($itemTreeBounds);
     }
     $noLicenseUploadTreeView->unmaterialize();
     $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId, $isFlat);
     $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisions($allDecisions);
     $baseUri = Traceback_uri() . '?mod=license' . Traceback_parm_keep(array('upload', 'folder', 'show'));
     $tableData = array();
     global $Plugins;
     $ModLicView =& $Plugins[plugin_find_id("view-license")];
     $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
     foreach ($descendants as $child) {
         if (empty($child)) {
             continue;
         }
         $tableData[] = $this->createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $baseUri, $ModLicView, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds);
     }
     $vars['fileData'] = $tableData;
     return $vars;
 }
Exemplo n.º 14
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @return Highlight[]
  */
 public function getHighlightKeywords(ItemTreeBounds $itemTreeBounds)
 {
     $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
     $stmt = __METHOD__ . $uploadTreeTableName;
     $sql = "SELECT start,len\n             FROM highlight_keyword\n             WHERE pfile_fk = (SELECT pfile_fk FROM {$uploadTreeTableName} WHERE uploadtree_pk = \$1)";
     $this->dbManager->prepare($stmt, $sql);
     $result = $this->dbManager->execute($stmt, array($itemTreeBounds->getItemId()));
     $highlightEntries = array();
     while ($row = $this->dbManager->fetchArray($result)) {
         $highlightEntries[] = new Highlight(intval($row['start']), intval($row['start'] + $row['len']), Highlight::KEYWORD, 0, 0);
     }
     $this->dbManager->freeResult($result);
     return $highlightEntries;
 }
Exemplo n.º 15
0
 /**
  * @return bool
  */
 public function containsFileTreeItems()
 {
     return $this->itemTreeBounds->containsFiles();
 }
Exemplo n.º 16
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @return array
  */
 public function getNonArtifactDescendants(ItemTreeBounds $itemTreeBounds)
 {
     $uploadExpr = '$' . (count($this->params) + 1);
     $lftExpr = '$' . (count($this->params) + 2);
     $rgtExpr = '$' . (count($this->params) + 3);
     $dbManager = $GLOBALS['container']->get('db.manager');
     $sql = "SELECT u.uploadtree_pk FROM " . $this->getDbViewName() . " u " . "WHERE u.upload_fk={$uploadExpr} AND (u.lft BETWEEN {$lftExpr} AND {$rgtExpr}) AND u.ufile_mode & (3<<28) = 0";
     $stmt = __METHOD__ . '.' . $this->getDbViewName();
     if (!$this->materialized) {
         $sql = $this->asCTE() . ' ' . $sql;
         $stmt .= '.cte';
     }
     $dbManager->prepare($stmt, $sql);
     $params = array_merge($this->params, array($itemTreeBounds->getUploadId(), $itemTreeBounds->getLeft(), $itemTreeBounds->getRight()));
     $res = $dbManager->execute($stmt, $params);
     $descendants = array();
     while ($row = $dbManager->fetchArray($res)) {
         $descendants[$row['uploadtree_pk']] = 1;
     }
     $dbManager->freeResult($res);
     return $descendants;
 }
Exemplo n.º 17
0
 /**
  * @param $tagId
  * @param ItemTreeBounds $itemTreeBounds
  * @param $UniqueTagArray
  * @param $selectedAgentId
  * @param int $groupId
  * @param ScanJobProxy $scanJobProxy
  * @return array
  */
 private function createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy)
 {
     if (!empty($selectedAgentId)) {
         $agentName = $this->agentDao->getAgentName($selectedAgentId);
         $selectedScanners = array($agentName => $selectedAgentId);
     } else {
         $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
     }
     /** change the license result when selecting one version of nomos */
     $uploadId = $itemTreeBounds->getUploadId();
     $isFlat = isset($_GET['flatten']);
     if ($isFlat) {
         $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
     } else {
         $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->getItemId());
     }
     $descendantView = new UploadTreeProxy($uploadId, $options, $itemTreeBounds->getUploadTreeTableName(), 'uberItems');
     $vars['iTotalDisplayRecords'] = $descendantView->count();
     $columnNamesInDatabase = array($isFlat ? 'ufile_name' : 'lft');
     $defaultOrder = array(array(0, "asc"));
     $orderString = $this->getObject('utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
     $offset = GetParm('iDisplayStart', PARM_INTEGER);
     $limit = GetParm('iDisplayLength', PARM_INTEGER);
     if ($offset) {
         $orderString .= " OFFSET {$offset}";
     }
     if ($limit) {
         $orderString .= " LIMIT {$limit}";
     }
     /* Get ALL the items under this Uploadtree_pk */
     $sql = $descendantView->getDbViewQuery() . " {$orderString}";
     $dbManager = $this->getObject('db.manager');
     $dbManager->prepare($stmt = __METHOD__ . $orderString, $sql);
     $res = $dbManager->execute($stmt, $descendantView->getParams());
     $descendants = $dbManager->fetchAll($res);
     $dbManager->freeResult($res);
     /* Filter out Children that don't have tag */
     if (!empty($tagId)) {
         TagFilter($descendants, $tagId, $itemTreeBounds->getUploadTreeTableName());
     }
     if (empty($descendants)) {
         $vars['fileData'] = array();
         return $vars;
     }
     if ($isFlat) {
         $firstChild = reset($descendants);
         $lastChild = end($descendants);
         $nameRange = array($firstChild['ufile_name'], $lastChild['ufile_name']);
     } else {
         $nameRange = array();
     }
     /*******    File Listing     ************/
     $pfileLicenses = array();
     foreach ($selectedScanners as $agentName => $agentId) {
         $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange);
         foreach ($licensePerPfile as $pfile => $licenseRow) {
             foreach ($licenseRow as $licId => $row) {
                 $lic = $this->licenseProjector->getProjectedShortname($licId);
                 $pfileLicenses[$pfile][$lic][$agentName] = $row;
             }
         }
     }
     $baseUri = Traceback_uri() . '?mod=fileBrowse' . Traceback_parm_keep(array('upload', 'folder', 'show'));
     $tableData = array();
     global $Plugins;
     $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
     foreach ($descendants as $child) {
         if (empty($child)) {
             continue;
         }
         $tableData[] = $this->createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $baseUri, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds);
     }
     $vars['fileData'] = $tableData;
     return $vars;
 }
Exemplo n.º 18
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param bool $isFlat plain files from sub*folders instead of folders
  * @return array
  */
 public function countNonArtifactDescendants(ItemTreeBounds $itemTreeBounds, $isFlat = true)
 {
     $stmt = __METHOD__;
     $sql = "SELECT count(*) FROM " . $itemTreeBounds->getUploadTreeTableName() . " ut " . "WHERE ut.upload_fk=\$1";
     $params = array($itemTreeBounds->getUploadId());
     if (!$isFlat) {
         $stmt = __METHOD__ . '.parent';
         $params[] = $itemTreeBounds->getItemId();
         $sql .= " AND ut.ufile_mode & (1<<28) = 0 AND ut.realparent = \$2";
     } else {
         $params[] = $itemTreeBounds->getLeft();
         $params[] = $itemTreeBounds->getRight();
         $sql .= " AND ut.ufile_mode & (3<<28) = 0 AND (ut.lft BETWEEN \$2 AND \$3)";
     }
     $descendants = $this->dbManager->getSingleRow($sql, $params);
     return $descendants['count'];
 }
Exemplo n.º 19
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $userId
  */
 protected function processClearingEventsForItem(ItemTreeBounds $itemTreeBounds, $userId, $groupId, $additionalEventsFromThisJob)
 {
     $this->dbManager->begin();
     $itemId = $itemTreeBounds->getItemId();
     switch ($this->conflictStrategyId) {
         case self::FORCE_DECISION:
             $createDecision = true;
             break;
         default:
             $createDecision = !$this->clearingDecisionProcessor->hasUnhandledScannerDetectedLicenses($itemTreeBounds, $groupId, $additionalEventsFromThisJob, $this->licenseMap);
     }
     if ($createDecision) {
         $this->clearingDecisionProcessor->makeDecisionFromLastEvents($itemTreeBounds, $userId, $groupId, DecisionTypes::IDENTIFIED, $this->decisionIsGlobal, $additionalEventsFromThisJob);
     } else {
         foreach ($additionalEventsFromThisJob as $eventId) {
             $this->clearingDao->copyEventIdTo($eventId, $itemId, $userId, $groupId);
         }
         $this->clearingDao->markDecisionAsWip($itemId, $userId, $groupId);
     }
     $this->heartbeat(1);
     $this->dbManager->commit();
 }
Exemplo n.º 20
0
 public function testGetClearedLicenses()
 {
     $user = 1;
     $groupId = 601;
     $rf = 401;
     $isRm = false;
     $t = -10815;
     $item = 303;
     $this->buildProposals(array(array($item, $user, $groupId, $rf, $isRm, $t), array($item, $user, $groupId, $rf + 1, !$isRm, $t + 1)), $eventId = 0);
     $type = DecisionTypes::IDENTIFIED;
     $scope = DecisionScopes::ITEM;
     $this->buildDecisions(array(array($item, $user, $groupId, $type, $t, $scope, array($eventId, $eventId + 1))));
     $treeBounds = M::mock(ItemTreeBounds::classname());
     $treeBounds->shouldReceive('getLeft')->andReturn(1);
     $treeBounds->shouldReceive('getRight')->andReturn(8);
     $treeBounds->shouldReceive('getUploadTreeTableName')->andReturn("uploadtree");
     $treeBounds->shouldReceive('getUploadId')->andReturn(102);
     $map = $this->clearingDao->getClearedLicenses($treeBounds, $groupId);
     assertThat($map, equalTo(array(new LicenseRef($rf, 'FOO', 'foo full'))));
 }
Exemplo n.º 21
0
 /**
  * @param ItemTreeBounds $item
  * @param string $hash
  * @param int $userId
  * @param string $cpTable
  */
 public function rollbackTable($item, $hash, $userId, $cpTable = 'copyright')
 {
     $itemTable = $item->getUploadTreeTableName();
     $stmt = __METHOD__ . ".{$cpTable}.{$itemTable}";
     $params = array($hash, $item->getLeft(), $item->getRight(), $userId);
     $sql = "UPDATE {$cpTable} AS cpr SET content = cpa.oldtext, hash = \$1\n            FROM " . $cpTable . "_audit as cpa, {$itemTable} AS ut\n            WHERE cpr.pfile_fk = ut.pfile_fk\n              AND cpr.ct_pk = cpa.ct_fk\n              AND md5(cpa.oldtext) = \$1\n              AND ( ut.lft BETWEEN \$2 AND \$3 )\n              AND cpa.user_fk=\$4";
     if ('uploadtree_a' == $item->getUploadTreeTableName()) {
         $params[] = $item->getUploadId();
         $sql .= " AND ut.upload_fk=\$" . count($params);
         $stmt .= '.upload';
     }
     $this->dbManager->prepare($stmt, "{$sql}");
     $resource = $this->dbManager->execute($stmt, $params);
     $this->dbManager->freeResult($resource);
 }
Exemplo n.º 22
0
 /**
  * \brief Given an $Uploadtree_pk, display:
  *   - The histogram for the directory BY LICENSE.
  *   - The file listing for the directory.
  */
 private function showUploadHist(ItemTreeBounds $itemTreeBounds)
 {
     $groupId = Auth::getGroupId();
     $selectedAgentId = GetParm('agentId', PARM_INTEGER);
     $tag_pk = GetParm("tag", PARM_INTEGER);
     $uploadId = $itemTreeBounds->getUploadId();
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->agentDao, $uploadId);
     $scannerVars = $scanJobProxy->createAgentStatus($scannerAgents);
     $agentMap = $scanJobProxy->getAgentMap();
     $vars = array('agentId' => GetParm('agentId', PARM_INTEGER), 'agentShowURI' => Traceback_uri() . '?mod=' . Traceback_parm(), 'agentMap' => $agentMap, 'scanners' => $scannerVars);
     $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
     if (!empty($agentMap)) {
         $licVars = $this->createLicenseHistogram($itemTreeBounds->getItemId(), $tag_pk, $itemTreeBounds, $selectedAgentIds, $groupId);
         $vars = array_merge($vars, $licVars);
     }
     $this->licenseProjector = new LicenseMap($this->getObject('db.manager'), $groupId, LicenseMap::CONCLUSION, true);
     $dirVars = $this->countFileListing($itemTreeBounds);
     $childCount = $dirVars['iTotalRecords'];
     /***************************************
      * Problem: $ChildCount can be zero if you have a container that does not
      * unpack to a directory.  For example:
      * file.gz extracts to archive.txt that contains a license.
      * Same problem seen with .pdf and .Z files.
      * Solution: if $ChildCount == 0, then just view the license!
      *
      * $ChildCount can also be zero if the directory is empty.
      * **************************************/
     if ($childCount == 0) {
         return new RedirectResponse("?mod=view-license" . Traceback_parm_keep(array("upload", "item")));
     }
     $vars['licenseUri'] = Traceback_uri() . "?mod=popup-license&rf=";
     $vars['bulkUri'] = Traceback_uri() . "?mod=popup-license";
     return array_merge($vars, $dirVars);
 }
Exemplo n.º 23
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $groupId
  * @param boolean $orderAscending
  * @return array
  */
 protected function getCurrentSelectedLicensesTableData(ItemTreeBounds $itemTreeBounds, $groupId, $orderAscending)
 {
     $uploadTreeId = $itemTreeBounds->getItemId();
     $uploadId = $itemTreeBounds->getUploadId();
     $uberUri = Traceback_uri() . "?mod=view-license" . Traceback_parm_keep(array('upload', 'folder'));
     list($addedClearingResults, $removedLicenses) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId, LicenseMap::CONCLUSION);
     $licenseEventTypes = new ClearingEventTypes();
     $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId);
     $table = array();
     /* @var $clearingResult ClearingResult */
     foreach ($addedClearingResults as $licenseShortName => $clearingResult) {
         $licenseId = $clearingResult->getLicenseId();
         $types = $this->getAgentInfo($clearingResult, $uberUri, $uploadTreeId);
         $reportInfo = "";
         $comment = "";
         if ($clearingResult->hasClearingEvent()) {
             $licenseDecisionEvent = $clearingResult->getClearingEvent();
             $types[] = $this->getEventInfo($licenseDecisionEvent, $uberUri, $uploadTreeId, $licenseEventTypes);
             $reportInfo = $licenseDecisionEvent->getReportinfo();
             $comment = $licenseDecisionEvent->getComment();
         }
         $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef());
         $actionLink = "<a href=\"javascript:;\" onclick=\"removeLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img class=\"delete\" src=\"images/space_16.png\" alt=\"\"/></a>";
         if (in_array($clearingResult->getLicenseId(), $mainLicIds)) {
             $tooltip = _('This is a main license for the upload. Click to discard selection.');
             $actionLink .= " <a href=\"javascript:;\" onclick=\"removeMainLicense({$uploadId}, {$licenseId});\"><img src=\"images/icons/star_filled_16.png\" alt=\"mainLicense\" title=\"{$tooltip}\" border=\"0\"/></a>";
         } else {
             $tooltip = _('Click to select this as a main license for the upload.');
             $actionLink .= " <a href=\"javascript:;\" onclick=\"makeMainLicense({$uploadId}, {$licenseId});\"><img src=\"images/icons/star_16.png\" alt=\"noMainLicense\" title=\"{$tooltip}\" border=\"0\"/></a>";
         }
         $reportInfoField = nl2br(htmlspecialchars($reportInfo));
         $commentField = nl2br(htmlspecialchars($comment));
         $id = "{$uploadTreeId},{$licenseId}";
         $table[$licenseShortName] = array('DT_RowId' => $id, '0' => $licenseShortNameWithLink, '1' => implode("<br/>", $types), '2' => $reportInfoField, '3' => $commentField, '4' => $actionLink);
     }
     foreach ($removedLicenses as $licenseShortName => $clearingResult) {
         if ($clearingResult->getAgentDecisionEvents()) {
             $agents = $this->getAgentInfo($clearingResult, $uberUri, $uploadTreeId);
             $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef());
             $licenseId = $clearingResult->getLicenseId();
             $actionLink = "<a href=\"javascript:;\" onclick=\"addLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img class=\"add\" src=\"images/space_16.png\" alt=\"\"/></a>";
             $filled = in_array($clearingResult->getLicenseId(), $mainLicIds) ? 'filled_' : '';
             $actionLink .= ' <img src="images/icons/star_' . $filled . '16.png" alt="mainLicense"/>';
             $idArray = array($uploadTreeId, $licenseId);
             $id = implode(',', $idArray);
             $table[$licenseShortName] = array('DT_RowId' => $id, 'DT_RowClass' => 'removed', '0' => $licenseShortNameWithLink, '1' => implode("<br/>", $agents), '2' => "-", '3' => "-", '4' => $actionLink);
         }
     }
     $valueTable = array_values($this->sortByKeys($table, $orderAscending));
     return $valueTable;
 }