Esempio n. 1
0
 private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
     $licenseRef2 = $this->licenseDao->getLicenseByShortName("GPL-1.0")->getRef();
     $licenseRef3 = $this->licenseDao->getLicenseByShortName("APL-1.0")->getRef();
     $licId1 = $licenseRef1->getId();
     $licId2 = $licenseRef2->getId();
     $licId3 = $licenseRef3->getId();
     $agentNomosId = 6;
     $agentMonkId = 5;
     $agentOther = 8;
     $pfile = 4;
     $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ({$licId2}, {$licId1}, " . LicenseMap::CONCLUSION . ")");
     $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ({$licId3}, {$licId1}, " . LicenseMap::CONCLUSION . ")");
     $this->dbManager->queryOnce("DELETE FROM license_file");
     $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,{$licId1},{$pfile},{$agentNomosId})");
     $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
     $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
     $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,{$licId2},{$pfile},{$agentMonkId})");
     $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,6,2)");
     $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
     $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,{$licId3},{$pfile},{$agentOther})");
     $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
     $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,13,19)");
     list($success, $output, $retCode) = $runner->run($uploadId = 2, $userId = 6, $groupId = 4, $jobId = 31, $args = "");
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'decider failed (did you make test?): ' . $output);
     assertThat($this->getHeartCount($output), equalTo(1));
     $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
     $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
     assertThat($decisions, is(arrayWithSize(1)));
     $this->rmRepo();
 }
Esempio n. 2
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @return string[][][] $filesWithLicenses mapping item->'concluded'->(array of shortnames)
  */
 protected function getFilesWithLicensesFromClearings(ItemTreeBounds $itemTreeBounds)
 {
     $clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $this->groupId);
     $filesWithLicenses = array();
     $clearingsProceeded = 0;
     foreach ($clearingDecisions as $clearingDecision) {
         $clearingsProceeded += 1;
         if (($clearingsProceeded & 2047) == 0) {
             $this->heartbeat(0);
         }
         if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
             continue;
         }
         foreach ($clearingDecision->getClearingEvents() as $clearingEvent) {
             $clearingLicense = $clearingEvent->getClearingLicense();
             if ($clearingLicense->isRemoved()) {
                 continue;
             }
             if ($clearingEvent->getReportinfo()) {
                 $customLicenseText = $clearingEvent->getReportinfo();
                 $reportedLicenseShortname = $this->licenseMap->getProjectedShortname($this->licenseMap->getProjectedId($clearingLicense->getLicenseId())) . '-' . md5($customLicenseText);
                 $this->includedLicenseIds[$reportedLicenseShortname] = $customLicenseText;
                 $filesWithLicenses[$clearingDecision->getUploadTreeId()]['concluded'][] = $reportedLicenseShortname;
             } else {
                 $reportedLicenseId = $this->licenseMap->getProjectedId($clearingLicense->getLicenseId());
                 $this->includedLicenseIds[$reportedLicenseId] = true;
                 $filesWithLicenses[$clearingDecision->getUploadTreeId()]['concluded'][] = $this->licenseMap->getProjectedShortname($reportedLicenseId);
             }
         }
     }
     return $filesWithLicenses;
 }
Esempio n. 3
0
 private function runnerReuserScanWithoutAnyUploadToCopyAndNoClearing(SchedulerTestRunner $runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     list($success, $output, $retCode) = $runner->run($uploadId = 1, $this->userId);
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'reuser failed: ' . $output);
     assertThat($this->getHeartCount($output), equalTo(0));
     $bounds = $this->uploadDao->getParentItemBounds($uploadId);
     assertThat($this->clearingDao->getFileClearingsFolder($bounds, $groupId = 5), is(emptyArray()));
     $this->rmRepo();
 }
 protected function getStatements($uploadId, $uploadTreeTableName, $groupId = null)
 {
     $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
     $clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId);
     $dbManager = $GLOBALS['container']->get('db.manager');
     $licenseMap = new LicenseMap($dbManager, $groupId, LicenseMap::REPORT);
     $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId);
     $ungroupedStatements = array();
     foreach ($clearingDecisions as $clearingDecision) {
         if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
             continue;
         }
         /** @var ClearingDecision $clearingDecision */
         foreach ($clearingDecision->getClearingLicenses() as $clearingLicense) {
             if ($clearingLicense->isRemoved()) {
                 continue;
             }
             if ($this->onlyComments && !($comment = $clearingLicense->getComment())) {
                 continue;
             }
             $originLicenseId = $clearingLicense->getLicenseId();
             $licenseId = $licenseMap->getProjectedId($originLicenseId);
             if (!$this->onlyComments && in_array($licenseId, $mainLicIds)) {
                 continue;
             }
             if ($this->onlyComments) {
                 $text = $comment;
             } else {
                 $reportInfo = $clearingLicense->getReportInfo();
                 $text = $reportInfo ?: $this->getCachedLicenseText($licenseId, $groupId);
             }
             $ungroupedStatements[] = array('content' => $licenseMap->getProjectedShortname($originLicenseId, $clearingLicense->getShortName()), 'uploadtree_pk' => $clearingDecision->getUploadTreeId(), 'text' => $text);
         }
     }
     return $ungroupedStatements;
 }
