72 if (!empty($licenseMap) && !($licenseMap instanceof
LicenseMap)) {
73 throw new Exception(
'invalid license map');
75 $userEvents = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $groupId);
76 $usageId = empty($licenseMap) ? LicenseMap::TRIVIAL : $licenseMap->getUsage();
77 $scannerDetectedEvents = $this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds,$usageId);
78 $eventLicenceIds = array();
79 foreach (array_keys($userEvents) as $licenseId) {
80 $eventLicenceIds[empty($licenseMap)? $licenseId: $licenseMap->getProjectedId($licenseId)] = $licenseId;
82 foreach (array_keys($additionalEventIds) as $licenseId) {
83 $eventLicenceIds[empty($licenseMap)? $licenseId: $licenseMap->getProjectedId($licenseId)] = $licenseId;
85 foreach (array_keys($scannerDetectedEvents) as $licenseId) {
86 if (!array_key_exists(empty($licenseMap)? $licenseId: $licenseMap->getProjectedId($licenseId), $eventLicenceIds)) {
106 foreach ($this->agentLicenseEventProcessor->getScannerEvents($itemBounds) as $licenseId => $scannerEvents) {
107 if (array_key_exists($licenseId, $removedIds)) {
110 $scannerLicenseRef = $scannerEvents[0]->getLicenseRef();
111 $eventIds[$scannerLicenseRef->getId()] = $this->clearingDao->insertClearingEvent($itemBounds->
getItemId(), $userId, $groupId, $scannerLicenseRef->getId(), $remove, $type);
127 if (count($clearingEvents) != count($clearingEventIds)) {
131 foreach ($clearingEvents as $clearingEvent) {
132 if (
false === array_search($clearingEvent->getEventId(), $clearingEventIds)) {
136 return ($type !== $decision->
getType()) || ($scope !== $decision->
getScope());
150 if ($type < self::NO_LICENSE_KNOWN_DECISION_TYPE) {
156 $includeSubFolders =
false;
157 if (($global == DecisionScopes::REPO) && ($type != self::NO_LICENSE_KNOWN_DECISION_TYPE)) {
158 $includeSubFolders =
true;
160 $previousEvents = $this->clearingDao->getRelevantClearingEvents($itemBounds, $groupId, $includeSubFolders);
161 if ($type === self::NO_LICENSE_KNOWN_DECISION_TYPE) {
162 $type = DecisionTypes::IDENTIFIED;
164 foreach ($previousEvents as $eventId => $clearingEvent) {
165 if (!in_array($eventId, $clearingEventIds) && !$clearingEvent->isRemoved()) {
166 $licenseId = $clearingEvent->getLicenseId();
167 $newEventId = $this->clearingDao->insertClearingEvent($itemBounds->
getItemId(), $userId, $groupId, $licenseId,
true);
168 $clearingEventIds[$licenseId] = $newEventId;
173 foreach ($previousEvents as $clearingEvent) {
174 $clearingEventIds[$clearingEvent->getLicenseId()] = $clearingEvent->getEventId();
178 $currentDecision = $this->clearingDao->getRelevantClearingDecision($itemBounds, $groupId);
179 $clearingEventIds = array_unique(array_merge($clearingEventIds, $additionalEventIds));
181 $scope = $global ? DecisionScopes::REPO : DecisionScopes::ITEM;
183 $this->clearingDao->createDecisionFromEvents($itemBounds->
getItemId(), $userId, $groupId, $type, $scope,
186 $this->clearingDao->removeWipClearingDecision($itemId, $groupId);
202 $agentEvents = $this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds, $usageId);
203 $events = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $groupId);
205 $addedResults = array();
206 $removedResults = array();
208 foreach (array_unique(array_merge(array_keys($events), array_keys($agentEvents))) as $licenseId) {
209 $licenseDecisionEvent = array_key_exists($licenseId, $events) ? $events[$licenseId] :
null;
210 $agentClearingEvents = array_key_exists($licenseId, $agentEvents) ? $agentEvents[$licenseId] : array();
212 if (($licenseDecisionEvent ===
null) && (count($agentClearingEvents) == 0)) {
215 $licenseDecisionResult =
new ClearingResult($licenseDecisionEvent, $agentClearingEvents);
216 if ($licenseDecisionResult->isRemoved()) {
217 $removedResults[$licenseId] = $licenseDecisionResult;
219 $addedResults[$licenseId] = $licenseDecisionResult;
223 return array($addedResults, $removedResults);
Handle events related to license findings.
Utility functions to process ClearingDecision.
getCurrentClearings(ItemTreeBounds $itemTreeBounds, $groupId, $usageId=LicenseMap::TRIVIAL)
For a given item, get the clearing decisions.
const NO_LICENSE_KNOWN_DECISION_TYPE
makeDecisionFromLastEvents(ItemTreeBounds $itemBounds, $userId, $groupId, $type, $global, $additionalEventIds=array())
Create clearing decisions from clearing events.
insertClearingEventsForAgentFindings(ItemTreeBounds $itemBounds, $userId, $groupId, $remove=false, $type=ClearingEventTypes::AGENT, $removedIds=array())
Insert clearing events in DB for agent findings.
$agentLicenseEventProcessor
__construct(ClearingDao $clearingDao, AgentLicenseEventProcessor $agentLicenseEventProcessor, ClearingEventProcessor $clearingEventProcessor, DbManager $dbManager)
hasUnhandledScannerDetectedLicenses(ItemTreeBounds $itemTreeBounds, $groupId, $additionalEventIds=array(), $licenseMap=null)
clearingDecisionIsDifferentFrom(ClearingDecision $decision, $type, $scope, $clearingEventIds)
Check if clearing decisions are different from clearing event ids.
Functions to process clearing events.
Wrapper class for license map.
fo_dbManager * dbManager
fo_dbManager object
Contains business rules for FOSSology.