FOSSology  4.5.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 (! $parametersSent) {
153  throw new HttpBadRequestException("No parameters selected for agents!");
154  }
155 
156  $scanOptions = new ScanOptions($analysis, $reuser, $decider, $scancode);
157  return $scanOptions->scheduleAgents($folderId, $uploadId, $newUpload);
158  }
159 
160 
177  public function createNewUpload($reqBody, $folderId, $fileDescription,
178  $isPublic, $ignoreScm, $uploadType,
179  $applyGlobal = false, $excludefolder = false)
180  {
181  $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
182  $uploadedFile = $symReq->files->get($this->uploadFilePage::FILE_INPUT_NAME,
183  null);
184 
185  if ($applyGlobal) {
186  // If global decisions should be ignored
187  $applyGlobal = 1;
188  } else {
189  $applyGlobal = 0;
190  }
191  if ($excludefolder) {
192  // If configured folder should be ignored
193  $excludefolder = 1;
194  } else {
195  $excludefolder = 0;
196  }
197 
198  if (! empty($ignoreScm) && ($ignoreScm == "true")) {
199  // If SCM should be ignored
200  $ignoreScm = 1;
201  } else {
202  $ignoreScm = 0;
203  }
204  if (empty($uploadedFile)) {
205  if (empty($uploadType)) {
206  return array(false, "Missing 'uploadType' header",
207  "Send file with parameter " . $this->uploadFilePage::FILE_INPUT_NAME .
208  " or define 'uploadType' header with appropriate body.",
209  - 1
210  );
211  }
212  return $this->handleUpload($reqBody, $uploadType, $folderId,
213  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
214  } else {
215  return $this->createFileUpload($uploadedFile, $folderId,
216  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
217  }
218  }
219 
232  private function createFileUpload($uploadedFile, $folderId, $fileDescription,
233  $isPublic, $ignoreScm = 0, $applyGlobal = 0, $excludefolder = 0)
234  {
235  $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
236  $symfonySession = $GLOBALS['container']->get('session');
237  $symfonySession->set(
238  $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
239 
240  $symfonyRequest->request->set($this->uploadFilePage::FOLDER_PARAMETER_NAME,
241  $folderId);
242  $symfonyRequest->request->set(
243  $this->uploadFilePage::DESCRIPTION_INPUT_NAME,
244  [$fileDescription]);
245  $symfonyRequest->files->set($this->uploadFilePage::FILE_INPUT_NAME,
246  [$uploadedFile]);
247  $symfonyRequest->setSession($symfonySession);
248  $symfonyRequest->request->set(
249  $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
250  $symfonyRequest->request->set('public', $isPublic);
251  $symfonyRequest->request->set('globalDecisions', $applyGlobal);
252  $symfonyRequest->request->set('scm', $ignoreScm);
253  $symfonyRequest->request->set('excludefolder', $excludefolder);
254 
255  return $this->uploadFilePage->handleRequest($symfonyRequest);
256  }
257 
271  private function handleUpload($body, $uploadType, $folderId, $fileDescription,
272  $isPublic, $ignoreScm = 0, $applyGlobal = 0, $excludefolder = 0)
273  {
274  $sanity = false;
275  switch ($uploadType) {
276  case "vcs":
277  $sanity = $this->sanitizeVcsData($body);
278  break;
279  case "url":
280  $sanity = $this->sanitizeUrlData($body);
281  break;
282  case "server":
283  $sanity = $this->sanitizeSrvData($body);
284  break;
285  default:
286  $message = "Invalid 'uploadType'";
287  $statusDescription = "uploadType should be any of (" .
288  implode(",", self::VALID_UPLOAD_TYPES) . ")";
289  $code = 400;
290  $sanity = array(false, $message, $statusDescription, $code);
291  }
292  if ($sanity !== true) {
293  return $sanity;
294  }
295  $uploadResponse = false;
296  switch ($uploadType) {
297  case "vcs":
298  $uploadResponse = $this->generateVcsUpload($body, $folderId,
299  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
300  break;
301  case "url":
302  $uploadResponse = $this->generateUrlUpload($body, $folderId,
303  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
304  break;
305  case "server":
306  $uploadResponse = $this->generateSrvUpload($body, $folderId,
307  $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
308  break;
309  }
310  return $uploadResponse;
311  }
312 
323  private function sanitizeVcsData(&$vcsData)
324  {
325  $message = "";
326  $statusDescription = "";
327  $code = 0;
328 
329  if (! array_key_exists("vcsType", $vcsData) ||
330  ! in_array($vcsData["vcsType"], self::VALID_VCS_TYPES)) {
331  $message = "Missing vcsType";
332  $statusDescription = "vcsType should be any of (" .
333  implode(", ", self::VALID_VCS_TYPES) . ")";
334  $code = 400;
335  }
336  $vcsType = "";
337  if ($vcsData["vcsType"] == "git") {
338  $vcsType = "Git";
339  } else {
340  $vcsType = "SVN";
341  }
342 
343  if (! array_key_exists("vcsUrl", $vcsData)) {
344  $message = "Missing vcsUrl";
345  $statusDescription = "vcsUrl should be passed.";
346  $code = 400;
347  }
348 
349  if (! array_key_exists("vcsName", $vcsData)) {
350  $vcsData["vcsName"] = "";
351  }
352  if (! array_key_exists("vcsUsername", $vcsData)) {
353  $vcsData["vcsUsername"] = "";
354  }
355  if (! array_key_exists("vcsPassword", $vcsData)) {
356  $vcsData["vcsPassword"] = "";
357  }
358  if (! array_key_exists("vcsBranch", $vcsData)) {
359  $vcsData["vcsBranch"] = "";
360  }
361  $vcsData["vcsType"] = $vcsType;
362  if ($code !== 0) {
363  return array(false, $message, $statusDescription, $code);
364  } else {
365  return true;
366  }
367  }
368 
378  private function sanitizeUrlData(&$urlData)
379  {
380  $message = "";
381  $statusDescription = "";
382  $code = 0;
383 
384  if (! array_key_exists("url", $urlData)) {
385  $message = "Missing url";
386  $statusDescription = "Missing upload url from request";
387  $code = 400;
388  }
389 
390  if (! array_key_exists("name", $urlData)) {
391  $urlData["name"] = "";
392  }
393  if (! array_key_exists("accept", $urlData)) {
394  $urlData["accept"] = "";
395  }
396  if (! array_key_exists("reject", $urlData)) {
397  $urlData["reject"] = "";
398  }
399  if (! array_key_exists("maxRecursionDepth", $urlData)) {
400  $urlData["maxRecursionDepth"] = "";
401  }
402  if ($code !== 0) {
403  return array(false, $message, $statusDescription, $code);
404  } else {
405  return true;
406  }
407  }
408 
418  private function sanitizeSrvData(&$srvData)
419  {
420  $message = "";
421  $statusDescription = "";
422  $code = 0;
423 
424  if (! array_key_exists("path", $srvData)) {
425  $message = "Missing path";
426  $statusDescription = "Missing upload path from request";
427  $code = 400;
428  }
429 
430  if (! array_key_exists("name", $srvData)) {
431  $srvData["name"] = "";
432  }
433  if ($code !== 0) {
434  return array(false, $message, $statusDescription, $code);
435  } else {
436  return true;
437  }
438  }
439 
451  private function generateVcsUpload($vcsData, $folderId, $fileDescription,
452  $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
453  {
454  $vcsType = $vcsData["vcsType"];
455  $vcsUrl = $vcsData["vcsUrl"];
456  $vcsName = $vcsData["vcsName"];
457  $vcsUsername = $vcsData["vcsUsername"];
458  $vcsPasswd = $vcsData["vcsPassword"];
459  $vcsBranch = $vcsData["vcsBranch"];
460 
461  $symfonySession = $GLOBALS['container']->get('session');
462  $symfonySession->set($this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
463  "restUpload");
464 
465  $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
466  $symfonyRequest->setSession($symfonySession);
467 
468  $symfonyRequest->request->set($this->uploadVcsPage::FOLDER_PARAMETER_NAME,
469  $folderId);
470  $symfonyRequest->request->set($this->uploadVcsPage::DESCRIPTION_INPUT_NAME,
471  $fileDescription);
472  $symfonyRequest->request->set($this->uploadVcsPage::GETURL_PARAM, $vcsUrl);
473  $symfonyRequest->request->set(
474  $this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
475  $symfonyRequest->request->set('public', $isPublic);
476  $symfonyRequest->request->set('name', $vcsName);
477  $symfonyRequest->request->set('vcstype', $vcsType);
478  $symfonyRequest->request->set('username', $vcsUsername);
479  $symfonyRequest->request->set('passwd', $vcsPasswd);
480  $symfonyRequest->request->set('branch', $vcsBranch);
481  $symfonyRequest->request->set('globalDecisions', $applyGlobal);
482  $symfonyRequest->request->set('scm', $ignoreScm);
483  $symfonyRequest->request->set('excludefolder', $excludefolder);
484 
485  return $this->uploadVcsPage->handleRequest($symfonyRequest);
486  }
487 
499  private function generateUrlUpload($urlData, $folderName, $fileDescription,
500  $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
501  {
502  $url = $urlData["url"];
503  $name = $urlData["name"];
504  $accept = $urlData["accept"];
505  $reject = $urlData["reject"];
506  $maxRecursionDepth = $urlData["maxRecursionDepth"];
507 
508  $symfonySession = $GLOBALS['container']->get('session');
509  $symfonySession->set($this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
510  "restUpload");
511 
512  $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
513  $symfonyRequest->setSession($symfonySession);
514 
515  $symfonyRequest->request->set($this->uploadUrlPage::FOLDER_PARAMETER_NAME,
516  $folderName);
517  $symfonyRequest->request->set($this->uploadUrlPage::DESCRIPTION_INPUT_NAME,
518  $fileDescription);
519  $symfonyRequest->request->set(
520  $this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
521  $symfonyRequest->request->set('public', $isPublic);
522  $symfonyRequest->request->set($this->uploadUrlPage::NAME_PARAM, $name);
523  $symfonyRequest->request->set($this->uploadUrlPage::ACCEPT_PARAM, $accept);
524  $symfonyRequest->request->set($this->uploadUrlPage::REJECT_PARAM, $reject);
525  $symfonyRequest->request->set($this->uploadUrlPage::GETURL_PARAM, $url);
526  $symfonyRequest->request->set($this->uploadUrlPage::LEVEL_PARAM,
527  $maxRecursionDepth);
528  $symfonyRequest->request->set('globalDecisions', $applyGlobal);
529  $symfonyRequest->request->set('scm', $ignoreScm);
530  $symfonyRequest->request->set('excludefolder', $excludefolder);
531 
532  return $this->uploadUrlPage->handleRequest($symfonyRequest);
533  }
534 
546  private function generateSrvUpload($srvData, $folderName, $fileDescription,
547  $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
548  {
549  $path = $srvData["path"];
550  $name = $srvData["name"];
551 
552  $symfonySession = $GLOBALS['container']->get('session');
553  $symfonySession->set($this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
554  "restUpload");
555 
556  $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
557  $symfonyRequest->setSession($symfonySession);
558 
559  $symfonyRequest->request->set($this->uploadSrvPage::FOLDER_PARAMETER_NAME,
560  $folderName);
561  $symfonyRequest->request->set($this->uploadSrvPage::DESCRIPTION_INPUT_NAME,
562  $fileDescription);
563  $symfonyRequest->request->set(
564  $this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME, "restUpload");
565  $symfonyRequest->request->set('public', $isPublic);
566  $symfonyRequest->request->set($this->uploadSrvPage::SOURCE_FILES_FIELD,
567  $path);
568  $symfonyRequest->request->set($this->uploadSrvPage::NAME_PARAM, $name);
569  $symfonyRequest->request->set('globalDecisions', $applyGlobal);
570  $symfonyRequest->request->set('scm', $ignoreScm);
571  $symfonyRequest->request->set('excludefolder', $excludefolder);
572 
573  return $this->uploadSrvPage->handleRequest($symfonyRequest);
574  }
575 
582  public function generateUploadSummary($uploadId, $groupId)
583  {
584  global $container;
585  $restHelper = $container->get('helper.restHelper');
586  $uploadDao = $restHelper->getUploadDao();
587  $dbManager = $restHelper->getDbHelper()->getDbManager();
588  $copyrightDao = $container->get('dao.copyright');
589  $agentDao = $container->get('dao.agent');
590 
591  $agentName = "copyright";
592  $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
593 
594  $noLicenseUploadTreeView = new UploadTreeProxy($uploadId,
595  array(UploadTreeProxy::OPT_SKIP_THESE => "noLicense",
596  UploadTreeProxy::OPT_GROUP_ID => $groupId),
597  $uploadTreeTableName,
598  'no_license_uploadtree' . $uploadId);
599  $clearingCount = $noLicenseUploadTreeView->count();
600 
601  $nonClearedUploadTreeView = new UploadTreeProxy($uploadId,
602  array(UploadTreeProxy::OPT_SKIP_THESE => "alreadyCleared",
603  UploadTreeProxy::OPT_GROUP_ID => $groupId),
604  $uploadTreeTableName,
605  'already_cleared_uploadtree' . $uploadId);
606  $filesToBeCleared = $nonClearedUploadTreeView->count();
607 
608  $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
609  $uploadTreeTableName);
610  $scanProx = new ScanJobProxy($agentDao, $uploadId);
611  $scanProx->createAgentStatus([$agentName]);
612  $agents = $scanProx->getLatestSuccessfulAgentIds();
613  $copyrightCount = 0;
614  if (array_key_exists($agentName, $agents) && ! empty($agents[$agentName])) {
615  $copyrightCount = count(
616  $copyrightDao->getAllEntriesReport($agentName, $uploadId,
617  $uploadTreeTableName, null, false, null, "C.agent_fk = " .
618  $agents[$agentName], $groupId));
619  }
620 
621  $mainLicenses = $this->getMainLicenses($dbManager, $uploadId, $groupId);
622 
624  $uiLicense = $restHelper->getPlugin("license");
625  $hist = $uiLicense->getUploadHist($itemTreeBounds);
626  if (!is_array($hist) || !array_key_exists('uniqueLicenseCount', $hist)) {
627  $hist = [];
628  $hist['uniqueLicenseCount'] = 0;
629  $hist['scannerLicenseCount'] = 0;
630  $hist['editedUniqueLicenseCount'] = 0;
631  $hist['editedLicenseCount'] = 0;
632  }
633 
634  $summary = new UploadSummary();
635  $summary->setUploadId($uploadId);
636  $summary->setUploadName($uploadDao->getUpload($uploadId)->getFilename());
637  $summary->setAssignee($uploadDao->getAssignee($uploadId, $groupId));
638  if ($mainLicenses !== null) {
639  $summary->setMainLicense(implode(",", $mainLicenses));
640  }
641  $summary->setUniqueLicenses($hist['uniqueLicenseCount']);
642  $summary->setTotalLicenses($hist['scannerLicenseCount']);
643  $summary->setUniqueConcludedLicenses($hist['editedUniqueLicenseCount']);
644  $summary->setTotalConcludedLicenses($hist['editedLicenseCount']);
645  $summary->setFilesToBeCleared($filesToBeCleared);
646  $summary->setFilesCleared($clearingCount);
647  $summary->setClearingStatus($uploadDao->getStatus($uploadId, $groupId));
648  $summary->setCopyrightCount($copyrightCount);
649  return $summary;
650  }
651 
659  private function getMainLicenses($dbManager, $uploadId, $groupId)
660  {
661  $sql = "SELECT rf_shortname FROM license_ref lf JOIN upload_clearing_license ucl"
662  . " ON lf.rf_pk=ucl.rf_fk WHERE upload_fk=$1 AND ucl.group_fk=$2";
663  $stmt = __METHOD__.'.collectMainLicenses';
664  $rows = $dbManager->getRows($sql, array($uploadId, $groupId), $stmt);
665  if (empty($rows)) {
666  return null;
667  }
668  $mainLicenses = [];
669  foreach ($rows as $row) {
670  $mainLicenses[] = $row['rf_shortname'];
671  }
672  return $mainLicenses;
673  }
674 
681  public function getUploadCopyrightList($uploadId)
682  {
683  global $container;
684  $restHelper = $container->get('helper.restHelper');
685  $uploadDao = $restHelper->getUploadDao();
686 
687  $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
688  $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
689 
693  $copyrightListObj = $restHelper->getPlugin('export-list');
694  $copyrightList = $copyrightListObj->getCopyrights($uploadId,
695  $parent->getItemId(), $uploadTreeTableName, -1, '');
696  if (array_key_exists("warn", $copyrightList)) {
697  unset($copyrightList["warn"]);
698  }
699 
700  $responseList = array();
701  foreach ($copyrightList as $copyFilepath) {
702  $flag=0;
703  foreach ($responseList as $response) {
704  if ($copyFilepath['content'] == $response['copyright']) {
705  $flag=1;
706  break;
707  }
708  }
709  if ($flag==0) {
710  $copyrightContent = array();
711  foreach ($copyrightList as $copy) {
712  if (strcasecmp($copyFilepath['content'], $copy['content']) == 0) {
713  $copyrightContent[] = $copy['filePath'];
714  }
715  }
716  $responseRow = array();
717  $responseRow['copyright'] = $copyFilepath['content'];
718  $responseRow['filePath'] = $copyrightContent;
719  $responseList[] = $responseRow;
720  }
721  }
722  return $responseList;
723  }
724 
733  public function fetchClearingStatus($itemTreeBounds, $clearingDao, $groupId)
734  {
735  $decTypes = new DecisionTypes;
736  if ($itemTreeBounds !== null) {
737  $clearingList = $clearingDao->getFileClearings($itemTreeBounds, $groupId);
738  } else {
739  $clearingList = [];
740  }
741 
742  $clearingArray = [];
743  foreach ($clearingList as $clearingDecision) {
744  $clearingArray[] = $clearingDecision->getType();
745  }
746 
747  if (empty($clearingArray) || $clearingArray[0] === null) {
748  return "NOASSERTION";
749  } else {
750  return $decTypes->getTypeName($clearingArray[0]);
751  }
752  }
753 
764  public function getUploadLicenseList($uploadId, $agents, $printContainers, $boolLicense, $boolCopyright, $page = 0, $limit = 50, $apiVersion=ApiVersion::V1)
765  {
766  global $container;
767  $restHelper = $container->get('helper.restHelper');
768  $uploadDao = $restHelper->getUploadDao();
769  $agentDao = $container->get('dao.agent');
770  $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
771  $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
772  $groupId = $restHelper->getGroupId();
773  $scanProx = new ScanJobProxy($agentDao, $uploadId);
774  $scanProx->createAgentStatus($agents);
775  $agent_ids = $scanProx->getLatestSuccessfulAgentIds();
776  $clearingDao = $container->get("dao.clearing");
777 
781  if ($boolLicense) {
782  $licenseListObj = $restHelper->getPlugin('export-list');
783  $licenseList = $licenseListObj->createListOfLines($uploadTreeTableName,
784  $parent->getItemId(), $agent_ids, -1, true, '', !$printContainers);
785  if (array_key_exists("warn", $licenseList)) {
786  unset($licenseList["warn"]);
787  }
788  }
789 
793  if ($boolCopyright) {
794  $copyrightListObj = $restHelper->getPlugin('export-list');
795  $copyrightList = $copyrightListObj->getCopyrights($uploadId,
796  $parent->getItemId(), $uploadTreeTableName, -1, '');
797  if (array_key_exists("warn", $copyrightList)) {
798  unset($copyrightList["warn"]);
799  }
800  }
801 
802  $responseList = array();
803 
804  if ($boolLicense) {
805  foreach ($licenseList as $license) {
806  $copyrightContent = null;
807  if ($boolCopyright) {
808  $copyrightContent = [];
809  foreach ($copyrightList as $copy) {
810  if (($license['filePath'] == $copy['filePath']) !== false ) {
811  $copyrightContent[] = $copy['content'];
812  }
813  }
814  if (count($copyrightContent)==0) {
815  $copyrightContent = null;
816  }
817  }
818 
819  $findings = new Findings($license['agentFindings'],
820  $license['conclusions'], $copyrightContent);
821  $uploadTreeTableId = $license['uploadtree_pk'];
822  $uploadtree_tablename = $uploadDao->getUploadtreeTableName($uploadId);
823  if ($uploadTreeTableId!==null) {
824  $itemTreeBounds = $uploadDao->getItemTreeBounds($uploadTreeTableId,$uploadtree_tablename);
825  } else {
826  $itemTreeBounds=null;
827  }
828  $clearingDecision = $this->fetchClearingStatus($itemTreeBounds,
829  $clearingDao, $groupId);
830  $responseRow = new FileLicenses($license['filePath'], $findings,
831  $clearingDecision);
832  $responseList[] = $responseRow->getArray($apiVersion);
833  }
834  } elseif (!$boolLicense && $boolCopyright) {
835  foreach ($copyrightList as $copyFilepath) {
836  $copyrightContent = array();
837  foreach ($copyrightList as $copy) {
838  if (($copyFilepath['filePath'] == $copy['filePath']) === true) {
839  $copyrightContent[] = $copy['content'];
840  }
841  }
842  $findings = new Findings();
843  $findings->setCopyright($copyrightContent);
844  $responseRow = new FileLicenses($copyFilepath['filePath'], $findings);
845  $responseList[] = $responseRow->getArray($apiVersion);
846  }
847  }
848  $offset = $page * $limit;
849  $paginatedResponseList = array_slice($responseList, $offset, $limit);
850  $paginatedResponseListSize = sizeof($responseList);
851  return array($paginatedResponseList, $paginatedResponseListSize);
852  }
853 }
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.