FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ScanOptions.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************
3 Copyright (C) 2017 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  ***************************************************************/
23 namespace Fossology\UI\Api\Models;
24 
30 
31 require_once dirname(dirname(__DIR__)) . "/agent-add.php";
32 require_once dirname(dirname(dirname(dirname(__DIR__)))) . "/lib/php/common-folders.php";
33 
39 {
44  private $analysis;
49  private $reuse;
54  private $decider;
55 
62  public function __construct($analysis, $reuse, $decider)
63  {
64  $this->analysis = $analysis;
65  $this->reuse = $reuse;
66  $this->decider = $decider;
67  }
68 
73  public function getArray()
74  {
75  return [
76  "analysis" => $this->analysis,
77  "reuse" => $this->reuse,
78  "decide" => $this->decider
79  ];
80  }
81 
89  public function scheduleAgents($folderId, $uploadId)
90  {
91  $uploadsAccessible = FolderListUploads_perm($folderId, Auth::PERM_WRITE);
92  $found = false;
93  foreach ($uploadsAccessible as $singleUpload) {
94  if ($singleUpload['upload_pk'] == $uploadId) {
95  $found = true;
96  break;
97  }
98  }
99  if ($found === false) {
100  return new Info(404, "Folder id $folderId does not have upload id ".
101  "$uploadId or you do not have write access to the folder.", InfoType::ERROR);
102  }
103 
104  $paramAgentRequest = new Request();
105  $agentsToAdd = $this->prepareAgents();
106  $this->prepareReuser($paramAgentRequest);
107  $this->prepareDecider($paramAgentRequest);
108  $returnStatus = (new \AgentAdder())->scheduleAgents($uploadId, $agentsToAdd, $paramAgentRequest);
109  if (is_numeric($returnStatus)) {
110  return new Info(201, $returnStatus, InfoType::INFO);
111  } else {
112  return new Info(403, $returnStatus, InfoType::ERROR);
113  }
114  }
115 
120  private function prepareAgents()
121  {
122  $agentsToAdd = [];
123  foreach ($this->analysis->getArray() as $agent => $set) {
124  if ($set === true) {
125  if ($agent == "copyright_email_author") {
126  $agentsToAdd[] = "agent_copyright";
127  } else {
128  $agentsToAdd[] = "agent_$agent";
129  }
130  }
131  }
132  return $agentsToAdd;
133  }
134 
139  private function prepareReuser(Request &$request)
140  {
141  if ($this->reuse->getReuseUpload() == 0) {
142  // No upload to reuse
143  return;
144  }
145  $reuserRules = [];
146  if ($this->reuse->getReuseMain() === true) {
147  $reuserRules[] = 'reuseMain';
148  }
149  if ($this->reuse->getReuseEnhanced() === true) {
150  $reuserRules[] = 'reuseEnhanced';
151  }
152  $reuserSelector = $this->reuse->getReuseUpload() . "," . $this->reuse->getReuseGroup();
153  $request->request->set(ReuserAgentPlugin::UPLOAD_TO_REUSE_SELECTOR_NAME, $reuserSelector);
154  //global $SysConf;
155  //$request->request->set('groupId', $SysConf['auth'][Auth::GROUP_ID]);
156  $request->request->set('reuseMode', $reuserRules);
157  }
158 
163  private function prepareDecider(Request &$request)
164  {
165  $deciderRules = [];
166  if ($this->decider->getNomosMonk() === true) {
167  $deciderRules[] = 'nomosInMonk';
168  }
169  if ($this->decider->getBulkReused() === true) {
170  $deciderRules[] = 'reuseBulk';
171  }
172  if ($this->decider->getNewScanner() === true) {
173  $deciderRules[] = 'wipScannerUpdates';
174  }
175  if ($this->decider->getOjoDecider() === true) {
176  $deciderRules[] = 'ojoNoContradiction';
177  }
178  $request->request->set('deciderRules', $deciderRules);
179  if ($this->analysis->getNomos()) {
180  $request->request->set('Check_agent_nomos', 1);
181  }
182  }
183 }
scheduleAgents($folderId, $uploadId)
Definition: ScanOptions.php:89
Model to hold add settings for new scan.
Definition: ScanOptions.php:38
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
__construct($analysis, $reuse, $decider)
Definition: ScanOptions.php:62
const UPLOAD_TO_REUSE_SELECTOR_NAME
Form element name for main license to reuse.
Info model to contain general error and return values.
Definition: Info.php:29