83 if (!empty($licenseMap) && !($licenseMap instanceof
LicenseMap)) {
84 throw new Exception(
'invalid license map');
86 $userEvents = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $groupId);
87 $usageId = empty($licenseMap) ? LicenseMap::TRIVIAL : $licenseMap->getUsage();
88 $scannerDetectedEvents = $this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds,$usageId);
89 $eventLicenceIds = array();
90 foreach (array_keys($userEvents) as $licenseId) {
91 $eventLicenceIds[empty($licenseMap)? $licenseId: $licenseMap->getProjectedId($licenseId)] = $licenseId;
93 foreach (array_keys($additionalEventIds) as $licenseId) {
94 $eventLicenceIds[empty($licenseMap)? $licenseId: $licenseMap->getProjectedId($licenseId)] = $licenseId;
96 foreach (array_keys($scannerDetectedEvents) as $licenseId) {
97 if (!array_key_exists(empty($licenseMap)? $licenseId: $licenseMap->getProjectedId($licenseId), $eventLicenceIds)) {
117 foreach ($this->agentLicenseEventProcessor->getScannerEvents($itemBounds) as $licenseId => $scannerEvents) {
118 if (array_key_exists($licenseId, $removedIds)) {
121 $scannerLicenseRef = $scannerEvents[0]->getLicenseRef();
122 $eventIds[$scannerLicenseRef->getId()] = $this->clearingDao->insertClearingEvent($itemBounds->
getItemId(), $userId, $groupId, $scannerLicenseRef->getId(), $remove, $type);
138 if (count($clearingEvents) != count($clearingEventIds)) {
142 foreach ($clearingEvents as $clearingEvent) {
143 if (
false === array_search($clearingEvent->getEventId(), $clearingEventIds)) {
147 return ($type !== $decision->
getType()) || ($scope !== $decision->
getScope());
161 if ($type < self::NO_LICENSE_KNOWN_DECISION_TYPE) {
168 $previousEvents = $this->clearingDao->getRelevantClearingEvents($itemBounds, $groupId, $includeSubFolders=
false);
169 if ($type === self::NO_LICENSE_KNOWN_DECISION_TYPE) {
170 $type = DecisionTypes::IDENTIFIED;
172 foreach ($previousEvents as $eventId => $clearingEvent) {
173 if (!in_array($eventId, $clearingEventIds) && !$clearingEvent->isRemoved()) {
174 $licenseId = $clearingEvent->getLicenseId();
175 $newEventId = $this->clearingDao->insertClearingEvent($itemBounds->
getItemId(), $userId, $groupId, $licenseId,
true);
176 $clearingEventIds[$licenseId] = $newEventId;
181 foreach ($previousEvents as $clearingEvent) {
182 $clearingEventIds[$clearingEvent->getLicenseId()] = $clearingEvent->getEventId();
186 $currentDecision = $this->clearingDao->getRelevantClearingDecision($itemBounds, $groupId);
187 $clearingEventIds = array_unique(array_merge($clearingEventIds, $additionalEventIds));
189 $scope = $global ? DecisionScopes::REPO : DecisionScopes::ITEM;
191 $this->clearingDao->createDecisionFromEvents($itemBounds->
getItemId(), $userId, $groupId, $type, $scope,
194 $this->clearingDao->removeWipClearingDecision($itemId, $groupId);
210 $agentEvents = $this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds, $usageId);
211 $events = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $groupId);
213 $addedResults = array();
214 $removedResults = array();
216 foreach (array_unique(array_merge(array_keys($events), array_keys($agentEvents))) as $licenseId) {
217 $licenseDecisionEvent = array_key_exists($licenseId, $events) ? $events[$licenseId] : null;
218 $agentClearingEvents = array_key_exists($licenseId, $agentEvents) ? $agentEvents[$licenseId] : array();
220 if (($licenseDecisionEvent === null) && (count($agentClearingEvents) == 0)) {
223 $licenseDecisionResult =
new ClearingResult($licenseDecisionEvent, $agentClearingEvents);
224 if ($licenseDecisionResult->isRemoved()) {
225 $removedResults[$licenseId] = $licenseDecisionResult;
227 $addedResults[$licenseId] = $licenseDecisionResult;
231 return array($addedResults, $removedResults);
$agentLicenseEventProcessor
Utility functions to process ClearingDecision.
makeDecisionFromLastEvents(ItemTreeBounds $itemBounds, $userId, $groupId, $type, $global, $additionalEventIds=array())
Create clearing decisions from clearing events.
Handle events related to license findings.
Functions to process clearing events.
__construct(ClearingDao $clearingDao, AgentLicenseEventProcessor $agentLicenseEventProcessor, ClearingEventProcessor $clearingEventProcessor, DbManager $dbManager)
clearingDecisionIsDifferentFrom(ClearingDecision $decision, $type, $scope, $clearingEventIds)
Check if clearing decisions are different from clearing event ids.
getCurrentClearings(ItemTreeBounds $itemTreeBounds, $groupId, $usageId=LicenseMap::TRIVIAL)
For a given item, get the clearing decisions.
Wrapper class for license map.
Contains business rules for FOSSology.
hasUnhandledScannerDetectedLicenses(ItemTreeBounds $itemTreeBounds, $groupId, $additionalEventIds=array(), $licenseMap=null)
fo_dbManager * dbManager
fo_dbManager object
const NO_LICENSE_KNOWN_DECISION_TYPE
insertClearingEventsForAgentFindings(ItemTreeBounds $itemBounds, $userId, $groupId, $remove=false, $type=ClearingEventTypes::AGENT, $removedIds=array())
Insert clearing events in DB for agent findings.