/** * @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); }
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(); }