예제 #1
0
 /** @group Functional */
 public function testRunMonkBulkScanWithAnEmptySearchText()
 {
     $this->setUpTables();
     $this->setUpRepo();
     $userId = 2;
     $groupId = 2;
     $uploadTreeId = 1;
     $licenseId = 225;
     $removing = false;
     $refText = "";
     $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId => $removing), $refText);
     $this->assertGreaterThan($expected = 0, $bulkId);
     $jobId = 64;
     list($output, $retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId);
     $this->rmRepo();
     $this->assertEquals($retCode, 0, 'monk bulk failed: ' . $output);
     $bounds6 = new ItemTreeBounds(6, 'uploadtree_a', 1, 17, 18);
     $bounds7 = new ItemTreeBounds(7, 'uploadtree_a', 1, 15, 16);
     $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
     $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
     assertThat(count($relevantDecisionsItem6), is(equalTo(0)));
     assertThat(count($relevantDecisionsItem7), is(equalTo(0)));
     $bulkHighlights = $this->highlightDao->getHighlightBulk(6);
     assertThat(count($bulkHighlights), is(equalTo(0)));
 }
예제 #2
0
 private function runnerReuserScanWithARepoClearingEnhanced($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $originallyClearedItemId = 23;
     /* upload 3 in the test db is the same as upload 2 -> items 13-24 in upload 2 correspond to 33-44 */
     $reusingUploadItemShift = 20;
     $this->dbManager->queryOnce("UPDATE uploadtree_a SET pfile_fk=351 WHERE uploadtree_pk={$originallyClearedItemId}+{$reusingUploadItemShift}", __METHOD__ . '.minorChange');
     $this->uploadDao->addReusedUpload($uploadId = 3, $reusedUpload = 2, $this->groupId, $this->groupId, $reuseMode = 1);
     $repoPath = $this->testDb->getFossSysConf() . '/repo/files/';
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(4)->andReturn($repoPath . '04621571bcbabce75c4dd1c6445b87dec0995734.59cacdfce5051cd8a1d8a1f2dcce40a5.12320');
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(351)->andReturn($repoPath . 'c518ce1658140b65fa0132ad1130cb91512416bf.8e913e594d24ff3aeabe350107d97815.35829');
     list($clearingLicense1, $clearingLicense2, $addedEventIds) = $this->insertDecisionFromTwoEvents(DecisionScopes::REPO, $originallyClearedItemId);
     $clearingLicenses = array($clearingLicense1, $clearingLicense2);
     list($success, $output, $retCode) = $runner->run($uploadId, $this->userId, $this->groupId);
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'reuser failed: ' . $output);
     $newUploadClearings = $this->getFilteredClearings($uploadId, $this->groupId);
     $potentiallyReusableClearings = $this->getFilteredClearings($reusedUpload, $this->groupId);
     assertThat($newUploadClearings, is(arrayWithSize(1)));
     assertThat($potentiallyReusableClearings, is(arrayWithSize(1)));
     /** @var ClearingDecision */
     $potentiallyReusableClearing = $potentiallyReusableClearings[0];
     /** @var ClearingDecision */
     $newClearing = $newUploadClearings[0];
     /* they are actually the same ClearingDecision
      * only sameFolder and sameUpload are different */
     assertThat($newClearing, not(equalTo($potentiallyReusableClearing)));
     assertThat($newClearing->getClearingLicenses(), arrayContainingInAnyOrder($clearingLicenses));
     assertThat($newClearing->getType(), equalTo($potentiallyReusableClearing->getType()));
     assertThat($newClearing->getScope(), equalTo($potentiallyReusableClearing->getScope()));
     assertThat($newClearing->getUploadTreeId(), equalTo($potentiallyReusableClearing->getUploadTreeId() + $reusingUploadItemShift));
     /* reuser should have not created a correct local event history */
     $bounds = $this->uploadDao->getItemTreeBounds($originallyClearedItemId + $reusingUploadItemShift);
     $newEvents = $this->clearingDao->getRelevantClearingEvents($bounds, $this->groupId);
     assertThat($newEvents, is(arrayWithSize(count($clearingLicenses))));
     /** @var ClearingEvent $newEvent */
     foreach ($newEvents as $newEvent) {
         assertThat($newEvent->getEventId(), anyOf($addedEventIds));
         assertThat($newEvent->getClearingLicense(), anyOf($clearingLicenses));
     }
     $this->rmRepo();
 }
