FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ClearingDecisionFilter.php
1 <?php
2 /*
3 Copyright (C) 2014-2017,2020, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
20 
24 
30 {
33  const KEYREPO = "all";
34 
43  public function filterCurrentClearingDecisions($clearingDecisions)
44  {
45  /* @var ClearingDecision[][] $clearingDecisionsByItemId */
46  $clearingDecisionsMapped = array();
47 
48  foreach ($clearingDecisions as $clearingDecision) {
49  if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
50  continue;
51  }
52  $itemId = $clearingDecision->getUploadTreeId();
53  $fileId = $clearingDecision->getPfileId();
54  $scope = $clearingDecision->getScope();
55 
56  switch ($scope) {
57  case DecisionScopes::ITEM:
58  $clearingDecisionsMapped[$fileId][$itemId] = $clearingDecision;
59  break;
60 
61  case DecisionScopes::REPO:
62  $clearingDecisionsMapped[$fileId][self::KEYREPO] = $clearingDecision;
63  break;
64 
65  default:
66  throw new \InvalidArgumentException("unhandled clearing decision scope '" . $scope . "'");
67  }
68  }
69 
70  return $clearingDecisionsMapped;
71  }
72 
73 
81  public function filterCurrentClearingDecisionsForLicenseList($clearingDecisions)
82  {
83  $clearingDecisionsForLicList = array();
84 
85  foreach ($clearingDecisions as $clearingDecision) {
86 
87  if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
88  continue;
89  }
90 
91  foreach ($clearingDecision->getClearingLicenses() as $clearingLicense) {
92  if ($clearingLicense->isRemoved()) {
93  continue;
94  }
95  $itemId = $clearingDecision->getUploadTreeId();
96  $clearingDecisionsForLicList[$itemId][] = $clearingLicense->getShortName();
97  }
98  }
99  return $clearingDecisionsForLicList;
100  }
101 
102 
108  public function filterCurrentReusableClearingDecisions($clearingDecisions)
109  {
111  $clearingDecisionsByItemId = array();
112  foreach ($clearingDecisions as $clearingDecision) {
113  $itemId = $clearingDecision->getUploadTreeId();
114  $clearingDecisionsByItemId[$itemId] = $clearingDecision;
115  }
116  return $clearingDecisionsByItemId;
117  }
118 
124  public function getDecisionOf($decisionMap, $itemId, $pfileId)
125  {
126  if (array_key_exists($pfileId, $decisionMap)) {
127  $pfileMap = $decisionMap[$pfileId];
128  if (array_key_exists($itemId, $pfileMap)) {
129  return $pfileMap[$itemId];
130  }
131  if (array_key_exists(self::KEYREPO, $pfileMap)) {
132  return $pfileMap[self::KEYREPO];
133  }
134  }
135 
136  return false;
137  }
138 
148  public function filterCurrentClearingDecisionsForCopyrightList($clearingDecisions)
149  {
150  $clearingDecisionsForCopyList = array();
151 
152  foreach ($clearingDecisions as $clearingDecision) {
153  $itemId = $clearingDecision->getUploadTreeId();
154  $clearingDecisionsForCopyList[$itemId] = array();
155  if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
156  $clearingDecisionsForCopyList[$itemId][] = "Void";
157  continue;
158  }
159 
160  foreach ($clearingDecision->getClearingLicenses() as $clearingLicense) {
161  if ($clearingLicense->isRemoved()) {
162  continue;
163  }
164  $clearingDecisionsForCopyList[$itemId][] = $clearingLicense->getShortName();
165  }
166  if (empty($clearingDecisionsForCopyList[$itemId])) {
167  $clearingDecisionsForCopyList[$itemId][] = "Void";
168  }
169  }
170  return $clearingDecisionsForCopyList;
171  }
172 }
filterCurrentClearingDecisions($clearingDecisions)
Get the clearing decisions as a map of [<pfile-id>] => [<uploadtree-id>] => decision ...
filterCurrentClearingDecisionsForCopyrightList($clearingDecisions)
Get clearing decision as map of <item-id> => <license-shortnames> for copyright list.
Contains business rules for FOSSology.
Various utility functions to filter ClearingDecision.
getDecisionOf($decisionMap, $itemId, $pfileId)
For a given decision map, get the decision of the given item or pfile id.
filterCurrentClearingDecisionsForLicenseList($clearingDecisions)
Get clearing decision as map of <item-id> => <license-shortnames>