/**
  * @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();
 }
 function doEdit($userId, $groupId, $itemId)
 {
     $licenses = GetParm("licenseNumbersToBeSubmitted", PARM_RAW);
     $removed = $_POST['removed'] === 't' || $_POST['removed'] === 'true';
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId);
     $uploadId = $itemTreeBounds->getUploadId();
     $upload = $this->uploadDao->getUpload($uploadId);
     $uploadName = $upload->getFilename();
     $jobId = JobAddJob($userId, $groupId, $uploadName, $uploadId);
     if (isset($licenses)) {
         if (!is_array($licenses)) {
             return $this->errorJson("bad license array");
         }
         foreach ($licenses as $licenseId) {
             if (intval($licenseId) <= 0) {
                 return $this->errorJson("bad license");
             }
             $this->clearingDao->insertClearingEvent($itemId, $userId, $groupId, $licenseId, $removed, ClearingEventTypes::USER, $reportInfo = '', $comment = '', $jobId);
         }
     }
     /** @var agent_fodecider $deciderPlugin */
     $deciderPlugin = plugin_find("agent_deciderjob");
     $conflictStrategyId = null;
     $errorMsg = "";
     $jq_pk = $deciderPlugin->AgentAdd($jobId, $uploadId, $errorMsg, array(), $conflictStrategyId);
     /** after changing one license, purge all the report cache */
     ReportCachePurgeAll();
     //Todo: Change sql statement of fossology/src/buckets/agent/leaf.c line 124 to take the newest valid license, then uncomment this line
     // $this->ChangeBuckets(); // change bucket accordingly
     if (empty($errorMsg) && $jq_pk > 0) {
         return new JsonResponse(array("jqid" => $jq_pk));
     } else {
         return $this->errorJson($errorMsg, 500);
     }
 }
示例#3
0
 protected function insertDecisionFromTwoEvents($scope = DecisionScopes::ITEM, $originallyClearedItemId = 23)
 {
     $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
     $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef();
     $addedLicenses = array($licenseRef1, $licenseRef2);
     assertThat($addedLicenses, not(arrayContaining(null)));
     $clearingLicense1 = new ClearingLicense($licenseRef1, false, ClearingEventTypes::USER, "42", "44");
     $clearingLicense2 = new ClearingLicense($licenseRef2, true, ClearingEventTypes::USER, "-42", "-44");
     $eventId1 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, $this->userId, $this->groupId, $licenseRef1->getId(), $clearingLicense1->isRemoved(), $clearingLicense1->getType(), $clearingLicense1->getReportinfo(), $clearingLicense1->getComment());
     $eventId2 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, 5, $this->groupId, $licenseRef2->getId(), $clearingLicense2->isRemoved(), $clearingLicense2->getType(), $clearingLicense2->getReportinfo(), $clearingLicense2->getComment());
     $addedEventIds = array($eventId1, $eventId2);
     $this->clearingDao->createDecisionFromEvents($originallyClearedItemId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $scope, $addedEventIds);
     return array($clearingLicense1, $clearingLicense2, $addedEventIds);
 }
 /**
  * @return Response
  */
 function Output()
 {
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     $action = GetParm("do", PARM_STRING);
     $uploadId = GetParm("upload", PARM_INTEGER);
     $uploadTreeId = GetParm("item", PARM_INTEGER);
     $licenseId = GetParm("licenseId", PARM_INTEGER);
     $sort0 = GetParm("sSortDir_0", PARM_STRING);
     $orderAscending = isset($sort0) ? $sort0 === "asc" : true;
     switch ($action) {
         case "licenses":
             return new JsonResponse($this->doLicenses($orderAscending, $groupId, $uploadId, $uploadTreeId));
         case "licenseDecisions":
             return new JsonResponse($this->doClearings($orderAscending, $groupId, $uploadId, $uploadTreeId));
         case "addLicense":
             $this->clearingDao->insertClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, false, ClearingEventTypes::USER);
             return new JsonResponse();
         case "removeLicense":
             $this->clearingDao->insertClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, true, ClearingEventTypes::USER);
             return new JsonResponse();
         case "makeMainLicense":
             $this->clearingDao->makeMainLicense($uploadId, $groupId, $licenseId);
             return new JsonResponse();
         case "removeMainLicense":
             $this->clearingDao->removeMainLicense($uploadId, $groupId, $licenseId);
             return new JsonResponse();
         case "setNextPrev":
         case "setNextPrevCopyRight":
         case "setNextPrevIp":
         case "setNextPrevEcc":
             return new JsonResponse($this->doNextPrev($action, $uploadId, $uploadTreeId, $groupId));
         case "updateClearings":
             $id = GetParm("id", PARM_STRING);
             if (isset($id)) {
                 list($uploadTreeId, $licenseId) = explode(',', $id);
                 $what = GetParm("columnId", PARM_INTEGER) == 3 ? 'comment' : 'reportinfo';
                 $changeTo = GetParm("value", PARM_RAW);
                 $this->clearingDao->updateClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $what, $changeTo);
             }
             return $this->createPlainResponse("success");
         default:
             return $this->createPlainResponse("fail");
     }
 }
示例#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();
 }