41 use Symfony\Component\HttpFoundation\File\UploadedFile;
116 $newUpload =
false, $apiVersion = ApiVersion::V1)
119 $restHelper = $container->get(
'helper.restHelper');
121 $parametersSent =
false;
124 if (array_key_exists(
"analysis", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"analysis"])) {
125 $analysis->setUsingArray($scanOptionsJSON[
"analysis"], $apiVersion);
126 $parametersSent =
true;
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;
137 if (array_key_exists(
"scancode", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"scancode"])) {
138 $scancode->setUsingArray($scanOptionsJSON[
"scancode"]);
139 $parametersSent =
true;
142 $reuser =
new Reuser(0,
'groupName',
false,
false);
144 if (array_key_exists(
"reuse", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"reuse"])) {
145 $reuser->setUsingArray($scanOptionsJSON[
"reuse"], $apiVersion);
146 $parametersSent =
true;
148 }
catch (\UnexpectedValueException $e) {
152 if ($decider->getBulkReused() ===
true) {
153 $reuser->setReuseBulk(
true);
156 if (! $parametersSent) {
160 $scanOptions =
new ScanOptions($analysis, $reuser, $decider, $scancode);
161 return $scanOptions->scheduleAgents($folderId, $uploadId, $newUpload);
182 $isPublic, $ignoreScm, $uploadType,
183 $applyGlobal =
false, $excludefolder =
false)
185 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
186 $uploadedFile = $symReq->files->get($this->uploadFilePage::FILE_INPUT_NAME,
195 if ($excludefolder) {
202 if (! empty($ignoreScm) && ($ignoreScm ==
"true")) {
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.",
216 return $this->
handleUpload($reqBody, $uploadType, $folderId,
217 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
220 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
237 $isPublic, $ignoreScm = 0, $applyGlobal = 0, $excludefolder = 0)
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");
244 $symfonyRequest->request->set($this->uploadFilePage::FOLDER_PARAMETER_NAME,
246 $symfonyRequest->request->set(
247 $this->uploadFilePage::DESCRIPTION_INPUT_NAME,
249 $symfonyRequest->files->set($this->uploadFilePage::FILE_INPUT_NAME,
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);
259 return $this->uploadFilePage->handleRequest($symfonyRequest);
275 private function handleUpload($body, $uploadType, $folderId, $fileDescription,
276 $isPublic, $ignoreScm = 0, $applyGlobal = 0, $excludefolder = 0)
279 switch ($uploadType) {
290 $message =
"Invalid 'uploadType'";
291 $statusDescription =
"uploadType should be any of (" .
292 implode(
",", self::VALID_UPLOAD_TYPES) .
")";
294 $sanity = array(
false, $message, $statusDescription, $code);
296 if ($sanity !==
true) {
299 $uploadResponse =
false;
300 switch ($uploadType) {
303 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
307 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
311 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
314 return $uploadResponse;
330 $statusDescription =
"";
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) .
")";
341 if ($vcsData[
"vcsType"] ==
"git") {
347 if (! array_key_exists(
"vcsUrl", $vcsData)) {
348 $message =
"Missing vcsUrl";
349 $statusDescription =
"vcsUrl should be passed.";
353 if (! array_key_exists(
"vcsName", $vcsData)) {
354 $vcsData[
"vcsName"] =
"";
356 if (! array_key_exists(
"vcsUsername", $vcsData)) {
357 $vcsData[
"vcsUsername"] =
"";
359 if (! array_key_exists(
"vcsPassword", $vcsData)) {
360 $vcsData[
"vcsPassword"] =
"";
362 if (! array_key_exists(
"vcsBranch", $vcsData)) {
363 $vcsData[
"vcsBranch"] =
"";
365 $vcsData[
"vcsType"] = $vcsType;
367 return array(
false, $message, $statusDescription, $code);
385 $statusDescription =
"";
388 if (! array_key_exists(
"url", $urlData)) {
389 $message =
"Missing url";
390 $statusDescription =
"Missing upload url from request";
394 if (! array_key_exists(
"name", $urlData)) {
395 $urlData[
"name"] =
"";
397 if (! array_key_exists(
"accept", $urlData)) {
398 $urlData[
"accept"] =
"";
400 if (! array_key_exists(
"reject", $urlData)) {
401 $urlData[
"reject"] =
"";
403 if (! array_key_exists(
"maxRecursionDepth", $urlData)) {
404 $urlData[
"maxRecursionDepth"] =
"";
407 return array(
false, $message, $statusDescription, $code);
425 $statusDescription =
"";
428 if (! array_key_exists(
"path", $srvData)) {
429 $message =
"Missing path";
430 $statusDescription =
"Missing upload path from request";
434 if (! array_key_exists(
"name", $srvData)) {
435 $srvData[
"name"] =
"";
438 return array(
false, $message, $statusDescription, $code);
456 $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
458 $vcsType = $vcsData[
"vcsType"];
459 $vcsUrl = $vcsData[
"vcsUrl"];
460 $vcsName = $vcsData[
"vcsName"];
461 $vcsUsername = $vcsData[
"vcsUsername"];
462 $vcsPasswd = $vcsData[
"vcsPassword"];
463 $vcsBranch = $vcsData[
"vcsBranch"];
465 $symfonySession = $GLOBALS[
'container']->get(
'session');
466 $symfonySession->set($this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
469 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
470 $symfonyRequest->setSession($symfonySession);
472 $symfonyRequest->request->set($this->uploadVcsPage::FOLDER_PARAMETER_NAME,
474 $symfonyRequest->request->set($this->uploadVcsPage::DESCRIPTION_INPUT_NAME,
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);
489 return $this->uploadVcsPage->handleRequest($symfonyRequest);
504 $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
506 $url = $urlData[
"url"];
507 $name = $urlData[
"name"];
508 $accept = $urlData[
"accept"];
509 $reject = $urlData[
"reject"];
510 $maxRecursionDepth = $urlData[
"maxRecursionDepth"];
512 $symfonySession = $GLOBALS[
'container']->get(
'session');
513 $symfonySession->set($this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
516 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
517 $symfonyRequest->setSession($symfonySession);
519 $symfonyRequest->request->set($this->uploadUrlPage::FOLDER_PARAMETER_NAME,
521 $symfonyRequest->request->set($this->uploadUrlPage::DESCRIPTION_INPUT_NAME,
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,
532 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
533 $symfonyRequest->request->set(
'scm', $ignoreScm);
534 $symfonyRequest->request->set(
'excludefolder', $excludefolder);
536 return $this->uploadUrlPage->handleRequest($symfonyRequest);
551 $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
553 $path = $srvData[
"path"];
554 $name = $srvData[
"name"];
556 $symfonySession = $GLOBALS[
'container']->get(
'session');
557 $symfonySession->set($this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
560 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
561 $symfonyRequest->setSession($symfonySession);
563 $symfonyRequest->request->set($this->uploadSrvPage::FOLDER_PARAMETER_NAME,
565 $symfonyRequest->request->set($this->uploadSrvPage::DESCRIPTION_INPUT_NAME,
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,
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);
577 return $this->uploadSrvPage->handleRequest($symfonyRequest);
586 public function generateUploadSummary($uploadId, $groupId)
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');
595 $agentName =
"copyright";
596 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($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();
606 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
607 UploadTreeProxy::OPT_GROUP_ID => $groupId),
608 $uploadTreeTableName,
609 'already_cleared_uploadtree' . $uploadId);
610 $filesToBeCleared = $nonClearedUploadTreeView->count();
612 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
613 $uploadTreeTableName);
615 $scanProx->createAgentStatus([$agentName]);
616 $agents = $scanProx->getLatestSuccessfulAgentIds();
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));
625 $mainLicenses = $this->
getMainLicenses($dbManager, $uploadId, $groupId);
628 $uiLicense = $restHelper->getPlugin(
"license");
629 $hist = $uiLicense->getUploadHist($itemTreeBounds);
630 if (!is_array($hist) || !array_key_exists(
'uniqueLicenseCount', $hist)) {
632 $hist[
'uniqueLicenseCount'] = 0;
633 $hist[
'scannerLicenseCount'] = 0;
634 $hist[
'editedUniqueLicenseCount'] = 0;
635 $hist[
'editedLicenseCount'] = 0;
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));
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);
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);
673 foreach ($rows as $row) {
674 $mainLicenses[] = $row[
'rf_shortname'];
676 return $mainLicenses;
685 public function getUploadCopyrightList($uploadId)
688 $restHelper = $container->get(
'helper.restHelper');
689 $uploadDao = $restHelper->getUploadDao();
691 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
692 $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
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"]);
704 $responseList = array();
705 foreach ($copyrightList as $copyFilepath) {
707 foreach ($responseList as $response) {
708 if ($copyFilepath[
'content'] == $response[
'copyright']) {
714 $copyrightContent = array();
715 foreach ($copyrightList as $copy) {
716 if (strcasecmp($copyFilepath[
'content'], $copy[
'content']) == 0) {
717 $copyrightContent[] = $copy[
'filePath'];
720 $responseRow = array();
721 $responseRow[
'copyright'] = $copyFilepath[
'content'];
722 $responseRow[
'filePath'] = $copyrightContent;
723 $responseList[] = $responseRow;
726 return $responseList;
740 if ($itemTreeBounds !==
null) {
741 $clearingList = $clearingDao->getFileClearings($itemTreeBounds, $groupId);
747 foreach ($clearingList as $clearingDecision) {
748 $clearingArray[] = $clearingDecision->getType();
751 if (empty($clearingArray) || $clearingArray[0] ===
null) {
752 return "NOASSERTION";
768 public function getUploadLicenseList($uploadId, $agents, $printContainers, $boolLicense, $boolCopyright, $page = 0, $limit = 50, $apiVersion=ApiVersion::V1)
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();
778 $scanProx->createAgentStatus($agents);
779 $agent_ids = $scanProx->getLatestSuccessfulAgentIds();
780 $clearingDao = $container->get(
"dao.clearing");
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"]);
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"]);
806 $responseList = array();
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'];
818 if (count($copyrightContent)==0) {
819 $copyrightContent =
null;
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);
830 $itemTreeBounds=
null;
833 $clearingDao, $groupId);
834 $responseRow =
new FileLicenses($license[
'filePath'], $findings,
836 $responseList[] = $responseRow->getArray($apiVersion);
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'];
846 $findings =
new Findings();
847 $findings->setCopyright($copyrightContent);
848 $responseRow =
new FileLicenses($copyFilepath[
'filePath'], $findings);
849 $responseList[] = $responseRow->getArray($apiVersion);
852 $offset = $page * $limit;
853 $paginatedResponseList = array_slice($responseList, $offset, $limit);
854 $paginatedResponseListSize =
sizeof($responseList);
855 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, $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.
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.