16 namespace Fossology\UI\Api\Controllers;
50 use Psr\Http\Message\ServerRequestInterface;
51 use Slim\Psr7\Factory\StreamFactory;
134 $groupId = $this->restHelper->getGroupId();
135 $dbManager = $this->dbHelper->getDbManager();
136 $this->agentDao = $this->container->get(
'dao.agent');
138 $uploadBrowseProxy->sanity();
155 $query = $request->getQueryParams();
162 if (array_key_exists(self::FOLDER_PARAM, $query)) {
163 $folderId = filter_var($query[self::FOLDER_PARAM], FILTER_VALIDATE_INT);
164 if (! $this->restHelper->getFolderDao()->isFolderAccessible($folderId,
165 $this->restHelper->getUserId())) {
170 if (array_key_exists(self::RECURSIVE_PARAM, $query)) {
171 $recursive = filter_var($query[self::RECURSIVE_PARAM],
172 FILTER_VALIDATE_BOOLEAN);
174 if (array_key_exists(self::FILTER_NAME, $query)) {
177 if (array_key_exists(self::FILTER_STATUS, $query)) {
178 switch (strtolower($query[self::FILTER_STATUS])) {
180 $status = UploadStatus::OPEN;
183 $status = UploadStatus::IN_PROGRESS;
186 $status = UploadStatus::CLOSED;
189 $status = UploadStatus::REJECTED;
195 if (array_key_exists(self::FILTER_ASSIGNEE, $query)) {
197 if (strcasecmp($username,
"-me-") === 0) {
198 $assignee = $this->restHelper->getUserId();
199 } elseif (strcasecmp($username,
"-unassigned-") === 0) {
202 $assignee = $this->restHelper->getUserDao()->getUserByName($username);
203 if (empty($assignee)) {
206 $assignee = $assignee[
'user_pk'];
209 if (array_key_exists(self::FILTER_DATE, $query)) {
210 $date = filter_var($query[self::FILTER_DATE], FILTER_VALIDATE_REGEXP,
212 "regexp" =>
"/^\d{4}\-\d{2}\-\d{2}$/",
213 "flags" => FILTER_NULL_ON_FAILURE
215 $since = strtotime($date);
217 if ($apiVersion == ApiVersion::V2) {
221 $page = $request->getHeaderLine(self::PAGE_PARAM);
222 $limit = $request->getHeaderLine(self::LIMIT_PARAM);
224 if (! empty($page) || $page ==
"0") {
225 $page = filter_var($page, FILTER_VALIDATE_INT);
228 "page should be positive integer > 0");
233 if (! empty($limit)) {
234 $limit = filter_var($limit, FILTER_VALIDATE_INT);
237 "limit should be positive integer > 1");
243 if (isset($args[
'id'])) {
244 $id = intval($args[
'id']);
249 "folderId" => $folderId,
252 "assignee" => $assignee,
255 list($pages, $uploads) = $this->dbHelper->getUploads(
256 $this->restHelper->getUserId(), $this->restHelper->getGroupId(), $limit,
257 $page, $id, $options, $recursive, $apiVersion);
258 if ($id !==
null && ! empty($uploads)) {
259 $uploads = $uploads[0];
262 return $response->withHeader(
"X-Total-Pages", $pages)->withJson($uploads,
275 public function uploadDownload($request, $response, $args)
278 $ui_download = $this->restHelper->getPlugin(
'download');
281 if (isset($args[
'id'])) {
282 $id = intval($args[
'id']);
285 $dbManager = $this->restHelper->getDbHelper()->getDbManager();
286 $uploadDao = $this->restHelper->getUploadDao();
287 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($id);
288 $itemTreeBounds = $uploadDao->getParentItemBounds($id,$uploadTreeTableName);
289 $sql =
"SELECT pfile_fk , ufile_name FROM uploadtree_a WHERE uploadtree_pk=$1";
290 $params = array($itemTreeBounds->getItemId());
291 $descendants = $dbManager->getSingleRow($sql,$params);
292 $path=
RepPath(($descendants[
'pfile_fk']));
293 $responseFile = $ui_download->getDownload($path, $descendants[
'ufile_name']);
294 $responseContent = $responseFile->getFile();
295 $newResponse = $response->withHeader(
'Content-Description',
297 ->withHeader(
'Content-Type',
298 $responseContent->getMimeType())
299 ->withHeader(
'Content-Disposition',
300 $responseFile->headers->get(
'Content-Disposition'))
301 ->withHeader(
'Cache-Control',
'must-revalidate')
302 ->withHeader(
'Pragma',
'private')
303 ->withHeader(
'Content-Length', filesize($responseContent->getPathname()));
304 $sf =
new StreamFactory();
305 return $newResponse->withBody(
306 $sf->createStreamFromFile($responseContent->getPathname())
321 $id = intval($args[
'id']);
322 $query = $request->getQueryParams();
323 $selectedAgentId = $query[
'agentId'] ??
null;
324 $agentDao = $this->container->get(
'dao.agent');
326 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
331 $uploadSummary = $uploadHelper->generateUploadSummary($id, $this->restHelper->getGroupId());
332 $browseLicense = $this->restHelper->getPlugin(
'license');
333 $uploadDao = $this->restHelper->getUploadDao();
334 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($id);
335 $itemTreeBounds = $uploadDao->getParentItemBounds($id, $uploadTreeTableName);
337 $scannerAgents = array_keys(AgentRef::AGENT_LIST);
338 $scanJobProxy->createAgentStatus($scannerAgents);
339 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
340 $res = $browseLicense->createLicenseHistogram(
"",
"", $itemTreeBounds, $selectedAgentIds, $this->restHelper->getGroupId());
341 $uploadSummary->setUniqueConcludedLicenses($res[
'editedUniqueLicenseCount']);
342 $uploadSummary->setTotalConcludedLicenses($res[
'editedLicenseCount']);
343 $uploadSummary->setTotalLicenses($res[
'scannerLicenseCount']);
344 $uploadSummary->setUniqueLicenses($res[
'uniqueLicenseCount']);
345 $uploadSummary->setConcludedNoLicenseFoundCount($res[
'editedNoLicenseFoundCount']);
346 $uploadSummary->setFileCount($res[
'fileCount']);
347 $uploadSummary->setNoScannerLicenseFoundCount($res[
'noScannerLicenseFoundCount']);
348 $uploadSummary->setScannerUniqueLicenseCount($res[
'scannerUniqueLicenseCount']);
350 return $response->withJson($uploadSummary->getArray(), 200);
364 require_once dirname(__DIR__, 4) .
"/delagent/ui/delete-helper.php";
365 $id = intval($args[
'id']);
368 $result = TryToDelete($id, $this->restHelper->getUserId(),
369 $this->restHelper->getGroupId(), $this->restHelper->getUploadDao());
372 $result->getDeleteMessageString());
374 $returnVal =
new Info(202,
"Delete Job for file with id " . $id,
376 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
390 $queryParams = $request->getQueryParams();
391 $action = $queryParams[
'action'] ??
"";
393 $action = $request->getHeaderLine(
'action');
395 if (strtolower($action) ==
"move") {
400 return $this->
changeUpload($request, $response, $args, $copy);
415 $queryParams = $request->getQueryParams();
417 $paramType = ($isApiVersionV2) ?
'parameter' :
'header';
419 if ((!$isApiVersionV2 && !$request->hasHeader(
'folderId') || $isApiVersionV2 && !isset($queryParams[
'folderId']))
420 || !is_numeric($newFolderID = ($isApiVersionV2 ? $queryParams[
'folderId'] : $request->getHeaderLine(
'folderId')))) {
421 throw new HttpBadRequestException(
"For API version " . ($isApiVersionV2 ?
'V2' :
'V1') .
", 'folderId' $paramType should be present and an integer.");
424 $id = intval($args[
'id']);
425 $returnVal = $this->restHelper->copyUpload($id, $newFolderID, $isCopy);
426 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
442 $uploadType = $reqBody[
'uploadType'] ??
null;
443 $folderId = $reqBody[
'folderId'] ??
null;
444 $description = $reqBody[
'uploadDescription'] ??
"";
445 $public = $reqBody[
'public'] ??
null;
446 $applyGlobal = filter_var($reqBody[
'applyGlobal'] ??
null,
447 FILTER_VALIDATE_BOOLEAN);
448 $ignoreScm = $reqBody[
'ignoreScm'] ??
null;
450 $uploadType = $request->getHeaderLine(
'uploadType');
451 $folderId = $request->getHeaderLine(
'folderId');
452 $description = $request->getHeaderLine(
'uploadDescription');
453 $public = $request->getHeaderLine(
'public');
454 $applyGlobal = filter_var($request->getHeaderLine(
'applyGlobal'),
455 FILTER_VALIDATE_BOOLEAN);
456 $ignoreScm = $request->getHeaderLine(
'ignoreScm');
459 $public = empty($public) ?
'protected' : $public;
461 if (empty($uploadType)) {
465 if (array_key_exists(
'scanOptions', $reqBody)) {
466 if ($uploadType ==
'file') {
467 $scanOptions = json_decode($reqBody[
'scanOptions'],
true);
469 $scanOptions = $reqBody[
'scanOptions'];
473 if (! is_array($scanOptions)) {
479 if ($uploadType !=
"file" && (empty($reqBody) ||
480 ! array_key_exists(
"location", $reqBody))) {
482 "Require location object if uploadType != file");
484 if (empty($folderId) ||
485 !is_numeric($folderId) && $folderId > 0) {
489 $allFolderIds = $this->restHelper->getFolderDao()->getAllFolderIds();
490 if (!in_array($folderId, $allFolderIds)) {
493 if (!$this->restHelper->getFolderDao()->isFolderAccessible($folderId)) {
497 $locationObject = [];
498 if (array_key_exists(
"location", $reqBody)) {
499 $locationObject = $reqBody[
"location"];
500 } elseif ($uploadType !=
'file') {
502 "Require location object if uploadType != file");
505 $uploadResponse = $uploadHelper->createNewUpload($locationObject,
506 $folderId, $description, $public, $ignoreScm, $uploadType,
508 $status = $uploadResponse[0];
509 $message = $uploadResponse[1];
510 $statusDescription = $uploadResponse[2];
516 $uploadId = $uploadResponse[3];
517 if (! empty($scanOptions)) {
518 $info = $uploadHelper->handleScheduleAnalysis(intval($uploadId),
519 intval($folderId), $scanOptions,
true);
520 if ($info->getCode() == 201) {
521 $info =
new Info($info->getCode(), intval($uploadId), $info->getType());
524 $info =
new Info(201, intval($uploadId), InfoType::INFO);
526 return $response->withJson($info->getArray(), $info->getCode());
540 $id = intval($args[
'id']);
541 $query = $request->getQueryParams();
543 if ($apiVersion == ApiVersion::V2) {
544 $page = $query[
'page'] ??
"";
545 $limit = $query[
'limit'] ??
"";
547 $page = $request->getHeaderLine(
"page");
548 $limit = $request->getHeaderLine(
"limit");
550 if (! array_key_exists(self::AGENT_PARAM, $query)) {
553 $agents = explode(
",", $query[self::AGENT_PARAM]);
555 if (array_key_exists(self::CONTAINER_PARAM, $query)) {
556 $containers = (strcasecmp($query[self::CONTAINER_PARAM],
"true") === 0);
560 if (array_key_exists(
'license', $query)) {
561 $license = (strcasecmp($query[
'license'],
"true") === 0);
565 if (array_key_exists(
'copyright', $query)) {
566 $copyright = (strcasecmp($query[
'copyright'],
"true") === 0);
569 if (!$license && !$copyright) {
571 "'license' and 'copyright' atleast one should be true.");
582 if ((! ($page===
'') && (! is_numeric($page) || $page < 1)) ||
583 (! ($limit===
'') && (! is_numeric($limit) || $limit < 1))) {
585 "page and limit need to be positive integers!");
596 }
else if ($limit > 1000) {
601 list($licenseList, $count) = $uploadHelper->getUploadLicenseList($id, $agents, $containers, $license, $copyright, $page-1, $limit, $apiVersion);
602 $totalPages = intval(ceil($count / $limit));
603 return $response->withHeader(
"X-Total-Pages", $totalPages)->withJson($licenseList, 200);
617 $id = intval($args[
'id']);
621 $licenseList = $uploadHelper->getUploadCopyrightList($id);
622 return $response->withJson($licenseList, 200);
636 $id = intval($args[
'id']);
637 $query = $request->getQueryParams();
638 $userDao = $this->restHelper->getUserDao();
639 $userId = $this->restHelper->getUserId();
640 $groupId = $this->restHelper->getGroupId();
642 $perm = $userDao->isAdvisorOrAdmin($userId, $groupId);
645 "Can not update upload.");
650 $this->dbHelper->getDbManager()
658 if (array_key_exists(self::FILTER_ASSIGNEE, $query)) {
659 $assignee = filter_var($query[self::FILTER_ASSIGNEE], FILTER_VALIDATE_INT);
660 $userList = $userDao->getUserChoices($groupId);
661 if (!array_key_exists($assignee, $userList)) {
663 "New assignee does not have permisison on upload.");
665 $uploadBrowseProxy->updateTable(
"assignee", $id, $assignee);
669 array_key_exists(self::FILTER_STATUS, $query) &&
670 in_array(strtolower($query[self::FILTER_STATUS]), self::VALID_STATUS)
672 $newStatus = strtolower($query[self::FILTER_STATUS]);
674 if (in_array($newStatus, [
"closed",
"rejected"])) {
675 $body = $request->getBody();
676 $comment = $body->getContents();
680 if ($newStatus == self::VALID_STATUS[1]) {
681 $status = UploadStatus::IN_PROGRESS;
682 } elseif ($newStatus == self::VALID_STATUS[2]) {
683 $status = UploadStatus::CLOSED;
684 } elseif ($newStatus == self::VALID_STATUS[3]) {
685 $status = UploadStatus::REJECTED;
687 $status = UploadStatus::OPEN;
689 $uploadBrowseProxy->setStatusAndComment($id, $status, $comment);
692 $returnVal =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
693 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
703 $itemTreeBounds = $this->restHelper->getUploadDao()->getParentItemBounds(
705 if ($itemTreeBounds ===
false || empty($itemTreeBounds->getLeft())) {
707 "Ununpack job not started. Please check job status at " .
708 "/api/v1/jobs?upload=" . $id))
709 ->setHeaders([
'Retry-After' =>
'60',
710 'Look-at' =>
"/api/v1/jobs?upload=" . $id]);
728 $agentList = array_keys(AgentRef::AGENT_LIST);
729 $intersectArray = array_intersect($agents, $agentList);
731 if (count($agents) != count($intersectArray)) {
733 implode(
", ", $agentList) .
". " . implode(
",", $agents) .
" passed.");
736 foreach ($agents as $agent) {
737 if (!
$agentDao->arsTableExists($agent)) {
739 "Agent $agent not scheduled for the upload. " .
740 "Please POST to /jobs");
746 $agentList = $scanProxy->createAgentStatus($agents);
748 foreach ($agentList as $agent) {
749 if (! array_key_exists(
'currentAgentId', $agent)) {
751 "Agent " . $agent[
"agentName"] .
752 " not scheduled for the upload. Please POST to /jobs");
754 if (array_key_exists(
'isAgentRunning', $agent) &&
755 $agent[
'isAgentRunning']) {
757 "Agent " . $agent[
"agentName"] .
" is running. " .
758 "Please check job status at /api/v1/jobs?upload=" . $uploadId))
759 ->setHeaders([
'Retry-After' =>
'60',
760 'Look-at' =>
"/api/v1/jobs?upload=" . $uploadId]);
779 if (!$commu_status) {
785 $uploadPermissionObj =
$restHelper->getPlugin(
'upload_permissions');
787 $dbManager = $this->dbHelper->getDbManager();
791 $folder_pk = intval($reqBody[
'folderId']);
792 $upload_pk = intval($args[
'id']);
794 $allUploadsPerm = $reqBody[
'allUploadsPermission'] ? 1 : 0;
795 $newgroup = intval($reqBody[
'groupId']);
796 $newperm = $this->getEquivalentValueForPermission($reqBody[
'newPermission']);
797 $public_perm = isset($reqBody[
'publicPermission']) ? $this->getEquivalentValueForPermission($reqBody[
'publicPermission']) : -1;
799 $query =
"SELECT perm, perm_upload_pk FROM perm_upload WHERE upload_fk=$1 and group_fk=$2;";
800 $result = $dbManager->getSingleRow($query, [$upload_pk, $newgroup], __METHOD__.
".getOldPerm");
803 if (!empty($result)) {
804 $perm_upload_pk = intVal($result[
'perm_upload_pk']);
808 $uploadPermissionObj->editPermissionsForUpload($commu_status, $folder_pk, $upload_pk, $allUploadsPerm, $perm_upload_pk, $perm, $newgroup, $newperm, $public_perm);
810 $returnVal =
new Info(202,
"Permissions updated successfully!", InfoType::INFO);
811 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
814 public function getEquivalentValueForPermission($perm)
821 case 'clearing_admin':
822 return Auth::PERM_CADMIN;
842 $upload_pk = intval($args[
'id']);
844 $publicPerm = $this->restHelper->getUploadPermissionDao()->getPublicPermission($upload_pk);
845 $permGroups = $this->restHelper->getUploadPermissionDao()->getPermissionGroups($upload_pk);
848 $finalPermGroups = [];
849 foreach ($permGroups as $value) {
850 $groupPerm =
new GroupPermission($value[
'perm'], $value[
'group_pk'], $value[
'group_name']);
851 $finalPermGroups[] = $groupPerm->getArray($apiVersion);
853 $res =
new Permissions($publicPerm, $finalPermGroups);
854 return $response->withJson($res->getArray($apiVersion), 200);
866 public function getMainLicenses($request, $response, $args)
868 $uploadId = intval($args[
'id']);
872 $clearingDao = $this->container->get(
'dao.clearing');
873 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
874 $licenseDao = $this->container->get(
'dao.license');
877 foreach ($licenseIds as $value) {
878 $licenseId = intval($value);
879 $obligations = $licenseDao->getLicenseObligations([$licenseId],
881 $obligations = array_merge($obligations,
882 $licenseDao->getLicenseObligations([$licenseId],
true));
883 $obligationList = [];
884 foreach ($obligations as $obligation) {
886 $obligation[
'ob_pk'],
887 $obligation[
'ob_topic'],
888 $obligation[
'ob_type'],
889 $obligation[
'ob_text'],
890 $obligation[
'ob_classification'],
891 $obligation[
'ob_comment']
894 $license = $licenseDao->getLicenseById($licenseId);
897 $license->getShortName(),
898 $license->getFullName(),
904 $licenses[] = $licenseObj->getArray();
906 return $response->withJson($licenses, 200);
918 public function setMainLicense($request, $response, $args)
920 $uploadId = intval($args[
'id']);
922 $shortName = $body[
'shortName'];
923 $licenseDao = $this->container->get(
'dao.license');
924 $clearingDao = $this->container->get(
'dao.clearing');
928 if (empty($shortName)) {
929 throw new HttpBadRequestException(
"Short name missing from request.");
931 $license = $licenseDao->getLicenseByShortName($shortName,
932 $this->restHelper->getGroupId());
934 if ($license ===
null) {
935 throw new HttpNotFoundException(
936 "No license with shortname '$shortName' found.");
939 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
940 if (in_array($license->getId(), $licenseIds)) {
941 throw new HttpBadRequestException(
942 "License already exists for this upload.");
946 $clearingDao = $this->container->get(
'dao.clearing');
947 $clearingDao->makeMainLicense($uploadId, $this->restHelper->getGroupId(), $license->getId());
948 $returnVal =
new Info(200,
"Successfully added new main license", InfoType::INFO);
949 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
961 public function removeMainLicense($request, $response, $args)
963 $uploadId = intval($args[
'id']);
964 $shortName = $args[
'shortName'];
965 $licenseDao = $this->container->get(
'dao.license');
966 $clearingDao = $this->container->get(
'dao.clearing');
967 $license = $licenseDao->getLicenseByShortName($shortName, $this->restHelper->getGroupId());
971 if ($license ===
null) {
972 throw new HttpNotFoundException(
973 "No license with shortname '$shortName' found.");
975 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
976 if (!in_array($license->getId(), $licenseIds)) {
977 throw new HttpBadRequestException(
978 "License '$shortName' is not a main license for this upload.");
981 $clearingDao = $this->container->get(
'dao.clearing');
982 $clearingDao->removeMainLicense($uploadId, $this->restHelper->getGroupId(), $license->getId());
983 $returnVal =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
985 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
999 $uploadId = intval($args[
'id']);
1000 $uploadDao = $this->restHelper->getUploadDao();
1004 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1007 array(UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
1008 UploadTreeProxy::OPT_GROUP_ID => $this->restHelper->getGroupId()),
1009 $uploadTreeTableName,
1010 'no_license_uploadtree' . $uploadId);
1012 $filesOfInterest = $noLicenseUploadTreeView->count();
1015 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
1016 UploadTreeProxy::OPT_GROUP_ID => $this->restHelper->getGroupId()),
1017 $uploadTreeTableName,
1018 'already_cleared_uploadtree' . $uploadId);
1019 $filesToBeCleared = $nonClearedUploadTreeView->count();
1021 $filesAlreadyCleared = $filesOfInterest - $filesToBeCleared;
1024 "totalFilesOfInterest" => intval($filesOfInterest),
1025 "totalFilesCleared" => intval($filesAlreadyCleared),
1027 return $response->withJson($res, 200);
1041 $agentDao = $this->container->get(
'dao.agent');
1042 $clearingDao = $this->container->get(
'dao.clearing');
1043 $licenseDao = $this->container->get(
'dao.license');
1045 $uploadId = intval($args[
'id']);
1046 $uploadDao = $this->restHelper->getUploadDao();
1047 $query = $request->getQueryParams();
1048 $selectedAgentId = $query[
'agentId'] ??
null;
1052 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
1056 $scannerAgents = array_keys($this->agentNames);
1058 $scanJobProxy->createAgentStatus($scannerAgents);
1059 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1060 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1061 $editedLicenses = $clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $this->restHelper->getGroupId());
1062 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
1063 $scannedLicenses = $licenseDao->getLicenseHistogram($itemTreeBounds, $selectedAgentIds);
1064 $allScannerLicenseNames = array_keys($scannedLicenses);
1065 $allEditedLicenseNames = array_keys($editedLicenses);
1066 $allLicNames = array_unique(array_merge($allScannerLicenseNames, $allEditedLicenseNames));
1067 $realLicNames = array_diff($allLicNames, array(LicenseDao::NO_LICENSE_FOUND));
1068 $totalScannerLicenseCount = 0;
1069 $editedTotalLicenseCount = 0;
1072 foreach ($realLicNames as $licenseShortName) {
1074 if (array_key_exists($licenseShortName, $scannedLicenses)) {
1075 $count = $scannedLicenses[$licenseShortName][
'unique'];
1076 $rfId = $scannedLicenses[$licenseShortName][
'rf_pk'];
1078 $rfId = $editedLicenses[$licenseShortName][
'rf_pk'];
1080 $editedCount = array_key_exists($licenseShortName, $editedLicenses) ? $editedLicenses[$licenseShortName][
'count'] : 0;
1081 $totalScannerLicenseCount += $count;
1082 $editedTotalLicenseCount += $editedCount;
1083 $scannerCountLink = $count;
1084 $editedLink = $editedCount;
1086 $res[] = array($scannerCountLink, $editedLink, array($licenseShortName, $rfId));
1091 foreach ($res as $item) {
1093 "id" => intval($item[2][1]),
1094 "name" => $item[2][0],
1095 "scannerCount" => intval($item[0]),
1096 "concludedCount" => intval($item[1]),
1099 return $response->withJson($outputArray, 200);
1113 $uploadId = intval($args[
'id']);
1117 $scannerAgents = array_keys($this->agentNames);
1118 $agentDao = $this->container->get(
'dao.agent');
1120 $res = $scanJobProxy->createAgentStatus($scannerAgents);
1123 foreach ($res as &$item) {
1124 $successfulAgents = [];
1125 if (count($item[
'successfulAgents']) > 0) {
1126 $item[
'isAgentRunning'] =
false;
1128 $item[
'currentAgentId'] =
$agentDao->getCurrentAgentRef($item[
"agentName"])->getAgentId();
1129 $item[
'currentAgentRev'] =
"";
1131 foreach ($item[
'successfulAgents'] as &$agent) {
1132 $successfulAgent =
new SuccessfulAgent(intval($agent[
'agent_id']), $agent[
'agent_rev'], $agent[
'agent_name']);
1135 $agent =
new Agent($successfulAgents, $item[
'uploadId'], $item[
'agentName'], $item[
'currentAgentId'], $item[
'currentAgentRev'], $item[
'isAgentRunning']);
1138 return $response->withJson($outputArray, 200);
1152 $uploadId = intval($args[
'id']);
1156 $clearingDao = $this->container->get(
'dao.clearing');
1157 $uploadDao = $this->restHelper->getUploadDao();
1158 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1159 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1160 $res = $clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $this->restHelper->getGroupId());
1163 foreach ($res as $key => $value) {
1164 $editedLicense =
new EditedLicense(intval($value[
"rf_pk"]), $key, intval($value[
"count"]), $value[
"spdx_id"]);
1167 return $response->withJson($outputArray, 200);
1179 public function getReuseReportSummary($request, $response, $args)
1181 $uploadId = intval($args[
'id']);
1185 $reuseReportProcess = $this->container->get(
'businessrules.reusereportprocessor');
1186 $res = $reuseReportProcess->getReuseSummary($uploadId);
1187 return $response->withJson($res, 200);
1201 $uploadId = intval($args[
'id']);
1202 $query = $request->getQueryParams();
1203 $selectedAgentId = $query[
'agentId'] ??
null;
1204 $licenseDao = $this->container->get(
'dao.license');
1207 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
1210 $scannerAgents = array_keys(AgentRef::AGENT_LIST);
1211 $scanJobProxy =
new ScanJobProxy($this->agentDao, $uploadId);
1212 $scanJobProxy->createAgentStatus($scannerAgents);
1213 $uploadDao = $this->restHelper->getUploadDao();
1214 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1215 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1216 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
1217 $res = $licenseDao->getLicenseHistogram($itemTreeBounds, $selectedAgentIds);
1220 foreach ($res as $key => $value) {
1221 $scannedLicense =
new ScannedLicense($licenseDao->getLicenseByShortName($key)->getId(), $key, $value[
'count'], $value[
'unique'], $value[
'spdx_id']);
1224 return $response->withJson($outputArray, 200);
1237 $agentDao = $this->container->get(
'dao.agent');
1238 $uploadId = intval($args[
'id']);
1242 $scannerAgents = array_keys($this->agentNames);
1244 $scanJobProxy->createAgentStatus($scannerAgents);
1247 foreach ($scanJobProxy->getSuccessfulAgents() as $agent) {
1249 "id" => $agent->getAgentId(),
1250 "name" => $agent->getAgentName(),
1251 "revision" => $agent->getAgentRevision(),
1254 return $response->withJson($res, 200);
1268 $uploadId = intval($args[
'id']);
1269 if (!$this->dbHelper->doesIdExist(
"upload",
"upload_pk", $uploadId)) {
1270 $returnVal =
new Info(404,
"Upload does not exist", InfoType::ERROR);
1271 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1273 $uploadDao = $this->restHelper->getUploadDao();
1274 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
1275 $uploadDao->getUploadtreeTableName($uploadId));
1276 if ($itemTreeBounds ===
false) {
1277 $error =
new Info(500,
"Unable to get top item.", InfoType::ERROR);
1278 return $response->withJson($error->getArray(), $error->getCode());
1280 $info =
new Info(200, $itemTreeBounds->getItemId(), InfoType::INFO);
1281 return $response->withJson($info->getArray(), $info->getCode());
Messages which can be generated by delagent.
Contains the constants and helpers for authentication of user.
Base controller for REST calls.
getParsedBody(ServerRequestInterface $request)
Parse request body as JSON and return associative PHP array.
Controller for Upload model.
getUploadCopyrights($request, $response, $args)
getLicensesHistogram($request, $response, $args)
getTopItem($request, $response, $args)
areAgentsScheduled($uploadId, $agents, $response)
updateUpload($request, $response, $args)
getClearingProgressInfo($request, $response, $args)
setUploadPermissions($request, $response, $args)
getUploads($request, $response, $args)
getAllAgents($request, $response, $args)
getAgentsRevision($request, $response, $args)
getGroupsWithPermissions($request, $response, $args)
getEditedLicenses($request, $response, $args)
getScannedLicenses($request, $response, $args)
getUploadLicenses($request, $response, $args)
moveUpload($request, $response, $args)
deleteUpload($request, $response, $args)
postUpload($request, $response, $args)
changeUpload($request, $response, $args, $isCopy)
getUploadSummary($request, $response, $args)
Override Slim response for withJson function.
Handle new file uploads from Slim framework and move to FOSSology.
static getVersion(ServerRequestInterface $request)
Different type of infos provided by REST.
Info model to contain general error and return values.
RepPath($PfilePk, $Repo="files")
Given a pfile id, retrieve the pfile path.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.