40 use Symfony\Component\HttpFoundation\File\UploadedFile;
115 $newUpload =
false, $apiVersion = ApiVersion::V1)
118 $restHelper = $container->get(
'helper.restHelper');
120 $parametersSent =
false;
123 if (array_key_exists(
"analysis", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"analysis"])) {
124 $analysis->setUsingArray($scanOptionsJSON[
"analysis"], $apiVersion);
125 $parametersSent =
true;
129 $decider->setDeciderAgentPlugin($restHelper->getPlugin(
'agent_decider'));
130 if (array_key_exists(
"decider", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"decider"])) {
131 $decider->setUsingArray($scanOptionsJSON[
"decider"], $apiVersion);
132 $parametersSent =
true;
136 if (array_key_exists(
"scancode", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"scancode"])) {
137 $scancode->setUsingArray($scanOptionsJSON[
"scancode"]);
138 $parametersSent =
true;
141 $reuser =
new Reuser(0,
'groupName',
false,
false);
143 if (array_key_exists(
"reuse", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"reuse"])) {
144 $reuser->setUsingArray($scanOptionsJSON[
"reuse"], $apiVersion);
145 $parametersSent =
true;
147 }
catch (\UnexpectedValueException $e) {
151 if (! $parametersSent) {
155 $scanOptions =
new ScanOptions($analysis, $reuser, $decider, $scancode);
156 return $scanOptions->scheduleAgents($folderId, $uploadId, $newUpload);
176 $isPublic, $ignoreScm, $uploadType,
177 $applyGlobal =
false)
179 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
180 $uploadedFile = $symReq->files->get($this->uploadFilePage::FILE_INPUT_NAME,
190 if (! empty($ignoreScm) && ($ignoreScm ==
"true")) {
196 if (empty($uploadedFile)) {
197 if (empty($uploadType)) {
198 return array(
false,
"Missing 'uploadType' header",
199 "Send file with parameter " . $this->uploadFilePage::FILE_INPUT_NAME .
200 " or define 'uploadType' header with appropriate body.",
204 return $this->
handleUpload($reqBody, $uploadType, $folderId,
205 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
208 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
224 $isPublic, $ignoreScm = 0, $applyGlobal = 0)
226 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
227 $symfonySession = $GLOBALS[
'container']->get(
'session');
228 $symfonySession->set(
229 $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
231 $symfonyRequest->request->set($this->uploadFilePage::FOLDER_PARAMETER_NAME,
233 $symfonyRequest->request->set(
234 $this->uploadFilePage::DESCRIPTION_INPUT_NAME,
236 $symfonyRequest->files->set($this->uploadFilePage::FILE_INPUT_NAME,
238 $symfonyRequest->setSession($symfonySession);
239 $symfonyRequest->request->set(
240 $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
241 $symfonyRequest->request->set(
'public', $isPublic);
242 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
243 $symfonyRequest->request->set(
'scm', $ignoreScm);
245 return $this->uploadFilePage->handleRequest($symfonyRequest);
260 private function handleUpload($body, $uploadType, $folderId, $fileDescription,
261 $isPublic, $ignoreScm = 0, $applyGlobal = 0)
264 switch ($uploadType) {
275 $message =
"Invalid 'uploadType'";
276 $statusDescription =
"uploadType should be any of (" .
277 implode(
",", self::VALID_UPLOAD_TYPES) .
")";
279 $sanity = array(
false, $message, $statusDescription, $code);
281 if ($sanity !==
true) {
284 $uploadResponse =
false;
285 switch ($uploadType) {
288 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
292 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
296 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
299 return $uploadResponse;
315 $statusDescription =
"";
318 if (! array_key_exists(
"vcsType", $vcsData) ||
319 ! in_array($vcsData[
"vcsType"], self::VALID_VCS_TYPES)) {
320 $message =
"Missing vcsType";
321 $statusDescription =
"vcsType should be any of (" .
322 implode(
", ", self::VALID_VCS_TYPES) .
")";
326 if ($vcsData[
"vcsType"] ==
"git") {
332 if (! array_key_exists(
"vcsUrl", $vcsData)) {
333 $message =
"Missing vcsUrl";
334 $statusDescription =
"vcsUrl should be passed.";
338 if (! array_key_exists(
"vcsName", $vcsData)) {
339 $vcsData[
"vcsName"] =
"";
341 if (! array_key_exists(
"vcsUsername", $vcsData)) {
342 $vcsData[
"vcsUsername"] =
"";
344 if (! array_key_exists(
"vcsPassword", $vcsData)) {
345 $vcsData[
"vcsPassword"] =
"";
347 if (! array_key_exists(
"vcsBranch", $vcsData)) {
348 $vcsData[
"vcsBranch"] =
"";
350 $vcsData[
"vcsType"] = $vcsType;
352 return array(
false, $message, $statusDescription, $code);
370 $statusDescription =
"";
373 if (! array_key_exists(
"url", $urlData)) {
374 $message =
"Missing url";
375 $statusDescription =
"Missing upload url from request";
379 if (! array_key_exists(
"name", $urlData)) {
380 $urlData[
"name"] =
"";
382 if (! array_key_exists(
"accept", $urlData)) {
383 $urlData[
"accept"] =
"";
385 if (! array_key_exists(
"reject", $urlData)) {
386 $urlData[
"reject"] =
"";
388 if (! array_key_exists(
"maxRecursionDepth", $urlData)) {
389 $urlData[
"maxRecursionDepth"] =
"";
392 return array(
false, $message, $statusDescription, $code);
410 $statusDescription =
"";
413 if (! array_key_exists(
"path", $srvData)) {
414 $message =
"Missing path";
415 $statusDescription =
"Missing upload path from request";
419 if (! array_key_exists(
"name", $srvData)) {
420 $srvData[
"name"] =
"";
423 return array(
false, $message, $statusDescription, $code);
440 $isPublic, $ignoreScm, $applyGlobal)
442 $vcsType = $vcsData[
"vcsType"];
443 $vcsUrl = $vcsData[
"vcsUrl"];
444 $vcsName = $vcsData[
"vcsName"];
445 $vcsUsername = $vcsData[
"vcsUsername"];
446 $vcsPasswd = $vcsData[
"vcsPassword"];
447 $vcsBranch = $vcsData[
"vcsBranch"];
449 $symfonySession = $GLOBALS[
'container']->get(
'session');
450 $symfonySession->set($this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
453 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
454 $symfonyRequest->setSession($symfonySession);
456 $symfonyRequest->request->set($this->uploadVcsPage::FOLDER_PARAMETER_NAME,
458 $symfonyRequest->request->set($this->uploadVcsPage::DESCRIPTION_INPUT_NAME,
460 $symfonyRequest->request->set($this->uploadVcsPage::GETURL_PARAM, $vcsUrl);
461 $symfonyRequest->request->set(
462 $this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
463 $symfonyRequest->request->set(
'public', $isPublic);
464 $symfonyRequest->request->set(
'name', $vcsName);
465 $symfonyRequest->request->set(
'vcstype', $vcsType);
466 $symfonyRequest->request->set(
'username', $vcsUsername);
467 $symfonyRequest->request->set(
'passwd', $vcsPasswd);
468 $symfonyRequest->request->set(
'branch', $vcsBranch);
469 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
470 $symfonyRequest->request->set(
'scm', $ignoreScm);
472 return $this->uploadVcsPage->handleRequest($symfonyRequest);
486 $isPublic, $ignoreScm, $applyGlobal)
488 $url = $urlData[
"url"];
489 $name = $urlData[
"name"];
490 $accept = $urlData[
"accept"];
491 $reject = $urlData[
"reject"];
492 $maxRecursionDepth = $urlData[
"maxRecursionDepth"];
494 $symfonySession = $GLOBALS[
'container']->get(
'session');
495 $symfonySession->set($this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
498 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
499 $symfonyRequest->setSession($symfonySession);
501 $symfonyRequest->request->set($this->uploadUrlPage::FOLDER_PARAMETER_NAME,
503 $symfonyRequest->request->set($this->uploadUrlPage::DESCRIPTION_INPUT_NAME,
505 $symfonyRequest->request->set(
506 $this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
507 $symfonyRequest->request->set(
'public', $isPublic);
508 $symfonyRequest->request->set($this->uploadUrlPage::NAME_PARAM, $name);
509 $symfonyRequest->request->set($this->uploadUrlPage::ACCEPT_PARAM, $accept);
510 $symfonyRequest->request->set($this->uploadUrlPage::REJECT_PARAM, $reject);
511 $symfonyRequest->request->set($this->uploadUrlPage::GETURL_PARAM, $url);
512 $symfonyRequest->request->set($this->uploadUrlPage::LEVEL_PARAM,
514 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
515 $symfonyRequest->request->set(
'scm', $ignoreScm);
517 return $this->uploadUrlPage->handleRequest($symfonyRequest);
531 $isPublic, $ignoreScm, $applyGlobal)
533 $path = $srvData[
"path"];
534 $name = $srvData[
"name"];
536 $symfonySession = $GLOBALS[
'container']->get(
'session');
537 $symfonySession->set($this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
540 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
541 $symfonyRequest->setSession($symfonySession);
543 $symfonyRequest->request->set($this->uploadSrvPage::FOLDER_PARAMETER_NAME,
545 $symfonyRequest->request->set($this->uploadSrvPage::DESCRIPTION_INPUT_NAME,
547 $symfonyRequest->request->set(
548 $this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
549 $symfonyRequest->request->set(
'public', $isPublic);
550 $symfonyRequest->request->set($this->uploadSrvPage::SOURCE_FILES_FIELD,
552 $symfonyRequest->request->set($this->uploadSrvPage::NAME_PARAM, $name);
553 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
554 $symfonyRequest->request->set(
'scm', $ignoreScm);
556 return $this->uploadSrvPage->handleRequest($symfonyRequest);
565 public function generateUploadSummary($uploadId, $groupId)
568 $restHelper = $container->get(
'helper.restHelper');
569 $uploadDao = $restHelper->getUploadDao();
570 $dbManager = $restHelper->getDbHelper()->getDbManager();
571 $copyrightDao = $container->get(
'dao.copyright');
572 $agentDao = $container->get(
'dao.agent');
574 $agentName =
"copyright";
575 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
578 array(UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
579 UploadTreeProxy::OPT_GROUP_ID => $groupId),
580 $uploadTreeTableName,
581 'no_license_uploadtree' . $uploadId);
582 $clearingCount = $noLicenseUploadTreeView->count();
585 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
586 UploadTreeProxy::OPT_GROUP_ID => $groupId),
587 $uploadTreeTableName,
588 'already_cleared_uploadtree' . $uploadId);
589 $filesToBeCleared = $nonClearedUploadTreeView->count();
591 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
592 $uploadTreeTableName);
594 $scanProx->createAgentStatus([$agentName]);
595 $agents = $scanProx->getLatestSuccessfulAgentIds();
597 if (array_key_exists($agentName, $agents) && ! empty($agents[$agentName])) {
598 $copyrightCount = count(
599 $copyrightDao->getAllEntriesReport($agentName, $uploadId,
600 $uploadTreeTableName,
null,
false,
null,
"C.agent_fk = " .
601 $agents[$agentName], $groupId));
604 $mainLicenses = $this->
getMainLicenses($dbManager, $uploadId, $groupId);
607 $uiLicense = $restHelper->getPlugin(
"license");
608 $hist = $uiLicense->getUploadHist($itemTreeBounds);
609 if (!is_array($hist) || !array_key_exists(
'uniqueLicenseCount', $hist)) {
611 $hist[
'uniqueLicenseCount'] = 0;
612 $hist[
'scannerLicenseCount'] = 0;
613 $hist[
'editedUniqueLicenseCount'] = 0;
614 $hist[
'editedLicenseCount'] = 0;
617 $summary =
new UploadSummary();
618 $summary->setUploadId($uploadId);
619 $summary->setUploadName($uploadDao->getUpload($uploadId)->getFilename());
620 $summary->setAssignee($uploadDao->getAssignee($uploadId, $groupId));
621 if ($mainLicenses !==
null) {
622 $summary->setMainLicense(implode(
",", $mainLicenses));
624 $summary->setUniqueLicenses($hist[
'uniqueLicenseCount']);
625 $summary->setTotalLicenses($hist[
'scannerLicenseCount']);
626 $summary->setUniqueConcludedLicenses($hist[
'editedUniqueLicenseCount']);
627 $summary->setTotalConcludedLicenses($hist[
'editedLicenseCount']);
628 $summary->setFilesToBeCleared($filesToBeCleared);
629 $summary->setFilesCleared($clearingCount);
630 $summary->setClearingStatus($uploadDao->getStatus($uploadId, $groupId));
631 $summary->setCopyrightCount($copyrightCount);
644 $sql =
"SELECT rf_shortname FROM license_ref lf JOIN upload_clearing_license ucl"
645 .
" ON lf.rf_pk=ucl.rf_fk WHERE upload_fk=$1 AND ucl.group_fk=$2";
646 $stmt = __METHOD__.
'.collectMainLicenses';
647 $rows = $dbManager->getRows($sql, array($uploadId, $groupId), $stmt);
652 foreach ($rows as $row) {
653 $mainLicenses[] = $row[
'rf_shortname'];
655 return $mainLicenses;
664 public function getUploadCopyrightList($uploadId)
667 $restHelper = $container->get(
'helper.restHelper');
668 $uploadDao = $restHelper->getUploadDao();
670 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
671 $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
676 $copyrightListObj = $restHelper->getPlugin(
'export-list');
677 $copyrightList = $copyrightListObj->getCopyrights($uploadId,
678 $parent->getItemId(), $uploadTreeTableName, -1,
'');
679 if (array_key_exists(
"warn", $copyrightList)) {
680 unset($copyrightList[
"warn"]);
683 $responseList = array();
684 foreach ($copyrightList as $copyFilepath) {
686 foreach ($responseList as $response) {
687 if ($copyFilepath[
'content'] == $response[
'copyright']) {
693 $copyrightContent = array();
694 foreach ($copyrightList as $copy) {
695 if (strcasecmp($copyFilepath[
'content'], $copy[
'content']) == 0) {
696 $copyrightContent[] = $copy[
'filePath'];
699 $responseRow = array();
700 $responseRow[
'copyright'] = $copyFilepath[
'content'];
701 $responseRow[
'filePath'] = $copyrightContent;
702 $responseList[] = $responseRow;
705 return $responseList;
719 if ($itemTreeBounds !==
null) {
720 $clearingList = $clearingDao->getFileClearings($itemTreeBounds, $groupId);
726 foreach ($clearingList as $clearingDecision) {
727 $clearingArray[] = $clearingDecision->getType();
730 if (empty($clearingArray) || $clearingArray[0] ===
null) {
731 return "NOASSERTION";
747 public function getUploadLicenseList($uploadId, $agents, $printContainers, $boolLicense, $boolCopyright, $page = 0, $limit = 50, $apiVersion=ApiVersion::V1)
750 $restHelper = $container->get(
'helper.restHelper');
751 $uploadDao = $restHelper->getUploadDao();
752 $agentDao = $container->get(
'dao.agent');
753 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
754 $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
755 $groupId = $restHelper->getGroupId();
757 $scanProx->createAgentStatus($agents);
758 $agent_ids = $scanProx->getLatestSuccessfulAgentIds();
759 $clearingDao = $container->get(
"dao.clearing");
765 $licenseListObj = $restHelper->getPlugin(
'export-list');
766 $licenseList = $licenseListObj->createListOfLines($uploadTreeTableName,
767 $parent->getItemId(), $agent_ids, -1,
true,
'', !$printContainers);
768 if (array_key_exists(
"warn", $licenseList)) {
769 unset($licenseList[
"warn"]);
776 if ($boolCopyright) {
777 $copyrightListObj = $restHelper->getPlugin(
'export-list');
778 $copyrightList = $copyrightListObj->getCopyrights($uploadId,
779 $parent->getItemId(), $uploadTreeTableName, -1,
'');
780 if (array_key_exists(
"warn", $copyrightList)) {
781 unset($copyrightList[
"warn"]);
785 $responseList = array();
788 foreach ($licenseList as $license) {
789 $copyrightContent =
null;
790 if ($boolCopyright) {
791 $copyrightContent = [];
792 foreach ($copyrightList as $copy) {
793 if (($license[
'filePath'] == $copy[
'filePath']) !==
false ) {
794 $copyrightContent[] = $copy[
'content'];
797 if (count($copyrightContent)==0) {
798 $copyrightContent =
null;
802 $findings =
new Findings($license[
'agentFindings'],
803 $license[
'conclusions'], $copyrightContent);
804 $uploadTreeTableId = $license[
'uploadtree_pk'];
805 $uploadtree_tablename = $uploadDao->getUploadtreeTableName($uploadId);
806 if ($uploadTreeTableId!==
null) {
807 $itemTreeBounds = $uploadDao->getItemTreeBounds($uploadTreeTableId,$uploadtree_tablename);
809 $itemTreeBounds=
null;
812 $clearingDao, $groupId);
813 $responseRow =
new FileLicenses($license[
'filePath'], $findings,
815 $responseList[] = $responseRow->getArray($apiVersion);
817 } elseif (!$boolLicense && $boolCopyright) {
818 foreach ($copyrightList as $copyFilepath) {
819 $copyrightContent = array();
820 foreach ($copyrightList as $copy) {
821 if (($copyFilepath[
'filePath'] == $copy[
'filePath']) ===
true) {
822 $copyrightContent[] = $copy[
'content'];
825 $findings =
new Findings();
826 $findings->setCopyright($copyrightContent);
827 $responseRow =
new FileLicenses($copyFilepath[
'filePath'], $findings);
828 $responseList[] = $responseRow->getArray($apiVersion);
831 $offset = $page * $limit;
832 $paginatedResponseList = array_slice($responseList, $offset, $limit);
833 $paginatedResponseListSize =
sizeof($responseList);
834 return array($paginatedResponseList, $paginatedResponseListSize);
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)
getMainLicenses($dbManager, $uploadId, $groupId)
createNewUpload($reqBody, $folderId, $fileDescription, $isPublic, $ignoreScm, $uploadType, $applyGlobal=false)
generateVcsUpload($vcsData, $folderId, $fileDescription, $isPublic, $ignoreScm, $applyGlobal)
fetchClearingStatus($itemTreeBounds, $clearingDao, $groupId)
sanitizeSrvData(&$srvData)
Check if the passed server upload object is correct or not.
generateSrvUpload($srvData, $folderName, $fileDescription, $isPublic, $ignoreScm, $applyGlobal)
createFileUpload($uploadedFile, $folderId, $fileDescription, $isPublic, $ignoreScm=0, $applyGlobal=0)
handleUpload($body, $uploadType, $folderId, $fileDescription, $isPublic, $ignoreScm=0, $applyGlobal=0)
sanitizeVcsData(&$vcsData)
Check if the passed VCS object is correct or not.
Model to hold analysis settings.
Model holding information about license findings and conclusions.
Info model to contain general error and return values.
Model to hold info required by Reuser agent.
Model to hold add settings for new scan.
Model class to hold Upload info.