Пример #1
0
 /**
  * 
  * @param int $uploadTreeId
  * @param Request $request
  * @return int $jobQueueId
  */
 private function getJobQueueId($uploadTreeId, Request $request)
 {
     $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId);
     $uploadId = intval($uploadEntry['upload_fk']);
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     if ($uploadId <= 0 || !$this->uploadDao->isAccessible($uploadId, $groupId)) {
         throw new Exception('permission denied');
     }
     $bulkScope = $request->get('bulkScope');
     switch ($bulkScope) {
         case 'u':
             $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
             $topBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTable);
             $uploadTreeId = $topBounds->getItemId();
             break;
         case 'f':
             if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) {
                 $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId;
             }
             break;
         default:
             throw new InvalidArgumentException('bad scope request');
     }
     $refText = $request->get('refText');
     $actions = $request->get('bulkAction');
     $licenseRemovals = array();
     foreach ($actions as $licenseAction) {
         $licenseRemovals[$licenseAction['licenseId']] = $licenseAction['action'] == 'remove';
     }
     $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseRemovals, $refText);
     if ($bulkId <= 0) {
         throw new Exception('cannot insert bulk reference');
     }
     $upload = $this->uploadDao->getUpload($uploadId);
     $uploadName = $upload->getFilename();
     $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId);
     /** @var DeciderJobAgentPlugin $deciderPlugin */
     $deciderPlugin = plugin_find("agent_deciderjob");
     $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId));
     $conflictStrategyId = intval($request->get('forceDecision'));
     $errorMsg = '';
     $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId);
     if (!empty($errorMsg)) {
         throw new Exception(str_replace('<br>', "\n", $errorMsg));
     }
     return $jqId;
 }
Пример #2
0
 /**
  * @param int $uploadId
  * @return string
  */
 protected function renderPackage($uploadId)
 {
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
     $this->heartbeat(0);
     $filesWithLicenses = $this->getFilesWithLicensesFromClearings($itemTreeBounds);
     $this->heartbeat(0);
     $this->addClearingStatus($filesWithLicenses, $itemTreeBounds);
     $this->heartbeat(0);
     $licenseComment = $this->addScannerResults($filesWithLicenses, $itemTreeBounds);
     $this->heartbeat(0);
     $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] = true;
         $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, 'mainLicense' => SpdxTwoUtils::implodeLicenses($mainLicenses, "LicenseRef-"), 'licenseComments' => $licenseComment, 'fileNodes' => $fileNodes));
 }
Пример #3
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();
 }
Пример #4
0
 /** @group Functional */
 public function testRun()
 {
     $this->setUpTables();
     $this->setUpRepo();
     list($output, $retCode) = $this->runNinka($uploadId = 1);
     $this->rmRepo();
     $this->assertEquals($retCode, 0, 'ninka failed: ' . $output);
     $bounds = $this->uploadDao->getParentItemBounds($uploadId);
     $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds);
     $this->assertEquals($expected = 6, count($matches));
     foreach ($matches as $licenseMatch) {
         /** @var LicenseRef */
         $matchedLicense = $licenseMatch->getLicenseRef();
         switch ($licenseMatch->getFileId()) {
             case 7:
             case 4:
                 $expectedLicense = "GPL-3.0+";
                 break;
             case 3:
                 $expectedLicense = "UnclassifiedLicense";
                 break;
             default:
                 $expectedLicense = "No_license_found";
                 break;
         }
         $this->assertEquals($expectedLicense, $matchedLicense->getShortName(), "unexpected license for fileId " . $licenseMatch->getFileId());
         /** @var AgentRef */
         $agentRef = $licenseMatch->getAgentRef();
         $this->assertEquals($agentRef->getAgentName(), "ninka");
     }
 }
Пример #5
0
 function processUploadId($uploadId)
 {
     $args = $this->args;
     $this->activeRules = array_key_exists('r', $args) ? intval($args['r']) : self::RULES_ALL;
     $this->licenseMap = new LicenseMap($this->dbManager, $this->groupId, $this->licenseMapUsage);
     $parentBounds = $this->uploadDao->getParentItemBounds($uploadId);
     foreach ($this->uploadDao->getContainedItems($parentBounds) as $item) {
         $process = $this->processItem($item);
         $this->heartbeat($process);
     }
     if (($this->activeRules & self::RULES_BULK_REUSE) == self::RULES_BULK_REUSE) {
         $bulkReuser = new BulkReuser();
         $bulkReuser->rerunBulkAndDeciderOnUpload($uploadId, $this->groupId, $this->userId, $this->jobId);
     }
     return true;
 }
Пример #6
0
 function processUploadId($uploadId)
 {
     $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId);
     foreach ($this->uploadDao->getReusedUpload($uploadId, $this->groupId) as $reuseTriple) {
         $reusedUploadId = $reuseTriple['reused_upload_fk'];
         $reusedGroupId = $reuseTriple['reused_group_fk'];
         $reuseMode = $reuseTriple['reuse_mode'];
         $itemTreeBoundsReused = $this->uploadDao->getParentItemBounds($reusedUploadId);
         if (false === $itemTreeBoundsReused) {
             continue;
         }
         if (empty($reuseMode)) {
             $this->processUploadReuse($itemTreeBounds, $itemTreeBoundsReused, $reusedGroupId);
         } else {
             $this->processEnhancedUploadReuse($itemTreeBounds, $itemTreeBoundsReused, $reusedGroupId);
         }
     }
     return true;
 }
Пример #7
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();
 }
Пример #8
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();
 }
Пример #9
0
 /** @group Functional */
 public function testRunMonkTwiceOnAScan()
 {
     $this->setUpTables();
     $this->setUpRepo();
     list($output, $retCode) = $this->runMonk($uploadId = 1);
     list($output2, $retCode2) = $this->runMonk($uploadId);
     $this->assertEquals($retCode, 0, 'monk failed: ' . $output);
     $this->assertEquals(6, $this->getHeartCount($output));
     $this->assertEquals($retCode2, 0, 'monk failed: ' . $output2);
     $this->assertEquals(0, $this->getHeartCount($output2));
     $this->rmRepo();
     $bounds = $this->uploadDao->getParentItemBounds($uploadId);
     $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds);
     $this->assertEquals($expected = 2, count($matches));
     /** @var LicenseMatch */
     $licenseMatch = $matches[0];
     $this->assertEquals($expected = 4, $licenseMatch->getFileId());
     /** @var LicenseRef */
     $matchedLicense = $licenseMatch->getLicenseRef();
     $this->assertEquals($matchedLicense->getShortName(), "GPL-3.0");
     /** @var AgentRef */
     $agentRef = $licenseMatch->getAgentRef();
     $this->assertEquals($agentRef->getAgentName(), "monk");
 }