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());
438 public function postUpload($request, $response, $args)
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)) {
462 throw new HttpBadRequestException(
"Require 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)) {
477 $uploadHelper =
new UploadHelper();
479 if ($uploadType !=
"file" && (empty($reqBody) ||
480 ! array_key_exists(
"location", $reqBody))) {
481 throw new HttpBadRequestException(
482 "Require location object if uploadType != file");
484 if (empty($folderId) ||
485 !is_numeric($folderId) && $folderId > 0) {
486 throw new HttpBadRequestException(
"folderId must be a positive integer!");
489 $allFolderIds = $this->restHelper->getFolderDao()->getAllFolderIds();
490 if (!in_array($folderId, $allFolderIds)) {
491 throw new HttpNotFoundException(
"folderId $folderId does not exists!");
493 if (!$this->restHelper->getFolderDao()->isFolderAccessible($folderId)) {
494 throw new HttpForbiddenException(
"folderId $folderId is not accessible!");
497 $locationObject = [];
498 if (array_key_exists(
"location", $reqBody)) {
499 $locationObject = $reqBody[
"location"];
500 } elseif ($uploadType !=
'file') {
501 throw new HttpBadRequestException(
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];
512 throw new HttpInternalServerErrorException($message .
"\n" .
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 if (array_key_exists(
"mainLicense", $reqBody) &&
527 ! empty($reqBody[
"mainLicense"])) {
531 $mainLicense = $licenseDao
532 ->getLicenseByShortName($reqBody[
"mainLicense"]);
533 if ($mainLicense !==
null) {
535 $clearingDao =
$container->get(
'dao.clearing');
536 $clearingDao->makeMainLicense($uploadId,
537 $this->restHelper->getGroupId(), $mainLicense->getId());
540 return $response->withJson($info->getArray(), $info->getCode());
554 $id = intval($args[
'id']);
555 $query = $request->getQueryParams();
557 if ($apiVersion == ApiVersion::V2) {
558 $page = $query[
'page'] ??
"";
559 $limit = $query[
'limit'] ??
"";
561 $page = $request->getHeaderLine(
"page");
562 $limit = $request->getHeaderLine(
"limit");
564 if (! array_key_exists(self::AGENT_PARAM, $query)) {
567 $agents = explode(
",", $query[self::AGENT_PARAM]);
569 if (array_key_exists(self::CONTAINER_PARAM, $query)) {
570 $containers = (strcasecmp($query[self::CONTAINER_PARAM],
"true") === 0);
574 if (array_key_exists(
'license', $query)) {
575 $license = (strcasecmp($query[
'license'],
"true") === 0);
579 if (array_key_exists(
'copyright', $query)) {
580 $copyright = (strcasecmp($query[
'copyright'],
"true") === 0);
583 if (!$license && !$copyright) {
585 "'license' and 'copyright' atleast one should be true.");
596 if ((! ($page===
'') && (! is_numeric($page) || $page < 1)) ||
597 (! ($limit===
'') && (! is_numeric($limit) || $limit < 1))) {
599 "page and limit need to be positive integers!");
610 }
else if ($limit > 1000) {
615 list($licenseList, $count) = $uploadHelper->getUploadLicenseList($id, $agents, $containers, $license, $copyright, $page-1, $limit, $apiVersion);
616 $totalPages = intval(ceil($count / $limit));
617 return $response->withHeader(
"X-Total-Pages", $totalPages)->withJson($licenseList, 200);
631 $id = intval($args[
'id']);
635 $licenseList = $uploadHelper->getUploadCopyrightList($id);
636 return $response->withJson($licenseList, 200);
650 $id = intval($args[
'id']);
651 $query = $request->getQueryParams();
652 $userDao = $this->restHelper->getUserDao();
653 $userId = $this->restHelper->getUserId();
654 $groupId = $this->restHelper->getGroupId();
656 $perm = $userDao->isAdvisorOrAdmin($userId, $groupId);
659 "Can not update upload.");
664 $this->dbHelper->getDbManager()
672 if (array_key_exists(self::FILTER_ASSIGNEE, $query)) {
673 $assignee = filter_var($query[self::FILTER_ASSIGNEE], FILTER_VALIDATE_INT);
674 $userList = $userDao->getUserChoices($groupId);
675 if (!array_key_exists($assignee, $userList)) {
677 "New assignee does not have permisison on upload.");
679 $uploadBrowseProxy->updateTable(
"assignee", $id, $assignee);
683 array_key_exists(self::FILTER_STATUS, $query) &&
684 in_array(strtolower($query[self::FILTER_STATUS]), self::VALID_STATUS)
686 $newStatus = strtolower($query[self::FILTER_STATUS]);
688 if (in_array($newStatus, [
"closed",
"rejected"])) {
689 $body = $request->getBody();
690 $comment = $body->getContents();
694 if ($newStatus == self::VALID_STATUS[1]) {
695 $status = UploadStatus::IN_PROGRESS;
696 } elseif ($newStatus == self::VALID_STATUS[2]) {
697 $status = UploadStatus::CLOSED;
698 } elseif ($newStatus == self::VALID_STATUS[3]) {
699 $status = UploadStatus::REJECTED;
701 $status = UploadStatus::OPEN;
703 $uploadBrowseProxy->setStatusAndComment($id, $status, $comment);
706 $returnVal =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
707 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
717 $itemTreeBounds = $this->restHelper->getUploadDao()->getParentItemBounds(
719 if ($itemTreeBounds ===
false || empty($itemTreeBounds->getLeft())) {
721 "Ununpack job not started. Please check job status at " .
722 "/api/v1/jobs?upload=" . $id))
723 ->setHeaders([
'Retry-After' =>
'60',
724 'Look-at' =>
"/api/v1/jobs?upload=" . $id]);
742 $agentList = array_keys(AgentRef::AGENT_LIST);
743 $intersectArray = array_intersect($agents, $agentList);
745 if (count($agents) != count($intersectArray)) {
747 implode(
", ", $agentList) .
". " . implode(
",", $agents) .
" passed.");
750 foreach ($agents as $agent) {
751 if (!
$agentDao->arsTableExists($agent)) {
753 "Agent $agent not scheduled for the upload. " .
754 "Please POST to /jobs");
760 $agentList = $scanProxy->createAgentStatus($agents);
762 foreach ($agentList as $agent) {
763 if (! array_key_exists(
'currentAgentId', $agent)) {
765 "Agent " . $agent[
"agentName"] .
766 " not scheduled for the upload. Please POST to /jobs");
768 if (array_key_exists(
'isAgentRunning', $agent) &&
769 $agent[
'isAgentRunning']) {
771 "Agent " . $agent[
"agentName"] .
" is running. " .
772 "Please check job status at /api/v1/jobs?upload=" . $uploadId))
773 ->setHeaders([
'Retry-After' =>
'60',
774 'Look-at' =>
"/api/v1/jobs?upload=" . $uploadId]);
793 if (!$commu_status) {
799 $uploadPermissionObj =
$restHelper->getPlugin(
'upload_permissions');
801 $dbManager = $this->dbHelper->getDbManager();
805 $folder_pk = intval($reqBody[
'folderId']);
806 $upload_pk = intval($args[
'id']);
808 $allUploadsPerm = $reqBody[
'allUploadsPermission'] ? 1 : 0;
809 $newgroup = intval($reqBody[
'groupId']);
810 $newperm = $this->getEquivalentValueForPermission($reqBody[
'newPermission']);
811 $public_perm = isset($reqBody[
'publicPermission']) ? $this->getEquivalentValueForPermission($reqBody[
'publicPermission']) : -1;
813 $query =
"SELECT perm, perm_upload_pk FROM perm_upload WHERE upload_fk=$1 and group_fk=$2;";
814 $result = $dbManager->getSingleRow($query, [$upload_pk, $newgroup], __METHOD__.
".getOldPerm");
817 if (!empty($result)) {
818 $perm_upload_pk = intVal($result[
'perm_upload_pk']);
822 $uploadPermissionObj->editPermissionsForUpload($commu_status, $folder_pk, $upload_pk, $allUploadsPerm, $perm_upload_pk, $perm, $newgroup, $newperm, $public_perm);
824 $returnVal =
new Info(202,
"Permissions updated successfully!", InfoType::INFO);
825 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
828 public function getEquivalentValueForPermission($perm)
835 case 'clearing_admin':
836 return Auth::PERM_CADMIN;
856 $upload_pk = intval($args[
'id']);
858 $publicPerm = $this->restHelper->getUploadPermissionDao()->getPublicPermission($upload_pk);
859 $permGroups = $this->restHelper->getUploadPermissionDao()->getPermissionGroups($upload_pk);
862 $finalPermGroups = [];
863 foreach ($permGroups as $value) {
864 $groupPerm =
new GroupPermission($value[
'perm'], $value[
'group_pk'], $value[
'group_name']);
865 $finalPermGroups[] = $groupPerm->getArray($apiVersion);
867 $res =
new Permissions($publicPerm, $finalPermGroups);
868 return $response->withJson($res->getArray($apiVersion), 200);
880 public function getMainLicenses($request, $response, $args)
882 $uploadId = intval($args[
'id']);
886 $clearingDao = $this->container->get(
'dao.clearing');
887 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
888 $licenseDao = $this->container->get(
'dao.license');
891 foreach ($licenseIds as $value) {
892 $licenseId = intval($value);
893 $obligations = $licenseDao->getLicenseObligations([$licenseId],
895 $obligations = array_merge($obligations,
896 $licenseDao->getLicenseObligations([$licenseId],
true));
897 $obligationList = [];
898 foreach ($obligations as $obligation) {
900 $obligation[
'ob_pk'],
901 $obligation[
'ob_topic'],
902 $obligation[
'ob_type'],
903 $obligation[
'ob_text'],
904 $obligation[
'ob_classification'],
905 $obligation[
'ob_comment']
908 $license = $licenseDao->getLicenseById($licenseId);
911 $license->getShortName(),
912 $license->getFullName(),
918 $licenses[] = $licenseObj->getArray();
920 return $response->withJson($licenses, 200);
932 public function setMainLicense($request, $response, $args)
934 $uploadId = intval($args[
'id']);
936 $shortName = $body[
'shortName'];
937 $licenseDao = $this->container->get(
'dao.license');
938 $clearingDao = $this->container->get(
'dao.clearing');
942 if (empty($shortName)) {
943 throw new HttpBadRequestException(
"Short name missing from request.");
945 $license = $licenseDao->getLicenseByShortName($shortName,
946 $this->restHelper->getGroupId());
948 if ($license ===
null) {
949 throw new HttpNotFoundException(
950 "No license with shortname '$shortName' found.");
953 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
954 if (in_array($license->getId(), $licenseIds)) {
955 throw new HttpBadRequestException(
956 "License already exists for this upload.");
960 $clearingDao = $this->container->get(
'dao.clearing');
961 $clearingDao->makeMainLicense($uploadId, $this->restHelper->getGroupId(), $license->getId());
962 $returnVal =
new Info(200,
"Successfully added new main license", InfoType::INFO);
963 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
975 public function removeMainLicense($request, $response, $args)
977 $uploadId = intval($args[
'id']);
978 $shortName = $args[
'shortName'];
979 $licenseDao = $this->container->get(
'dao.license');
980 $clearingDao = $this->container->get(
'dao.clearing');
981 $license = $licenseDao->getLicenseByShortName($shortName, $this->restHelper->getGroupId());
985 if ($license ===
null) {
986 throw new HttpNotFoundException(
987 "No license with shortname '$shortName' found.");
989 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
990 if (!in_array($license->getId(), $licenseIds)) {
991 throw new HttpBadRequestException(
992 "License '$shortName' is not a main license for this upload.");
995 $clearingDao = $this->container->get(
'dao.clearing');
996 $clearingDao->removeMainLicense($uploadId, $this->restHelper->getGroupId(), $license->getId());
997 $returnVal =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
999 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1013 $uploadId = intval($args[
'id']);
1014 $uploadDao = $this->restHelper->getUploadDao();
1018 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1021 array(UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
1022 UploadTreeProxy::OPT_GROUP_ID => $this->restHelper->getGroupId()),
1023 $uploadTreeTableName,
1024 'no_license_uploadtree' . $uploadId);
1026 $filesOfInterest = $noLicenseUploadTreeView->count();
1029 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
1030 UploadTreeProxy::OPT_GROUP_ID => $this->restHelper->getGroupId()),
1031 $uploadTreeTableName,
1032 'already_cleared_uploadtree' . $uploadId);
1033 $filesToBeCleared = $nonClearedUploadTreeView->count();
1035 $filesAlreadyCleared = $filesOfInterest - $filesToBeCleared;
1038 "totalFilesOfInterest" => intval($filesOfInterest),
1039 "totalFilesCleared" => intval($filesAlreadyCleared),
1041 return $response->withJson($res, 200);
1055 $agentDao = $this->container->get(
'dao.agent');
1056 $clearingDao = $this->container->get(
'dao.clearing');
1057 $licenseDao = $this->container->get(
'dao.license');
1059 $uploadId = intval($args[
'id']);
1060 $uploadDao = $this->restHelper->getUploadDao();
1061 $query = $request->getQueryParams();
1062 $selectedAgentId = $query[
'agentId'] ??
null;
1066 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
1070 $scannerAgents = array_keys($this->agentNames);
1072 $scanJobProxy->createAgentStatus($scannerAgents);
1073 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1074 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1075 $editedLicenses = $clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $this->restHelper->getGroupId());
1076 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
1077 $scannedLicenses = $licenseDao->getLicenseHistogram($itemTreeBounds, $selectedAgentIds);
1078 $allScannerLicenseNames = array_keys($scannedLicenses);
1079 $allEditedLicenseNames = array_keys($editedLicenses);
1080 $allLicNames = array_unique(array_merge($allScannerLicenseNames, $allEditedLicenseNames));
1081 $realLicNames = array_diff($allLicNames, array(LicenseDao::NO_LICENSE_FOUND));
1082 $totalScannerLicenseCount = 0;
1083 $editedTotalLicenseCount = 0;
1086 foreach ($realLicNames as $licenseShortName) {
1088 if (array_key_exists($licenseShortName, $scannedLicenses)) {
1089 $count = $scannedLicenses[$licenseShortName][
'unique'];
1090 $rfId = $scannedLicenses[$licenseShortName][
'rf_pk'];
1092 $rfId = $editedLicenses[$licenseShortName][
'rf_pk'];
1094 $editedCount = array_key_exists($licenseShortName, $editedLicenses) ? $editedLicenses[$licenseShortName][
'count'] : 0;
1095 $totalScannerLicenseCount += $count;
1096 $editedTotalLicenseCount += $editedCount;
1097 $scannerCountLink = $count;
1098 $editedLink = $editedCount;
1100 $res[] = array($scannerCountLink, $editedLink, array($licenseShortName, $rfId));
1105 foreach ($res as $item) {
1107 "id" => intval($item[2][1]),
1108 "name" => $item[2][0],
1109 "scannerCount" => intval($item[0]),
1110 "concludedCount" => intval($item[1]),
1113 return $response->withJson($outputArray, 200);
1127 $uploadId = intval($args[
'id']);
1131 $scannerAgents = array_keys($this->agentNames);
1132 $agentDao = $this->container->get(
'dao.agent');
1134 $res = $scanJobProxy->createAgentStatus($scannerAgents);
1137 foreach ($res as &$item) {
1138 $successfulAgents = [];
1139 if (count($item[
'successfulAgents']) > 0) {
1140 $item[
'isAgentRunning'] =
false;
1142 $item[
'currentAgentId'] =
$agentDao->getCurrentAgentRef($item[
"agentName"])->getAgentId();
1143 $item[
'currentAgentRev'] =
"";
1145 foreach ($item[
'successfulAgents'] as &$agent) {
1146 $successfulAgent =
new SuccessfulAgent(intval($agent[
'agent_id']), $agent[
'agent_rev'], $agent[
'agent_name']);
1149 $agent =
new Agent($successfulAgents, $item[
'uploadId'], $item[
'agentName'], $item[
'currentAgentId'], $item[
'currentAgentRev'], $item[
'isAgentRunning']);
1152 return $response->withJson($outputArray, 200);
1166 $uploadId = intval($args[
'id']);
1170 $clearingDao = $this->container->get(
'dao.clearing');
1171 $uploadDao = $this->restHelper->getUploadDao();
1172 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1173 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1174 $res = $clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $this->restHelper->getGroupId());
1177 foreach ($res as $key => $value) {
1178 $editedLicense =
new EditedLicense(intval($value[
"rf_pk"]), $key, intval($value[
"count"]), $value[
"spdx_id"]);
1181 return $response->withJson($outputArray, 200);
1193 public function getReuseReportSummary($request, $response, $args)
1195 $uploadId = intval($args[
'id']);
1199 $reuseReportProcess = $this->container->get(
'businessrules.reusereportprocessor');
1200 $res = $reuseReportProcess->getReuseSummary($uploadId);
1201 return $response->withJson($res, 200);
1215 $uploadId = intval($args[
'id']);
1216 $query = $request->getQueryParams();
1217 $selectedAgentId = $query[
'agentId'] ??
null;
1218 $licenseDao = $this->container->get(
'dao.license');
1221 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
1224 $scannerAgents = array_keys(AgentRef::AGENT_LIST);
1225 $scanJobProxy =
new ScanJobProxy($this->agentDao, $uploadId);
1226 $scanJobProxy->createAgentStatus($scannerAgents);
1227 $uploadDao = $this->restHelper->getUploadDao();
1228 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1229 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1230 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
1231 $res = $licenseDao->getLicenseHistogram($itemTreeBounds, $selectedAgentIds);
1234 foreach ($res as $key => $value) {
1235 $scannedLicense =
new ScannedLicense($licenseDao->getLicenseByShortName($key)->getId(), $key, $value[
'count'], $value[
'unique'], $value[
'spdx_id']);
1238 return $response->withJson($outputArray, 200);
1251 $agentDao = $this->container->get(
'dao.agent');
1252 $uploadId = intval($args[
'id']);
1256 $scannerAgents = array_keys($this->agentNames);
1258 $scanJobProxy->createAgentStatus($scannerAgents);
1261 foreach ($scanJobProxy->getSuccessfulAgents() as $agent) {
1263 "id" => $agent->getAgentId(),
1264 "name" => $agent->getAgentName(),
1265 "revision" => $agent->getAgentRevision(),
1268 return $response->withJson($res, 200);
1282 $uploadId = intval($args[
'id']);
1283 if (!$this->dbHelper->doesIdExist(
"upload",
"upload_pk", $uploadId)) {
1284 $returnVal =
new Info(404,
"Upload does not exist", InfoType::ERROR);
1285 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1287 $uploadDao = $this->restHelper->getUploadDao();
1288 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
1289 $uploadDao->getUploadtreeTableName($uploadId));
1290 if ($itemTreeBounds ===
false) {
1291 $error =
new Info(500,
"Unable to get top item.", InfoType::ERROR);
1292 return $response->withJson($error->getArray(), $error->getCode());
1294 $info =
new Info(200, $itemTreeBounds->getItemId(), InfoType::INFO);
1295 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)
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.