69 include_once(__DIR__ .
"/version.php");
77 const RULES_NOMOS_IN_MONK = 0x1;
78 const RULES_NOMOS_MONK_NINKA = 0x2;
79 const RULES_BULK_REUSE = 0x4;
80 const RULES_WIP_SCANNER_UPDATES = 0x8;
81 const RULES_OJO_NO_CONTRADICTION = 0x10;
82 const RULES_ALL = 0xf;
127 parent::__construct(AGENT_DECIDER_NAME, AGENT_DECIDER_VERSION, AGENT_DECIDER_REV);
129 $this->uploadDao = $this->container->get(
'dao.upload');
130 $this->clearingDao = $this->container->get(
'dao.clearing');
131 $this->highlightDao = $this->container->get(
'dao.highlight');
132 $this->showJobsDao = $this->container->get(
'dao.show_jobs');
133 $this->decisionTypes = $this->container->get(
'decision.types');
134 $this->clearingDecisionProcessor = $this->container->get(
'businessrules.clearing_decision_processor');
135 $this->agentLicenseEventProcessor = $this->container->get(
'businessrules.agent_license_event_processor');
138 $this->agentSpecifOptions =
"r:";
148 $this->activeRules = array_key_exists(
'r',
$args) ? intval(
$args[
'r']) : self::RULES_ALL;
149 $this->licenseMap =
new LicenseMap($this->
dbManager, $this->groupId, $this->licenseMapUsage);
151 if (array_key_exists(
"r",
$args) && (($this->activeRules&self::RULES_BULK_REUSE)== self::RULES_BULK_REUSE)) {
153 $bulkIds = $this->clearingDao->getPreviousBulkIds($uploadId, $this->groupId, $this->userId);
154 if (count($bulkIds) == 0) {
160 foreach ($bulkIds as $bulkId) {
161 $jqId = $bulkReuser->rerunBulkAndDeciderOnUpload($uploadId, $this->groupId, $this->userId, $bulkId, $jqId);
164 $jqIdRow = $this->showJobsDao->getDataForASingleJob($jqId);
165 while ($this->showJobsDao->getJobStatus($jqId)) {
167 $timeInSec = $this->showJobsDao->getEstimatedTime($jqIdRow[
'jq_job_fk'],
'',0,0,1);
168 if ($timeInSec > $maxTime) {
170 }
else if ($timeInSec < $minTime) {
179 $parentBounds = $this->uploadDao->getParentItemBounds($uploadId);
180 foreach ($this->uploadDao->getContainedItems($parentBounds) as $item) {
200 $unMappedMatches = $this->agentLicenseEventProcessor->getLatestScannerDetectedMatches($itemTreeBounds);
203 $lastDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $this->groupId);
205 if (null!==$lastDecision && $lastDecision->getType()==DecisionTypes::IRRELEVANT) {
209 $currentEvents = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $this->groupId);
212 if (null !== $lastDecision && $projectedScannerMatches
213 && ($this->activeRules & self::RULES_WIP_SCANNER_UPDATES) == self::RULES_WIP_SCANNER_UPDATES) {
214 $licensesFromDecision = array();
215 foreach ($lastDecision->getClearingLicenses() as $clearingLicense) {
216 $licenseIdFromEvent = $this->licenseMap->getProjectedId($clearingLicense->getLicenseId());
217 $licensesFromDecision[$licenseIdFromEvent] = $licenseIdFromEvent;
222 if (null !== $lastDecision && $markAsWip) {
227 if (null!==$lastDecision || 0<count($currentEvents)) {
231 $haveDecided =
false;
233 if (($this->activeRules&self::RULES_OJO_NO_CONTRADICTION) == self::RULES_OJO_NO_CONTRADICTION) {
237 if (!$haveDecided && ($this->activeRules&self::RULES_NOMOS_IN_MONK) == self::RULES_NOMOS_IN_MONK) {
241 if (!$haveDecided && ($this->activeRules&self::RULES_NOMOS_MONK_NINKA)== self::RULES_NOMOS_MONK_NINKA) {
245 if (!$haveDecided && $markAsWip) {
249 return ($haveDecided||$markAsWip ? 1 : 0);
260 foreach (array_keys($projectedScannerMatches) as $projectedLicenseId) {
261 if (!array_key_exists($projectedLicenseId, $licensesFromDecision)) {
278 $licenseMatchExists = count($matches) > 0;
279 foreach ($matches as $licenseMatches) {
283 if ($licenseMatchExists) {
284 $this->clearingDecisionProcessor->makeDecisionFromLastEvents($itemTreeBounds, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $global=
true);
286 return $licenseMatchExists;
299 $canDecide = (count($matches)>0);
301 foreach ($matches as $licenseMatches) {
309 $this->clearingDecisionProcessor->makeDecisionFromLastEvents($itemTreeBounds, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $global=
true);
324 $canDecide = (count($matches)>0);
326 foreach ($matches as $licenseMatches) {
334 $this->clearingDecisionProcessor->makeDecisionFromLastEvents($itemTreeBounds, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $global=
true);
348 foreach ($matches as $licenseId => $licenseMatches) {
349 $projectedId = $this->licenseMap->getProjectedId($licenseId);
351 foreach ($licenseMatches as $agent => $agentMatches) {
352 $haveId = array_key_exists($projectedId, $remapped);
353 $haveAgent = $haveId && array_key_exists($agent, $remapped[$projectedId]);
355 $remapped[$projectedId][$agent] = array_merge($remapped[$projectedId][$agent], $agentMatches);
357 $remapped[$projectedId][$agent] = $agentMatches;
372 return ($big[0] >= 0) && ($small[0] >= $big[0]) && ($small[1] <= $big[1]);
382 if (!array_key_exists(
"nomos", $licenseMatches)) {
385 if (!array_key_exists(
"monk", $licenseMatches)) {
389 foreach ($licenseMatches[
"nomos"] as $licenseMatch) {
390 $matchId = $licenseMatch->getLicenseFileId();
391 $nomosRegion = $this->highlightDao->getHighlightRegion($matchId);
394 foreach ($licenseMatches[
"monk"] as $monkLicenseMatch) {
395 $monkRegion = $this->highlightDao->getHighlightRegion($monkLicenseMatch->getLicenseFileId());
416 $scanners = array(
'nomos',
'monk',
'ninka');
418 foreach ($scanners as $scanner) {
419 if (!array_key_exists($scanner, $licenseMatches)) {
422 foreach ($licenseMatches[$scanner] as $licenseMatch) {
423 $licId = $licenseMatch->getLicenseId();
424 $vote[$licId][$scanner] =
true;
428 foreach ($vote as $licId=>$voters) {
429 if (count($voters) != 3) {
444 if (array_key_exists($scanner, $licenseMatches) ===
true) {
447 return $match->getLicenseId();
448 }, $licenseMatches[$scanner]);
461 if (count($findingsByOjo) == 0) {
467 if (count($findingsByOtherScanner) == 0) {
471 foreach ($findingsByOtherScanner as $findingsByScanner) {
472 if (in_array($findingsByScanner, $findingsByOjo) ===
false) {
heartbeat($newProcessed)
Send hear beat to the scheduler.
$agentLicenseEventProcessor
Structure of an Agent with all required parameters.
Namespace for decider agent.
Agent to decide license findings in an upload.
Wrapper class for license map.
areNomosMonkNinkaAgreed($licenseMatches)
Check if findings by all agents are same or not.
processItem(Item $item)
Given an item, check with the $activeRules and apply rules to it.
areNomosMatchesInsideAMonkMatch($licenseMatches)
Check if matches by nomos are inside monk findings.
autodecideNomosMonkNinka(ItemTreeBounds $itemTreeBounds, $matches)
Auto decide matches which are in nomos, monk and ninka findings.
existsUnhandledMatch($projectedScannerMatches, $licensesFromDecision)
Check if matches contains unhandled match.
getLicenseIdsOfMatchesForScanner($scanner, $licenseMatches)
extracts the matches corresponding to a scanner from a $licenseMatches structure
areOtherScannerFindingsAndOJOAgreed($licenseMatches)
Check if the finding by only contains one single license and that no other scanner (nomos) has produc...
autodecideNomosMatchesInsideMonk(ItemTreeBounds $itemTreeBounds, $matches)
Auto decide matches by nomos which are in monk findings.
$clearingDecisionProcessor
autodecideIfOjoMatchesNoContradiction(ItemTreeBounds $itemTreeBounds, $matches)
Auto decide matches which are in nomos, monk and OJO findings.
isRegionIncluded($small, $big)
Check if the small highlight region is inside big one.
fo_dbManager * dbManager
fo_dbManager object
processUploadId($uploadId)
Given an upload ID, process the items in it.
remapByProjectedId($matches)
Given a set of matches, remap according to project id instead of license id.
Prepares bulk licenses for an upload and run DeciderJob on it.