Esempio n. 5
0
 protected function processEnhancedUploadReuse($itemTreeBounds, $itemTreeBoundsReused, $reusedGroupId)
 {
     $clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBoundsReused, $reusedGroupId);
     $currenlyVisibleClearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $this->groupId);
     $currenlyVisibleClearingDecisionsById = $this->mapByClearingId($currenlyVisibleClearingDecisions);
     $clearingDecisionsById = $this->mapByClearingId($clearingDecisions);
     $clearingDecisionsToImport = array_diff_key($clearingDecisionsById, $currenlyVisibleClearingDecisionsById);
     $sql = "SELECT ut.* FROM uploadtree ur, uploadtree ut WHERE ur.upload_fk=\$2 AND ur.pfile_fk=\$3 AND ut.upload_fk=\$1 AND ut.ufile_name=ur.ufile_name";
     $stmt = __METHOD__ . '.reuseByName';
     $this->dbManager->prepare($stmt, $sql);
     $treeDao = $this->container->get('dao.tree');
     foreach ($clearingDecisionsToImport as $clearingDecision) {
         $reusedPath = $treeDao->getRepoPathOfPfile($clearingDecision->getPfileId());
         $res = $this->dbManager->execute($stmt, array($itemTreeBounds->getUploadId(), $itemTreeBoundsReused->getUploadId(), $clearingDecision->getPfileId()));
         while ($row = $this->dbManager->fetchArray($res)) {
             $newPath = $treeDao->getRepoPathOfPfile($row['pfile_fk']);
             $this->copyClearingDecisionIfDifferenceIsSmall($reusedPath, $newPath, $clearingDecision, $row['uploadtree_pk']);
         }
         $this->dbManager->freeResult($res);
     }
 }
Esempio n. 6
0
 protected function renderPackage($uploadId)
 {
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
     $clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $this->groupId);
     $this->heartbeat(0);
     $filesWithLicenses = $this->getFilesWithLicensesFromClearings($clearingDecisions);
     $licenseComment = $this->addScannerResults($filesWithLicenses, $itemTreeBounds);
     $this->addCopyrightResults($filesWithLicenses, $uploadId);
     $this->heartbeat(0);
     $upload = $this->uploadDao->getUpload($uploadId);
     $fileNodes = $this->generateFileNodes($filesWithLicenses, $upload->getTreeTableName());
     $mainLicenseIds = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     $mainLicenses = array();
     foreach ($mainLicenseIds as $licId) {
         $reportedLicenseId = $this->licenseMap->getProjectedId($licId);
         $this->includedLicenseIds[$reportedLicenseId] = $reportedLicenseId;
         $mainLicenses[] = $this->licenseMap->getProjectedShortname($reportedLicenseId);
     }
     $hashes = $this->uploadDao->getUploadHashes($uploadId);
     return $this->renderString($this->getTemplateFile('package'), array('uploadId' => $uploadId, 'uri' => $this->uri, 'packageName' => $upload->getFilename(), 'uploadName' => $upload->getFilename(), 'sha1' => $hashes['sha1'], 'md5' => $hashes['md5'], 'verificationCode' => $this->getVerificationCode($upload), 'mainLicenses' => $mainLicenses, 'licenseComments' => $licenseComment, 'fileNodes' => $fileNodes));
 }
Esempio n. 7
0
 private function runnerDeciderScanWithForceDecision($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $jobId = 42;
     $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
     $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef();
     $agentLicId = $this->licenseDao->getLicenseByShortName("Adaptec")->getRef()->getId();
     $addedLicenses = array($licenseRef1, $licenseRef2);
     assertThat($addedLicenses, not(arrayContaining(null)));
     $agentId = 5;
     $pfile = 4;
     $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,{$agentLicId},{$pfile},{$agentId})");
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId = 23);
     assertThat($this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds), is(not(emptyArray())));
     $eventId1 = $this->clearingDao->insertClearingEvent($itemId, $userId = 2, $groupId = 3, $licenseRef1->getId(), false);
     $eventId2 = $this->clearingDao->insertClearingEvent($itemId, 5, $groupId, $licenseRef2->getId(), true);
     $this->dbManager->queryOnce("UPDATE clearing_event SET job_fk={$jobId}");
     $addedEventIds = array($eventId1, $eventId2);
     list($success, $output, $retCode) = $runner->run($uploadId = 2, $userId, $groupId, $jobId, $args = "-k1");
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'decider failed: ' . $output);
     assertThat($this->getHeartCount($output), equalTo(1));
     $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
     $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
     assertThat($decisions, is(arrayWithSize(1)));
     /** @var ClearingDecision $deciderMadeDecision */
     $deciderMadeDecision = $decisions[0];
     $eventIds = array();
     foreach ($deciderMadeDecision->getClearingEvents() as $event) {
         $eventIds[] = $event->getEventId();
     }
     assertThat($eventIds, arrayValue($addedEventIds[0]));
     assertThat($eventIds, arrayValue($addedEventIds[1]));
     assertThat($eventIds, arrayWithSize(1 + count($addedEventIds)));
     $this->rmRepo();
 }
Esempio n. 8
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;
 }