/**
  * @param ItemTreeBounds $itemBounds
  * @param int $userId
  * @param int $groupId
  * @param int $type
  * @param boolean $global
  * @param int[] $additionalEventIds additional event ids to include, indexed by licenseId
  */
 public function makeDecisionFromLastEvents(ItemTreeBounds $itemBounds, $userId, $groupId, $type, $global, $additionalEventIds = array())
 {
     if ($type < self::NO_LICENSE_KNOWN_DECISION_TYPE) {
         return;
     }
     $this->dbManager->begin();
     $itemId = $itemBounds->getItemId();
     $previousEvents = $this->clearingDao->getRelevantClearingEvents($itemBounds, $groupId);
     if ($type === self::NO_LICENSE_KNOWN_DECISION_TYPE) {
         $type = DecisionTypes::IDENTIFIED;
         $clearingEventIds = $this->insertClearingEventsForAgentFindings($itemBounds, $userId, $groupId, true, ClearingEventTypes::USER);
         foreach ($previousEvents as $eventId => $clearingEvent) {
             if (!in_array($eventId, $clearingEventIds) && !$clearingEvent->isRemoved()) {
                 $licenseId = $clearingEvent->getLicenseId();
                 $newEventId = $this->clearingDao->insertClearingEvent($itemBounds->getItemId(), $userId, $groupId, $licenseId, true);
                 $clearingEventIds[$licenseId] = $newEventId;
             }
         }
     } else {
         $clearingEventIds = $this->insertClearingEventsForAgentFindings($itemBounds, $userId, $groupId, false, ClearingEventTypes::AGENT, $previousEvents);
         foreach ($previousEvents as $clearingEvent) {
             $clearingEventIds[$clearingEvent->getLicenseId()] = $clearingEvent->getEventId();
         }
     }
     $currentDecision = $this->clearingDao->getRelevantClearingDecision($itemBounds, $groupId);
     $clearingEventIds = array_unique(array_merge($clearingEventIds, $additionalEventIds));
     $scope = $global ? DecisionScopes::REPO : DecisionScopes::ITEM;
     if (null === $currentDecision || $this->clearingDecisionIsDifferentFrom($currentDecision, $type, $scope, $clearingEventIds)) {
         $this->clearingDao->createDecisionFromEvents($itemBounds->getItemId(), $userId, $groupId, $type, $scope, $clearingEventIds);
     } else {
         $this->clearingDao->removeWipClearingDecision($itemId, $groupId);
     }
     $this->dbManager->commit();
 }
예제 #2
0
 private function runnerDeciderRealShouldMakeNoDecisionForIrrelevantFiles($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $monkAgentId = 5;
     $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
     $licId1 = $licenseRef1->getId();
     $pfile = 4;
     $jobId = 16;
     $groupId = 2;
     $userId = 2;
     $itemId = 7;
     $itemTreeBounds = new ItemTreeBounds($itemId, 'uploadtree_a', $uploadId = 1, 15, 16);
     $this->dbManager->queryOnce("DELETE FROM license_file");
     /* insert NoLicenseKnown decisions */
     $this->dbManager->queryOnce("INSERT INTO clearing_decision (clearing_decision_pk, uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added)" . " VALUES (2, {$itemId}, {$pfile}, {$userId}, {$groupId}, " . DecisionTypes::IRRELEVANT . ", " . DecisionScopes::ITEM . ", '2015-05-04 11:43:18.276425+02')");
     $lastDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId);
     $lastClearingId = $lastDecision->getClearingId();
     $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,{$licId1},{$pfile},{$monkAgentId})");
     $this->dbManager->queryOnce("INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed, jq_log, jq_runonpfile, jq_host, jq_cmd_args)" . " VALUES ({$jobId}, 2, 'decider', '2', '2015-06-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, '-r8')");
     list($success, $output, $retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, '');
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'decider failed (did you make test?): ' . $output);
     $newDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId);
     assertThat($newDecision->getClearingId(), equalTo($lastClearingId));
     $this->rmRepo();
 }
예제 #3
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;
 }