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 (! $parametersSent) {
156 $scanOptions =
new ScanOptions($analysis, $reuser, $decider, $scancode);
157 return $scanOptions->scheduleAgents($folderId, $uploadId, $newUpload);
178 $isPublic, $ignoreScm, $uploadType,
179 $applyGlobal =
false, $excludefolder =
false)
181 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
182 $uploadedFile = $symReq->files->get($this->uploadFilePage::FILE_INPUT_NAME,
191 if ($excludefolder) {
198 if (! empty($ignoreScm) && ($ignoreScm ==
"true")) {
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.",
212 return $this->
handleUpload($reqBody, $uploadType, $folderId,
213 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
216 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
233 $isPublic, $ignoreScm = 0, $applyGlobal = 0, $excludefolder = 0)
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");
240 $symfonyRequest->request->set($this->uploadFilePage::FOLDER_PARAMETER_NAME,
242 $symfonyRequest->request->set(
243 $this->uploadFilePage::DESCRIPTION_INPUT_NAME,
245 $symfonyRequest->files->set($this->uploadFilePage::FILE_INPUT_NAME,
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);
255 return $this->uploadFilePage->handleRequest($symfonyRequest);
271 private function handleUpload($body, $uploadType, $folderId, $fileDescription,
272 $isPublic, $ignoreScm = 0, $applyGlobal = 0, $excludefolder = 0)
275 switch ($uploadType) {
286 $message =
"Invalid 'uploadType'";
287 $statusDescription =
"uploadType should be any of (" .
288 implode(
",", self::VALID_UPLOAD_TYPES) .
")";
290 $sanity = array(
false, $message, $statusDescription, $code);
292 if ($sanity !==
true) {
295 $uploadResponse =
false;
296 switch ($uploadType) {
299 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
303 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
307 $fileDescription, $isPublic, $ignoreScm, $applyGlobal, $excludefolder);
310 return $uploadResponse;
326 $statusDescription =
"";
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) .
")";
337 if ($vcsData[
"vcsType"] ==
"git") {
343 if (! array_key_exists(
"vcsUrl", $vcsData)) {
344 $message =
"Missing vcsUrl";
345 $statusDescription =
"vcsUrl should be passed.";
349 if (! array_key_exists(
"vcsName", $vcsData)) {
350 $vcsData[
"vcsName"] =
"";
352 if (! array_key_exists(
"vcsUsername", $vcsData)) {
353 $vcsData[
"vcsUsername"] =
"";
355 if (! array_key_exists(
"vcsPassword", $vcsData)) {
356 $vcsData[
"vcsPassword"] =
"";
358 if (! array_key_exists(
"vcsBranch", $vcsData)) {
359 $vcsData[
"vcsBranch"] =
"";
361 $vcsData[
"vcsType"] = $vcsType;
363 return array(
false, $message, $statusDescription, $code);
381 $statusDescription =
"";
384 if (! array_key_exists(
"url", $urlData)) {
385 $message =
"Missing url";
386 $statusDescription =
"Missing upload url from request";
390 if (! array_key_exists(
"name", $urlData)) {
391 $urlData[
"name"] =
"";
393 if (! array_key_exists(
"accept", $urlData)) {
394 $urlData[
"accept"] =
"";
396 if (! array_key_exists(
"reject", $urlData)) {
397 $urlData[
"reject"] =
"";
399 if (! array_key_exists(
"maxRecursionDepth", $urlData)) {
400 $urlData[
"maxRecursionDepth"] =
"";
403 return array(
false, $message, $statusDescription, $code);
421 $statusDescription =
"";
424 if (! array_key_exists(
"path", $srvData)) {
425 $message =
"Missing path";
426 $statusDescription =
"Missing upload path from request";
430 if (! array_key_exists(
"name", $srvData)) {
431 $srvData[
"name"] =
"";
434 return array(
false, $message, $statusDescription, $code);
452 $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
454 $vcsType = $vcsData[
"vcsType"];
455 $vcsUrl = $vcsData[
"vcsUrl"];
456 $vcsName = $vcsData[
"vcsName"];
457 $vcsUsername = $vcsData[
"vcsUsername"];
458 $vcsPasswd = $vcsData[
"vcsPassword"];
459 $vcsBranch = $vcsData[
"vcsBranch"];
461 $symfonySession = $GLOBALS[
'container']->get(
'session');
462 $symfonySession->set($this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
465 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
466 $symfonyRequest->setSession($symfonySession);
468 $symfonyRequest->request->set($this->uploadVcsPage::FOLDER_PARAMETER_NAME,
470 $symfonyRequest->request->set($this->uploadVcsPage::DESCRIPTION_INPUT_NAME,
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);
485 return $this->uploadVcsPage->handleRequest($symfonyRequest);
500 $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
502 $url = $urlData[
"url"];
503 $name = $urlData[
"name"];
504 $accept = $urlData[
"accept"];
505 $reject = $urlData[
"reject"];
506 $maxRecursionDepth = $urlData[
"maxRecursionDepth"];
508 $symfonySession = $GLOBALS[
'container']->get(
'session');
509 $symfonySession->set($this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
512 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
513 $symfonyRequest->setSession($symfonySession);
515 $symfonyRequest->request->set($this->uploadUrlPage::FOLDER_PARAMETER_NAME,
517 $symfonyRequest->request->set($this->uploadUrlPage::DESCRIPTION_INPUT_NAME,
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,
528 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
529 $symfonyRequest->request->set(
'scm', $ignoreScm);
530 $symfonyRequest->request->set(
'excludefolder', $excludefolder);
532 return $this->uploadUrlPage->handleRequest($symfonyRequest);
547 $isPublic, $ignoreScm, $applyGlobal, $excludefolder)
549 $path = $srvData[
"path"];
550 $name = $srvData[
"name"];
552 $symfonySession = $GLOBALS[
'container']->get(
'session');
553 $symfonySession->set($this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
556 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
557 $symfonyRequest->setSession($symfonySession);
559 $symfonyRequest->request->set($this->uploadSrvPage::FOLDER_PARAMETER_NAME,
561 $symfonyRequest->request->set($this->uploadSrvPage::DESCRIPTION_INPUT_NAME,
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,
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);
573 return $this->uploadSrvPage->handleRequest($symfonyRequest);
582 public function generateUploadSummary($uploadId, $groupId)
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');
591 $agentName =
"copyright";
592 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($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();
602 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
603 UploadTreeProxy::OPT_GROUP_ID => $groupId),
604 $uploadTreeTableName,
605 'already_cleared_uploadtree' . $uploadId);
606 $filesToBeCleared = $nonClearedUploadTreeView->count();
608 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
609 $uploadTreeTableName);
611 $scanProx->createAgentStatus([$agentName]);
612 $agents = $scanProx->getLatestSuccessfulAgentIds();
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));
621 $mainLicenses = $this->
getMainLicenses($dbManager, $uploadId, $groupId);
624 $uiLicense = $restHelper->getPlugin(
"license");
625 $hist = $uiLicense->getUploadHist($itemTreeBounds);
626 if (!is_array($hist) || !array_key_exists(
'uniqueLicenseCount', $hist)) {
628 $hist[
'uniqueLicenseCount'] = 0;
629 $hist[
'scannerLicenseCount'] = 0;
630 $hist[
'editedUniqueLicenseCount'] = 0;
631 $hist[
'editedLicenseCount'] = 0;
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));
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);
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);
669 foreach ($rows as $row) {
670 $mainLicenses[] = $row[
'rf_shortname'];
672 return $mainLicenses;
681 public function getUploadCopyrightList($uploadId)
684 $restHelper = $container->get(
'helper.restHelper');
685 $uploadDao = $restHelper->getUploadDao();
687 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
688 $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
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"]);
700 $responseList = array();
701 foreach ($copyrightList as $copyFilepath) {
703 foreach ($responseList as $response) {
704 if ($copyFilepath[
'content'] == $response[
'copyright']) {
710 $copyrightContent = array();
711 foreach ($copyrightList as $copy) {
712 if (strcasecmp($copyFilepath[
'content'], $copy[
'content']) == 0) {
713 $copyrightContent[] = $copy[
'filePath'];
716 $responseRow = array();
717 $responseRow[
'copyright'] = $copyFilepath[
'content'];
718 $responseRow[
'filePath'] = $copyrightContent;
719 $responseList[] = $responseRow;
722 return $responseList;
736 if ($itemTreeBounds !==
null) {
737 $clearingList = $clearingDao->getFileClearings($itemTreeBounds, $groupId);
743 foreach ($clearingList as $clearingDecision) {
744 $clearingArray[] = $clearingDecision->getType();
747 if (empty($clearingArray) || $clearingArray[0] ===
null) {
748 return "NOASSERTION";
764 public function getUploadLicenseList($uploadId, $agents, $printContainers, $boolLicense, $boolCopyright, $page = 0, $limit = 50, $apiVersion=ApiVersion::V1)
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();
774 $scanProx->createAgentStatus($agents);
775 $agent_ids = $scanProx->getLatestSuccessfulAgentIds();
776 $clearingDao = $container->get(
"dao.clearing");
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"]);
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"]);
802 $responseList = array();
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'];
814 if (count($copyrightContent)==0) {
815 $copyrightContent =
null;
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);
826 $itemTreeBounds=
null;
829 $clearingDao, $groupId);
830 $responseRow =
new FileLicenses($license[
'filePath'], $findings,
832 $responseList[] = $responseRow->getArray($apiVersion);
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'];
842 $findings =
new Findings();
843 $findings->setCopyright($copyrightContent);
844 $responseRow =
new FileLicenses($copyFilepath[
'filePath'], $findings);
845 $responseList[] = $responseRow->getArray($apiVersion);
848 $offset = $page * $limit;
849 $paginatedResponseList = array_slice($responseList, $offset, $limit);
850 $paginatedResponseListSize =
sizeof($responseList);
851 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.