FOSSology  4.7.1
Open Source License Compliance by Open Source Software
UploadHelper.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2018, 2020 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5  SPDX-FileContributor: Kaushlendra Pratap <kaushlendra-pratap.singh@siemens.com>
6 
7  SPDX-License-Identifier: GPL-2.0-only
8 */
9 
14 namespace Fossology\UI\Api\Helper;
15 
41 use Symfony\Component\HttpFoundation\File\UploadedFile;
42 use UIExportList;
43 
49 {
54  private $uploadFilePage;
55 
60  private $uploadVcsPage;
61 
66  private $uploadUrlPage;
67 
72  private $uploadSrvPage;
73 
78  const VALID_VCS_TYPES = array(
79  "git",
80  "svn"
81  );
82 
87  const VALID_UPLOAD_TYPES = array(
88  "vcs",
89  "url",
90  "server"
91  );
92 
96  public function __construct()
97  {
98  $this->uploadFilePage = new HelperToUploadFilePage();
99  $this->uploadVcsPage = new HelperToUploadVcsPage();
100  $this->uploadUrlPage = new HelperToUploadUrlPage();
101  $this->uploadSrvPage = new HelperToUploadSrvPage();
102  }
103 
115  public function handleScheduleAnalysis($uploadId, $folderId, $scanOptionsJSON,
116  $newUpload = false, $apiVersion = ApiVersion::V1)
117  {
118  global $container;
119  $restHelper = $container->get('helper.restHelper');
120 
121  $parametersSent = false;
122  $analysis = new Analysis();
123 
124  if (array_key_exists("analysis", $scanOptionsJSON) && ! empty($scanOptionsJSON["analysis"])) {
125  $analysis->setUsingArray($scanOptionsJSON["analysis"], $apiVersion);
126  $parametersSent = true;
127  }
128 
129  $decider = new Decider();
130  $decider->setDeciderAgentPlugin($restHelper->getPlugin('agent_decider'));
131  if (array_key_exists("decider", $scanOptionsJSON) && ! empty($scanOptionsJSON["decider"])) {
132  $decider->setUsingArray($scanOptionsJSON["decider"], $apiVersion);
133  $parametersSent = true;
134  }
135 
136  $scancode = new Scancode();
137  if (array_key_exists("scancode", $scanOptionsJSON) && ! empty($scanOptionsJSON["scancode"])) {
138  $scancode->setUsingArray($scanOptionsJSON["scancode"]);
139  $parametersSent = true;
140  }
141 
142  $reuser = new Reuser(0, 'groupName', false, false);
143  try {
144  if (array_key_exists("reuse", $scanOptionsJSON) && ! empty($scanOptionsJSON["reuse"])) {
145  $reuser->setUsingArray($scanOptionsJSON["reuse"], $apiVersion);
146  $parametersSent = true;
147  }
148  } catch (\UnexpectedValueException $e) {
149  throw new HttpBadRequestException($e->getMessage(), $e);
150  }
151 
152  if ($decider->getBulkReused() === true) {
153  $reuser->setReuseBulk(true);
154  }
155 
156  if (! $parametersSent) {
157  throw new HttpBadRequestException("No parameters selected for agents!");
158  }
159 
160  $scanOptions = new ScanOptions($analysis, $reuser, $decider, $scancode);
161  return $scanOptions->scheduleAgents($folderId, $uploadId, $newUpload);
162  }
163 
164 
181  public function createNewUpload($reqBody, $folderId, $fileDescription,
182  $isPublic, $ignoreScm, $uploadType,
183  $applyGlobal = false, $excludefolder = false)
184  {
185  $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
186  $uploadedFile = $symReq->files->get($this->uploadFilePage::FILE_INPUT_NAME,
187  null);
188 
189  if ($applyGlobal) {
190  // If global decisions should be ignored
191  $applyGlobal = 1;
192  } else {
193  $applyGlobal = 0;
194  }
195  if ($excludefolder) {
196  // If configured folder should be ignored
197  $excludefolder = 1;
198  } else {
199  $excludefolder = 0;
200  }
201 
202  if (! empty($ignoreScm) && ($ignoreScm == "true")) {
203  // If SCM should be ignored
204  $ignoreScm = 1;
205  } else {
206  $ignoreScm = 0;
207  }
208  if (empty($uploadedFile)) {
209  if (empty($uploadType)) {
210  return array(false, "Missing 'uploadType' header",
211  "Send file with parameter " . $this->uploadFilePage::FILE_INPUT_NAME .
212  " or define 'uploadType' header with appropriate body.",
213  - 1
214  );
215  }
216  return $this->handleUpload($reqBody, $uploadType, $folderId,
217  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
218  } else {
219  return $this->createFileUpload($uploadedFile, $folderId,
220  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
221  }
222  }
223 
236  private function createFileUpload($uploadedFile, $folderId, $fileDescription,
237  $isPublic, $ignoreScm = 0, $applyGlobal = 0, $excludefolder = 0)
238  {
239  $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
240  $symfonySession = $GLOBALS['container']->get('session');
241  $symfonySession->set(
242  $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
243 
244  $symfonyRequest->request->set($this->uploadFilePage::FOLDER_PARAMETER_NAME,
245  $folderId);
246  $symfonyRequest->request->set(
247  $this->uploadFilePage::DESCRIPTION_INPUT_NAME,
248  [$fileDescription]);
249  $symfonyRequest->files->set($this->uploadFilePage::FILE_INPUT_NAME,
250  [$uploadedFile]);
251  $symfonyRequest->setSession($symfonySession);
252  $symfonyRequest->request->set(
253  $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
254  $symfonyRequest->request->set('public', $isPublic);
255  $symfonyRequest->request->set('globalDecisions', $applyGlobal);
256  $symfonyRequest->request->set('scm', $ignoreScm);
257  $symfonyRequest->request->set('excludefolder', $excludefolder);
258 
259  return $this->uploadFilePage->handleRequest($symfonyRequest);
260  }
261 
275  private function handleUpload($body, $uploadType, $folderId, $fileDescription,
276  $isPublic, $ignoreScm = 0, $applyGlobal = 0, $excludefolder = 0)
277  {
278  $sanity = false;
279  switch ($uploadType) {
280  case "vcs":
281  $sanity = $this->sanitizeVcsData($body);
282  break;
283  case "url":
284  $sanity = $this->sanitizeUrlData($body);
285  break;
286  case "server":
287  $sanity = $this->sanitizeSrvData($body);
288  break;
289  default:
290  $message = "Invalid 'uploadType'";
291  $statusDescription = "uploadType should be any of (" .
292  implode(",", self::VALID_UPLOAD_TYPES) . ")";
293  $code = 400;
294  $sanity = array(false, $message, $statusDescription, $code);
295  }
296  if ($sanity !== true) {
297  return $sanity;
298  }
299  $uploadResponse = false;
300  switch ($uploadType) {
301  case "vcs":
302  $uploadResponse = $this->generateVcsUpload($body, $folderId,
303  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
304  break;
305  case "url":
306  $uploadResponse = $this->generateUrlUpload($body, $folderId,
307  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
308  break;
309  case "server":
310  $uploadResponse = $this->generateSrvUpload($body, $folderId,
311  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
312  break;
313  }
314  return $uploadResponse;
315  }
316 
327  private function sanitizeVcsData(&$vcsData)
328  {
329  $message = "";
330  $statusDescription = "";
331  $code = 0;
332 
333  if (! array_key_exists("vcsType", $vcsData) ||
334  ! in_array($vcsData["vcsType"], self::VALID_VCS_TYPES)) {
335  $message = "Missing vcsType";
336  $statusDescription = "vcsType should be any of (" .
337  implode(", ", self::VALID_VCS_TYPES) . ")";
338  $code = 400;
339  }
340  $vcsType = "";
341  if ($vcsData["vcsType"] == "git") {
342  $vcsType = "Git";
343  } else {
344  $vcsType = "SVN";
345  }
346 
347  if (! array_key_exists("vcsUrl", $vcsData)) {
348  $message = "Missing vcsUrl";
349  $statusDescription = "vcsUrl should be passed.";
350  $code = 400;
351  }
352 
353  if (! array_key_exists("vcsName", $vcsData)) {
354  $vcsData["vcsName"] = "";
355  }
356  if (! array_key_exists("vcsUsername", $vcsData)) {
357  $vcsData["vcsUsername"] = "";
358  }
359  if (! array_key_exists("vcsPassword", $vcsData)) {
360  $vcsData["vcsPassword"] = "";
361  }
362  if (! array_key_exists("vcsBranch", $vcsData)) {
363  $vcsData["vcsBranch"] = "";
364  }
365  $vcsData["vcsType"] = $vcsType;
366  if ($code !== 0) {
367  return array(false, $message, $statusDescription, $code);
368  } else {
369  return true;
370  }
371  }
372 
382  private function sanitizeUrlData(&$urlData)
383  {
384  $message = "";
385  $statusDescription = "";
386  $code = 0;
387 
388  if (! array_key_exists("url", $urlData)) {
389  $message = "Missing url";
390  $statusDescription = "Missing upload url from request";
391  $code = 400;
392  }
393 
394  if (! array_key_exists("name", $urlData)) {
395  $urlData["name"] = "";
396  }
397  if (! array_key_exists("accept", $urlData)) {
398  $urlData["accept"] = "";
399  }
400  if (! array_key_exists("reject", $urlData)) {
401  $urlData["reject"] = "";
402  }
403  if (! array_key_exists("maxRecursionDepth", $urlData)) {
404  $urlData["maxRecursionDepth"] = "";
405  }
406  if ($code !== 0) {
407  return array(false, $message, $statusDescription, $code);
408  } else {
409  return true;
410  }
411  }
412 
422  private function sanitizeSrvData(&$srvData)
423  {
424  $message = "";
425  $statusDescription = "";
426  $code = 0;
427 
428  if (! array_key_exists("path", $srvData)) {
429  $message = "Missing path";
430  $statusDescription = "Missing upload path from request";
431  $code = 400;
432  }
433 
434  if (! array_key_exists("name", $srvData)) {
435  $srvData["name"] = "";
436  }
437  if ($code !== 0) {
438  return array(false, $message, $statusDescription, $code);
439  } else {
440  return true;
441  }
442  }
443 
455  private function generateVcsUpload($vcsData, $folderId, $fileDescription,
456  $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
457  {
458  $vcsType = $vcsData["vcsType"];
459  $vcsUrl = $vcsData["vcsUrl"];
460  $vcsName = $vcsData["vcsName"];
461  $vcsUsername = $vcsData["vcsUsername"];
462  $vcsPasswd = $vcsData["vcsPassword"];
463  $vcsBranch = $vcsData["vcsBranch"];
464 
465  $symfonySession = $GLOBALS['container']->get('session');
466  $symfonySession->set($this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
467  "restUpload");
468 
469  $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
470  $symfonyRequest->setSession($symfonySession);
471 
472  $symfonyRequest->request->set($this->uploadVcsPage::FOLDER_PARAMETER_NAME,
473  $folderId);
474  $symfonyRequest->request->set($this->uploadVcsPage::DESCRIPTION_INPUT_NAME,
475  $fileDescription);
476  $symfonyRequest->request->set($this->uploadVcsPage::GETURL_PARAM, $vcsUrl);
477  $symfonyRequest->request->set(
478  $this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
479  $symfonyRequest->request->set('public', $isPublic);
480  $symfonyRequest->request->set('name', $vcsName);
481  $symfonyRequest->request->set('vcstype', $vcsType);
482  $symfonyRequest->request->set('username', $vcsUsername);
483  $symfonyRequest->request->set('passwd', $vcsPasswd);
484  $symfonyRequest->request->set('branch', $vcsBranch);
485  $symfonyRequest->request->set('globalDecisions', $applyGlobal);
486  $symfonyRequest->request->set('scm', $ignoreScm);
487  $symfonyRequest->request->set('excludefolder', $excludefolder);
488 
489  return $this->uploadVcsPage->handleRequest($symfonyRequest);
490  }
491 
503  private function generateUrlUpload($urlData, $folderName, $fileDescription,
504  $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
505  {
506  $url = $urlData["url"];
507  $name = $urlData["name"];
508  $accept = $urlData["accept"];
509  $reject = $urlData["reject"];
510  $maxRecursionDepth = $urlData["maxRecursionDepth"];
511 
512  $symfonySession = $GLOBALS['container']->get('session');
513  $symfonySession->set($this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
514  "restUpload");
515 
516  $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
517  $symfonyRequest->setSession($symfonySession);
518 
519  $symfonyRequest->request->set($this->uploadUrlPage::FOLDER_PARAMETER_NAME,
520  $folderName);
521  $symfonyRequest->request->set($this->uploadUrlPage::DESCRIPTION_INPUT_NAME,
522  $fileDescription);
523  $symfonyRequest->request->set(
524  $this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
525  $symfonyRequest->request->set('public', $isPublic);
526  $symfonyRequest->request->set($this->uploadUrlPage::NAME_PARAM, $name);
527  $symfonyRequest->request->set($this->uploadUrlPage::ACCEPT_PARAM, $accept);
528  $symfonyRequest->request->set($this->uploadUrlPage::REJECT_PARAM, $reject);
529  $symfonyRequest->request->set($this->uploadUrlPage::GETURL_PARAM, $url);
530  $symfonyRequest->request->set($this->uploadUrlPage::LEVEL_PARAM,
531  $maxRecursionDepth);
532  $symfonyRequest->request->set('globalDecisions', $applyGlobal);
533  $symfonyRequest->request->set('scm', $ignoreScm);
534  $symfonyRequest->request->set('excludefolder', $excludefolder);
535 
536  return $this->uploadUrlPage->handleRequest($symfonyRequest);
537  }
538 
550  private function generateSrvUpload($srvData, $folderName, $fileDescription,
551  $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
552  {
553  $path = $srvData["path"];
554  $name = $srvData["name"];
555 
556  $symfonySession = $GLOBALS['container']->get('session');
557  $symfonySession->set($this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
558  "restUpload");
559 
560  $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
561  $symfonyRequest->setSession($symfonySession);
562 
563  $symfonyRequest->request->set($this->uploadSrvPage::FOLDER_PARAMETER_NAME,
564  $folderName);
565  $symfonyRequest->request->set($this->uploadSrvPage::DESCRIPTION_INPUT_NAME,
566  $fileDescription);
567  $symfonyRequest->request->set(
568  $this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
569  $symfonyRequest->request->set('public', $isPublic);
570  $symfonyRequest->request->set($this->uploadSrvPage::SOURCE_FILES_FIELD,
571  $path);
572  $symfonyRequest->request->set($this->uploadSrvPage::NAME_PARAM, $name);
573  $symfonyRequest->request->set('globalDecisions', $applyGlobal);
574  $symfonyRequest->request->set('scm', $ignoreScm);
575  $symfonyRequest->request->set('excludefolder', $excludefolder);
576 
577  return $this->uploadSrvPage->handleRequest($symfonyRequest);
578  }
579 
586  public function generateUploadSummary($uploadId, $groupId)
587  {
588  global $container;
589  $restHelper = $container->get('helper.restHelper');
590  $uploadDao = $restHelper->getUploadDao();
591  $dbManager = $restHelper->getDbHelper()->getDbManager();
592  $copyrightDao = $container->get('dao.copyright');
593  $agentDao = $container->get('dao.agent');
594 
595  $agentName = "copyright";
596  $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
597 
598  $noLicenseUploadTreeView = new UploadTreeProxy($uploadId,
599  array(UploadTreeProxy::OPT_SKIP_THESE => "noLicense",
600  UploadTreeProxy::OPT_GROUP_ID => $groupId),
601  $uploadTreeTableName,
602  'no_license_uploadtree' . $uploadId);
603  $clearingCount = $noLicenseUploadTreeView->count();
604 
605  $nonClearedUploadTreeView = new UploadTreeProxy($uploadId,
606  array(UploadTreeProxy::OPT_SKIP_THESE => "alreadyCleared",
607  UploadTreeProxy::OPT_GROUP_ID => $groupId),
608  $uploadTreeTableName,
609  'already_cleared_uploadtree' . $uploadId);
610  $filesToBeCleared = $nonClearedUploadTreeView->count();
611 
612  $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
613  $uploadTreeTableName);
614  $scanProx = new ScanJobProxy($agentDao, $uploadId);
615  $scanProx->createAgentStatus([$agentName]);
616  $agents = $scanProx->getLatestSuccessfulAgentIds();
617  $copyrightCount = 0;
618  if (array_key_exists($agentName, $agents) && ! empty($agents[$agentName])) {
619  $copyrightCount = count(
620  $copyrightDao->getAllEntriesReport($agentName, $uploadId,
621  $uploadTreeTableName, null, false, null, "C.agent_fk = " .
622  $agents[$agentName], $groupId));
623  }
624 
625  $mainLicenses = $this->getMainLicenses($dbManager, $uploadId, $groupId);
626 
628  $uiLicense = $restHelper->getPlugin("license");
629  $hist = $uiLicense->getUploadHist($itemTreeBounds);
630  if (!is_array($hist) || !array_key_exists('uniqueLicenseCount', $hist)) {
631  $hist = [];
632  $hist['uniqueLicenseCount'] = 0;
633  $hist['scannerLicenseCount'] = 0;
634  $hist['editedUniqueLicenseCount'] = 0;
635  $hist['editedLicenseCount'] = 0;
636  }
637 
638  $summary = new UploadSummary();
639  $summary->setUploadId($uploadId);
640  $summary->setUploadName($uploadDao->getUpload($uploadId)->getFilename());
641  $summary->setAssignee($uploadDao->getAssignee($uploadId, $groupId));
642  if ($mainLicenses !== null) {
643  $summary->setMainLicense(implode(",", $mainLicenses));
644  }
645  $summary->setUniqueLicenses($hist['uniqueLicenseCount']);
646  $summary->setTotalLicenses($hist['scannerLicenseCount']);
647  $summary->setUniqueConcludedLicenses($hist['editedUniqueLicenseCount']);
648  $summary->setTotalConcludedLicenses($hist['editedLicenseCount']);
649  $summary->setFilesToBeCleared($filesToBeCleared);
650  $summary->setFilesCleared($clearingCount);
651  $summary->setClearingStatus($uploadDao->getStatus($uploadId, $groupId));
652  $summary->setCopyrightCount($copyrightCount);
653  return $summary;
654  }
655 
663  private function getMainLicenses($dbManager, $uploadId, $groupId)
664  {
665  $sql = "SELECT rf_shortname FROM license_ref lf JOIN upload_clearing_license ucl"
666  . " ON lf.rf_pk=ucl.rf_fk WHERE upload_fk=$1 AND ucl.group_fk=$2";
667  $stmt = __METHOD__.'.collectMainLicenses';
668  $rows = $dbManager->getRows($sql, array($uploadId, $groupId), $stmt);
669  if (empty($rows)) {
670  return null;
671  }
672  $mainLicenses = [];
673  foreach ($rows as $row) {
674  $mainLicenses[] = $row['rf_shortname'];
675  }
676  return $mainLicenses;
677  }
678 
685  public function getUploadCopyrightList($uploadId)
686  {
687  global $container;
688  $restHelper = $container->get('helper.restHelper');
689  $uploadDao = $restHelper->getUploadDao();
690 
691  $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
692  $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
693 
697  $copyrightListObj = $restHelper->getPlugin('export-list');
698  $copyrightList = $copyrightListObj->getCopyrights($uploadId,
699  $parent->getItemId(), $uploadTreeTableName, -1, '');
700  if (array_key_exists("warn", $copyrightList)) {
701  unset($copyrightList["warn"]);
702  }
703 
704  $responseList = array();
705  foreach ($copyrightList as $copyFilepath) {
706  $flag=0;
707  foreach ($responseList as $response) {
708  if ($copyFilepath['content'] == $response['copyright']) {
709  $flag=1;
710  break;
711  }
712  }
713  if ($flag==0) {
714  $copyrightContent = array();
715  foreach ($copyrightList as $copy) {
716  if (strcasecmp($copyFilepath['content'], $copy['content']) == 0) {
717  $copyrightContent[] = $copy['filePath'];
718  }
719  }
720  $responseRow = array();
721  $responseRow['copyright'] = $copyFilepath['content'];
722  $responseRow['filePath'] = $copyrightContent;
723  $responseList[] = $responseRow;
724  }
725  }
726  return $responseList;
727  }
728 
737  public function fetchClearingStatus($itemTreeBounds, $clearingDao, $groupId)
738  {
739  $decTypes = new DecisionTypes;
740  if ($itemTreeBounds !== null) {
741  $clearingList = $clearingDao->getFileClearings($itemTreeBounds, $groupId);
742  } else {
743  $clearingList = [];
744  }
745 
746  $clearingArray = [];
747  foreach ($clearingList as $clearingDecision) {
748  $clearingArray[] = $clearingDecision->getType();
749  }
750 
751  if (empty($clearingArray) || $clearingArray[0] === null) {
752  return "NOASSERTION";
753  } else {
754  return $decTypes->getTypeName($clearingArray[0]);
755  }
756  }
757 
768  public function getUploadLicenseList($uploadId, $agents, $printContainers, $boolLicense, $boolCopyright, $page = 0, $limit = 50, $apiVersion=ApiVersion::V1)
769  {
770  global $container;
771  $restHelper = $container->get('helper.restHelper');
772  $uploadDao = $restHelper->getUploadDao();
773  $agentDao = $container->get('dao.agent');
774  $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
775  $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
776  $groupId = $restHelper->getGroupId();
777  $scanProx = new ScanJobProxy($agentDao, $uploadId);
778  $scanProx->createAgentStatus($agents);
779  $agent_ids = $scanProx->getLatestSuccessfulAgentIds();
780  $clearingDao = $container->get("dao.clearing");
781 
785  if ($boolLicense) {
786  $licenseListObj = $restHelper->getPlugin('export-list');
787  $licenseList = $licenseListObj->createListOfLines($uploadTreeTableName,
788  $parent->getItemId(), $agent_ids, -1, true, '', !$printContainers);
789  if (array_key_exists("warn", $licenseList)) {
790  unset($licenseList["warn"]);
791  }
792  }
793 
797  if ($boolCopyright) {
798  $copyrightListObj = $restHelper->getPlugin('export-list');
799  $copyrightList = $copyrightListObj->getCopyrights($uploadId,
800  $parent->getItemId(), $uploadTreeTableName, -1, '');
801  if (array_key_exists("warn", $copyrightList)) {
802  unset($copyrightList["warn"]);
803  }
804  }
805 
806  $responseList = array();
807 
808  if ($boolLicense) {
809  foreach ($licenseList as $license) {
810  $copyrightContent = null;
811  if ($boolCopyright) {
812  $copyrightContent = [];
813  foreach ($copyrightList as $copy) {
814  if (($license['filePath'] == $copy['filePath']) !== false ) {
815  $copyrightContent[] = $copy['content'];
816  }
817  }
818  if (count($copyrightContent)==0) {
819  $copyrightContent = null;
820  }
821  }
822 
823  $findings = new Findings($license['agentFindings'],
824  $license['conclusions'], $copyrightContent);
825  $uploadTreeTableId = $license['uploadtree_pk'];
826  $uploadtree_tablename = $uploadDao->getUploadtreeTableName($uploadId);
827  if ($uploadTreeTableId!==null) {
828  $itemTreeBounds = $uploadDao->getItemTreeBounds($uploadTreeTableId,$uploadtree_tablename);
829  } else {
830  $itemTreeBounds=null;
831  }
832  $clearingDecision = $this->fetchClearingStatus($itemTreeBounds,
833  $clearingDao, $groupId);
834  $responseRow = new FileLicenses($license['filePath'], $findings,
835  $clearingDecision);
836  $responseList[] = $responseRow->getArray($apiVersion);
837  }
838  } elseif (!$boolLicense && $boolCopyright) {
839  foreach ($copyrightList as $copyFilepath) {
840  $copyrightContent = array();
841  foreach ($copyrightList as $copy) {
842  if (($copyFilepath['filePath'] == $copy['filePath']) === true) {
843  $copyrightContent[] = $copy['content'];
844  }
845  }
846  $findings = new Findings();
847  $findings->setCopyright($copyrightContent);
848  $responseRow = new FileLicenses($copyFilepath['filePath'], $findings);
849  $responseList[] = $responseRow->getArray($apiVersion);
850  }
851  }
852  $offset = $page * $limit;
853  $paginatedResponseList = array_slice($responseList, $offset, $limit);
854  $paginatedResponseListSize = sizeof($responseList);
855  return array($paginatedResponseList, $paginatedResponseListSize);
856  }
857 }
Fossology exception.
Definition: Exception.php:15
Handle new file uploads from Slim framework and move to FOSSology.
handleScheduleAnalysis($uploadId, $folderId, $scanOptionsJSON, $newUpload=false, $apiVersion=ApiVersion::V1)
sanitizeUrlData(&$urlData)
Check if the passed URL object is correct or not.
generateUrlUpload($urlData, $folderName, $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
getMainLicenses($dbManager, $uploadId, $groupId)
createFileUpload($uploadedFile, $folderId, $fileDescription, $isPublic, $ignoreScm=0, $applyGlobal=0, $excludefolder=0)
fetchClearingStatus($itemTreeBounds, $clearingDao, $groupId)
generateSrvUpload($srvData, $folderName, $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
sanitizeSrvData(&$srvData)
Check if the passed server upload object is correct or not.
handleUpload($body, $uploadType, $folderId, $fileDescription, $isPublic, $ignoreScm=0, $applyGlobal=0, $excludefolder=0)
createNewUpload($reqBody, $folderId, $fileDescription, $isPublic, $ignoreScm, $uploadType, $applyGlobal=false, $excludefolder=false)
sanitizeVcsData(&$vcsData)
Check if the passed VCS object is correct or not.
generateVcsUpload($vcsData, $folderId, $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
Model to hold analysis settings.
Definition: Analysis.php:21
Model holding information about license findings and conclusions.
Definition: Findings.php:18
Info model to contain general error and return values.
Definition: Info.php:19
Model to hold info required by Reuser agent.
Definition: Reuser.php:18
Model to hold add settings for new scan.
Definition: ScanOptions.php:32
Model class to hold Upload info.
REST api helper classes.