/** * @param int $userId * @param int * @param int $lastItem * @return array */ protected function updateLastItem($userId, $groupId, $lastItem) { $type = GetParm("clearingTypes", PARM_INTEGER); $global = GetParm("globalDecision", PARM_STRING) === "on"; $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($lastItem); $itemBounds = $this->uploadDao->getItemTreeBounds($lastItem, $uploadTreeTableName); $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global); }
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(); }
/** * @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; }
/** * @param ItemTreeBounds $itemTreeBounds * @param LicenseMatch[] $matches * @return boolean */ private function autodecideNomosMatchesInsideMonk(ItemTreeBounds $itemTreeBounds, $matches) { $canDecide = count($matches) > 0; foreach ($matches as $licenseMatches) { if (!$canDecide) { break; } $canDecide &= $this->areNomosMatchesInsideAMonkMatch($licenseMatches); } if ($canDecide) { $this->clearingDecisionProcessor->makeDecisionFromLastEvents($itemTreeBounds, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $global = true); } return $canDecide; }
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 $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(); }
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(); }