protected function setUp()
 {
     global $container;
     $this->highlightDao = M::mock(HighlightDao::classname());
     $container->shouldReceive('get')->withArgs(array('dao.highlight'))->andReturn($this->highlightDao);
     $container->shouldReceive('get')->withArgs(array('dao.upload'))->andReturn(M::mock(UploadDao::classname()));
     $container->shouldReceive('get')->withArgs(array('dao.clearing'))->andReturn(M::mock(ClearingDao::classname()));
     $container->shouldReceive('get')->withArgs(array('decision.types'))->andReturn(M::mock(DecisionTypes::classname()));
     $container->shouldReceive('get')->withArgs(array('businessrules.clearing_decision_processor'))->andReturn(M::mock(ClearingDecisionProcessor::classname()));
     $container->shouldReceive('get')->withArgs(array('businessrules.agent_license_event_processor'))->andReturn(M::mock(AgentLicenseEventProcessor::classname()));
     $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
 }
 public function testGetUnhandledScannerDetectedLicensesWithMappedMatch()
 {
     /** @var LicenseRef $licenseRef */
     list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
     $offset = 0;
     $clearingEvent = $this->createClearingEvent($eventId = 123, $this->timestamp, $licenseRef->getId() + $offset, $licenseRef->getShortName(), $licenseRef->getFullName());
     $this->clearingDao->shouldReceive("getRelevantClearingEvents")->with($this->itemTreeBounds, $this->groupId)->andReturn(array($clearingEvent->getLicenseId() => $clearingEvent));
     $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")->with($this->itemTreeBounds, LicenseMap::CONCLUSION)->andReturn($scannerResults);
     $licenseMap = M::mock(LicenseMap::classname());
     $licenseMap->shouldReceive('getProjectedId')->andReturnUsing(function ($id) {
         return $id;
     });
     $licenseMap->shouldReceive('getUsage')->andReturn(LicenseMap::CONCLUSION);
     $hasUnhandledScannerDetectedLicenses = $this->clearingDecisionProcessor->hasUnhandledScannerDetectedLicenses($this->itemTreeBounds, $this->groupId, array(), $licenseMap);
     assertThat($hasUnhandledScannerDetectedLicenses, is(False));
 }
 /**
  * @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);
 }
Example #4
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;
 }
Example #5
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();
 }
 public function testGetScannedLicensesWithEmptyDetails()
 {
     assertThat($this->agentLicenseEventProcessor->getScannedLicenses(array()), is(emptyArray()));
 }