예제 #3
0
 public function testRelevantClearingEvents()
 {
     $groupId = 701;
     $this->buildProposals(array(array(301, 1, $groupId, 401, false, -99), array(301, 2, $groupId, 402, true, -98), array(301, 2, $groupId, 401, true, -97)), $firstEventId = 0);
     $this->buildDecisions(array(array(301, 1, $groupId, DecisionTypes::IDENTIFIED, -90, DecisionScopes::REPO, array($firstEventId, $firstEventId + 1, $firstEventId + 2))));
     $itemTreeBounds = M::mock(ItemTreeBounds::classname());
     $itemTreeBounds->shouldReceive('getItemId')->andReturn(301);
     $itemTreeBounds->shouldReceive('getUploadTreeTableName')->andReturn('uploadtree');
     $itemTreeBounds->shouldReceive('containsFiles')->andReturn(false);
     $itemTreeBounds->shouldReceive('getUploadId')->andReturn($this->items[301][0]);
     $itemTreeBounds->shouldReceive('getLeft')->andReturn($this->items[301][4]);
     $itemTreeBounds->shouldReceive('getRight')->andReturn($this->items[301][5]);
     $events1 = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $groupId);
     assertThat($events1, arrayWithSize(2));
     assertThat($events1, hasKeyInArray(401));
     assertThat($events1, hasKeyInArray(402));
     assertThat($events1[401], is(anInstanceOf(ClearingEvent::classname())));
     assertThat($events1[402]->getEventId(), is($firstEventId + 1));
     assertThat($events1[401]->getEventId(), is($firstEventId + 2));
 }
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $groupId
  * @return array
  * @throws Exception
  */
 public function getCurrentClearings(ItemTreeBounds $itemTreeBounds, $groupId, $usageId = LicenseMap::TRIVIAL)
 {
     $agentEvents = $this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds, $usageId);
     $events = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $groupId);
     $addedResults = array();
     $removedResults = array();
     foreach (array_unique(array_merge(array_keys($events), array_keys($agentEvents))) as $licenseId) {
         $licenseDecisionEvent = array_key_exists($licenseId, $events) ? $events[$licenseId] : null;
         $agentClearingEvents = array_key_exists($licenseId, $agentEvents) ? $agentEvents[$licenseId] : array();
         if ($licenseDecisionEvent === null && count($agentClearingEvents) == 0) {
             throw new Exception('not in merge');
         }
         $licenseDecisionResult = new ClearingResult($licenseDecisionEvent, $agentClearingEvents);
         if ($licenseDecisionResult->isRemoved()) {
             $removedResults[$licenseId] = $licenseDecisionResult;
         } else {
             $addedResults[$licenseId] = $licenseDecisionResult;
         }
     }
     return array($addedResults, $removedResults);
 }
예제 #5
0
 private function processItem(Item $item)
 {
     $itemTreeBounds = $item->getItemTreeBounds();
     $unMappedMatches = $this->agentLicenseEventProcessor->getLatestScannerDetectedMatches($itemTreeBounds);
     $projectedScannerMatches = $this->remapByProjectedId($unMappedMatches);
     $lastDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $this->groupId);
     if (null !== $lastDecision && $lastDecision->getType() == DecisionTypes::IRRELEVANT) {
         return 0;
     }
     $currentEvents = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $this->groupId);
     $markAsWip = false;
     if (null !== $lastDecision && $projectedScannerMatches && ($this->activeRules & self::RULES_WIP_SCANNER_UPDATES) == self::RULES_WIP_SCANNER_UPDATES) {
         $licensesFromDecision = array();
         foreach ($lastDecision->getClearingLicenses() as $clearingLicense) {
             $licenseIdFromEvent = $this->licenseMap->getProjectedId($clearingLicense->getLicenseId());
             $licensesFromDecision[$licenseIdFromEvent] = $licenseIdFromEvent;
         }
         $markAsWip = $this->existsUnhandledMatch($projectedScannerMatches, $licensesFromDecision);
     }
     if (null !== $lastDecision && $markAsWip) {
         $this->clearingDao->markDecisionAsWip($item->getId(), $this->userId, $this->groupId);
         return 1;
     }
     if (null !== $lastDecision || 0 < count($currentEvents)) {
         return 0;
     }
     $haveDecided = false;
     if (($this->activeRules & self::RULES_NOMOS_IN_MONK) == self::RULES_NOMOS_IN_MONK) {
         $haveDecided = $this->autodecideNomosMatchesInsideMonk($itemTreeBounds, $projectedScannerMatches);
     }
     if (!$haveDecided && ($this->activeRules & self::RULES_NOMOS_MONK_NINKA) == self::RULES_NOMOS_MONK_NINKA) {
         $haveDecided = $this->autodecideNomosMonkNinka($itemTreeBounds, $projectedScannerMatches);
     }
     if (!$haveDecided && $markAsWip) {
         $this->clearingDao->markDecisionAsWip($item->getId(), $this->userId, $this->groupId);
     }
     return $haveDecided || $markAsWip ? 1 : 0;
 }