FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ClearingDecisionFilter.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2017, 2020 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
13 
19 {
22  const KEYREPO = "all";
23 
32  public function filterCurrentClearingDecisions($clearingDecisions)
33  {
34  /* @var ClearingDecision[][] $clearingDecisionsByItemId */
35  $clearingDecisionsMapped = array();
36 
37  foreach ($clearingDecisions as $clearingDecision) {
38  if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
39  continue;
40  }
41  $itemId = $clearingDecision->getUploadTreeId();
42  $fileId = $clearingDecision->getPfileId();
43  $scope = $clearingDecision->getScope();
44 
45  switch ($scope) {
46  case DecisionScopes::ITEM:
47  $clearingDecisionsMapped[$fileId][$itemId] = $clearingDecision;
48  break;
49 
50  case DecisionScopes::REPO:
51  $clearingDecisionsMapped[$fileId][self::KEYREPO] = $clearingDecision;
52  break;
53 
54  default:
55  throw new \InvalidArgumentException("unhandled clearing decision scope '" . $scope . "'");
56  }
57  }
58 
59  return $clearingDecisionsMapped;
60  }
61 
62 
70  public function filterCurrentClearingDecisionsForLicenseList($clearingDecisions)
71  {
72  $clearingDecisionsForLicList = array();
73 
74  foreach ($clearingDecisions as $clearingDecision) {
75 
76  if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
77  continue;
78  }
79 
80  foreach ($clearingDecision->getClearingLicenses() as $clearingLicense) {
81  if ($clearingLicense->isRemoved()) {
82  continue;
83  }
84  $itemId = $clearingDecision->getUploadTreeId();
85  $clearingDecisionsForLicList[$itemId][] = $clearingLicense->getShortName();
86  }
87  }
88  return $clearingDecisionsForLicList;
89  }
90 
91 
97  public function filterCurrentReusableClearingDecisions($clearingDecisions)
98  {
100  $clearingDecisionsByItemId = array();
101  foreach ($clearingDecisions as $clearingDecision) {
102  $itemId = $clearingDecision->getUploadTreeId();
103  $clearingDecisionsByItemId[$itemId] = $clearingDecision;
104  }
105  return $clearingDecisionsByItemId;
106  }
107 
113  public function getDecisionOf($decisionMap, $itemId, $pfileId)
114  {
115  if (array_key_exists($pfileId, $decisionMap)) {
116  $pfileMap = $decisionMap[$pfileId];
117  if (array_key_exists($itemId, $pfileMap)) {
118  return $pfileMap[$itemId];
119  }
120  if (array_key_exists(self::KEYREPO, $pfileMap)) {
121  return $pfileMap[self::KEYREPO];
122  }
123  }
124 
125  return false;
126  }
127 
137  public function filterCurrentClearingDecisionsForCopyrightList($clearingDecisions)
138  {
139  $clearingDecisionsForCopyList = array();
140 
141  foreach ($clearingDecisions as $clearingDecision) {
142  $itemId = $clearingDecision->getUploadTreeId();
143  $clearingDecisionsForCopyList[$itemId] = array();
144  if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
145  $clearingDecisionsForCopyList[$itemId][] = "Void";
146  continue;
147  }
148 
149  foreach ($clearingDecision->getClearingLicenses() as $clearingLicense) {
150  if ($clearingLicense->isRemoved()) {
151  continue;
152  }
153  $clearingDecisionsForCopyList[$itemId][] = $clearingLicense->getShortName();
154  }
155  if (empty($clearingDecisionsForCopyList[$itemId])) {
156  $clearingDecisionsForCopyList[$itemId][] = "Void";
157  }
158  }
159  return $clearingDecisionsForCopyList;
160  }
161 }
Various utility functions to filter ClearingDecision.
filterCurrentClearingDecisions($clearingDecisions)
Get the clearing decisions as a map of [<pfile-id>] => [<uploadtree-id>] => decision
getDecisionOf($decisionMap, $itemId, $pfileId)
For a given decision map, get the decision of the given item or pfile id.
filterCurrentClearingDecisionsForCopyrightList($clearingDecisions)
Get clearing decision as map of <item-id> => <license-shortnames> for copyright list.
filterCurrentClearingDecisionsForLicenseList($clearingDecisions)
Get clearing decision as map of <item-id> => <license-shortnames>
Contains business rules for FOSSology.