17 namespace Fossology\UI\Api\Controllers;
51 use Psr\Http\Message\ServerRequestInterface;
52 use Slim\Psr7\Factory\StreamFactory;
135 $groupId = $this->restHelper->getGroupId();
136 $dbManager = $this->dbHelper->getDbManager();
137 $this->agentDao = $this->container->get(
'dao.agent');
139 $uploadBrowseProxy->sanity();
156 $query = $request->getQueryParams();
163 if (array_key_exists(self::FOLDER_PARAM, $query)) {
164 $folderId = filter_var($query[self::FOLDER_PARAM], FILTER_VALIDATE_INT);
165 if (! $this->restHelper->getFolderDao()->isFolderAccessible($folderId,
166 $this->restHelper->getUserId())) {
171 if (array_key_exists(self::RECURSIVE_PARAM, $query)) {
172 $recursive = filter_var($query[self::RECURSIVE_PARAM],
173 FILTER_VALIDATE_BOOLEAN);
175 if (array_key_exists(self::FILTER_NAME, $query)) {
178 if (array_key_exists(self::FILTER_STATUS, $query)) {
179 switch (strtolower($query[self::FILTER_STATUS])) {
181 $status = UploadStatus::OPEN;
184 $status = UploadStatus::IN_PROGRESS;
187 $status = UploadStatus::CLOSED;
190 $status = UploadStatus::REJECTED;
196 if (array_key_exists(self::FILTER_ASSIGNEE, $query)) {
198 if (strcasecmp($username,
"-me-") === 0) {
199 $assignee = $this->restHelper->getUserId();
200 } elseif (strcasecmp($username,
"-unassigned-") === 0) {
203 $assignee = $this->restHelper->getUserDao()->getUserByName($username);
204 if (empty($assignee)) {
207 $assignee = $assignee[
'user_pk'];
210 if (array_key_exists(self::FILTER_DATE, $query)) {
211 $date = filter_var($query[self::FILTER_DATE], FILTER_VALIDATE_REGEXP,
213 "regexp" =>
"/^\d{4}\-\d{2}\-\d{2}$/",
214 "flags" => FILTER_NULL_ON_FAILURE
216 $since = strtotime($date);
218 if ($apiVersion == ApiVersion::V2) {
222 $page = $request->getHeaderLine(self::PAGE_PARAM);
223 $limit = $request->getHeaderLine(self::LIMIT_PARAM);
225 if (! empty($page) || $page ==
"0") {
226 $page = filter_var($page, FILTER_VALIDATE_INT);
229 "page should be positive integer > 0");
234 if (! empty($limit)) {
235 $limit = filter_var($limit, FILTER_VALIDATE_INT);
238 "limit should be positive integer > 1");
244 if (isset($args[
'id'])) {
245 $id = intval($args[
'id']);
250 "folderId" => $folderId,
253 "assignee" => $assignee,
256 list($pages, $uploads) = $this->dbHelper->getUploads(
257 $this->restHelper->getUserId(), $this->restHelper->getGroupId(), $limit,
258 $page, $id, $options, $recursive, $apiVersion);
259 if ($id !==
null && ! empty($uploads)) {
260 $uploads = $uploads[0];
263 return $response->withHeader(
"X-Total-Pages", $pages)->withJson($uploads,
276 public function uploadDownload($request, $response, $args)
279 $ui_download = $this->restHelper->getPlugin(
'download');
282 if (isset($args[
'id'])) {
283 $id = intval($args[
'id']);
286 $dbManager = $this->restHelper->getDbHelper()->getDbManager();
287 $uploadDao = $this->restHelper->getUploadDao();
288 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($id);
289 $itemTreeBounds = $uploadDao->getParentItemBounds($id,$uploadTreeTableName);
290 $sql =
"SELECT pfile_fk , ufile_name FROM uploadtree_a WHERE uploadtree_pk=$1";
291 $params = array($itemTreeBounds->getItemId());
292 $descendants = $dbManager->getSingleRow($sql,$params);
293 $path=
RepPath(($descendants[
'pfile_fk']));
294 $responseFile = $ui_download->getDownload($path, $descendants[
'ufile_name']);
295 $responseContent = $responseFile->getFile();
296 $newResponse = $response->withHeader(
'Content-Description',
298 ->withHeader(
'Content-Type',
299 $responseContent->getMimeType())
300 ->withHeader(
'Content-Disposition',
301 $responseFile->headers->get(
'Content-Disposition'))
302 ->withHeader(
'Cache-Control',
'must-revalidate')
303 ->withHeader(
'Pragma',
'private')
304 ->withHeader(
'Content-Length', filesize($responseContent->getPathname()));
305 $sf =
new StreamFactory();
306 return $newResponse->withBody(
307 $sf->createStreamFromFile($responseContent->getPathname())
322 $id = intval($args[
'id']);
323 $query = $request->getQueryParams();
324 $selectedAgentId = $query[
'agentId'] ??
null;
325 $agentDao = $this->container->get(
'dao.agent');
327 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
332 $uploadSummary = $uploadHelper->generateUploadSummary($id, $this->restHelper->getGroupId());
333 $browseLicense = $this->restHelper->getPlugin(
'license');
334 $uploadDao = $this->restHelper->getUploadDao();
335 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($id);
336 $itemTreeBounds = $uploadDao->getParentItemBounds($id, $uploadTreeTableName);
338 $scannerAgents = array_keys(AgentRef::AGENT_LIST);
339 $scanJobProxy->createAgentStatus($scannerAgents);
340 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
341 $res = $browseLicense->createLicenseHistogram(
"",
"", $itemTreeBounds, $selectedAgentIds, $this->restHelper->getGroupId());
342 $uploadSummary->setUniqueConcludedLicenses($res[
'editedUniqueLicenseCount']);
343 $uploadSummary->setTotalConcludedLicenses($res[
'editedLicenseCount']);
344 $uploadSummary->setTotalLicenses($res[
'scannerLicenseCount']);
345 $uploadSummary->setUniqueLicenses($res[
'uniqueLicenseCount']);
346 $uploadSummary->setConcludedNoLicenseFoundCount($res[
'editedNoLicenseFoundCount']);
347 $uploadSummary->setFileCount($res[
'fileCount']);
348 $uploadSummary->setNoScannerLicenseFoundCount($res[
'noScannerLicenseFoundCount']);
349 $uploadSummary->setScannerUniqueLicenseCount($res[
'scannerUniqueLicenseCount']);
351 return $response->withJson($uploadSummary->getArray(), 200);
365 require_once dirname(__DIR__, 4) .
"/delagent/ui/delete-helper.php";
366 $id = intval($args[
'id']);
369 $result = TryToDelete($id, $this->restHelper->getUserId(),
370 $this->restHelper->getGroupId(), $this->restHelper->getUploadDao());
373 $result->getDeleteMessageString());
375 $returnVal =
new Info(202,
"Delete Job for file with id " . $id,
377 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
391 $queryParams = $request->getQueryParams();
392 $action = $queryParams[
'action'] ??
"";
394 $action = $request->getHeaderLine(
'action');
396 if (strtolower($action) ==
"move") {
401 return $this->
changeUpload($request, $response, $args, $copy);
416 $queryParams = $request->getQueryParams();
418 $paramType = ($isApiVersionV2) ?
'parameter' :
'header';
420 if ((!$isApiVersionV2 && !$request->hasHeader(
'folderId') || $isApiVersionV2 && !isset($queryParams[
'folderId']))
421 || !is_numeric($newFolderID = ($isApiVersionV2 ? $queryParams[
'folderId'] : $request->getHeaderLine(
'folderId')))) {
422 throw new HttpBadRequestException(
"For API version " . ($isApiVersionV2 ?
'V2' :
'V1') .
", 'folderId' $paramType should be present and an integer.");
425 $id = intval($args[
'id']);
426 $returnVal = $this->restHelper->copyUpload($id, $newFolderID, $isCopy);
427 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
439 public function postUpload($request, $response, $args)
443 $uploadType = $reqBody[
'uploadType'] ??
null;
444 $folderId = $reqBody[
'folderId'] ??
null;
445 $description = $reqBody[
'uploadDescription'] ??
"";
446 $public = $reqBody[
'public'] ??
null;
447 $applyGlobal = filter_var($reqBody[
'applyGlobal'] ??
null,
448 FILTER_VALIDATE_BOOLEAN);
449 $ignoreScm = $reqBody[
'ignoreScm'] ??
null;
450 $excludefolder = $reqBody[
'excludefolder'] ??
false;
452 $uploadType = $request->getHeaderLine(
'uploadType');
453 $folderId = $request->getHeaderLine(
'folderId');
454 $description = $request->getHeaderLine(
'uploadDescription');
455 $public = $request->getHeaderLine(
'public');
456 $applyGlobal = filter_var($request->getHeaderLine(
'applyGlobal'),
457 FILTER_VALIDATE_BOOLEAN);
458 $ignoreScm = $request->getHeaderLine(
'ignoreScm');
461 $public = empty($public) ?
'protected' : $public;
463 if (empty($uploadType)) {
464 throw new HttpBadRequestException(
"Require uploadType");
467 if (array_key_exists(
'scanOptions', $reqBody)) {
468 if ($uploadType ==
'file') {
469 $scanOptions = json_decode($reqBody[
'scanOptions'],
true);
471 $scanOptions = $reqBody[
'scanOptions'];
475 if (! is_array($scanOptions)) {
479 $uploadHelper =
new UploadHelper();
481 if ($uploadType !=
"file" && (empty($reqBody) ||
482 ! array_key_exists(
"location", $reqBody))) {
483 throw new HttpBadRequestException(
484 "Require location object if uploadType != file");
486 if (empty($folderId) ||
487 !is_numeric($folderId) && $folderId > 0) {
488 throw new HttpBadRequestException(
"folderId must be a positive integer!");
491 $allFolderIds = $this->restHelper->getFolderDao()->getAllFolderIds();
492 if (!in_array($folderId, $allFolderIds)) {
493 throw new HttpNotFoundException(
"folderId $folderId does not exists!");
495 if (!$this->restHelper->getFolderDao()->isFolderAccessible($folderId)) {
496 throw new HttpForbiddenException(
"folderId $folderId is not accessible!");
499 $locationObject = [];
500 if (array_key_exists(
"location", $reqBody)) {
501 $locationObject = $reqBody[
"location"];
502 } elseif ($uploadType !=
'file') {
503 throw new HttpBadRequestException(
504 "Require location object if uploadType != file");
508 $uploadResponse = $uploadHelper->createNewUpload($locationObject,
509 $folderId, $description, $public, $ignoreScm, $uploadType,
510 $applyGlobal, $excludefolder);
512 $uploadResponse = $uploadHelper->createNewUpload($locationObject,
513 $folderId, $description, $public, $ignoreScm, $uploadType,
516 $status = $uploadResponse[0];
517 $message = $uploadResponse[1];
518 $statusDescription = $uploadResponse[2];
520 throw new HttpInternalServerErrorException($message .
"\n" .
524 $uploadId = $uploadResponse[3];
525 if (! empty($scanOptions)) {
526 $info = $uploadHelper->handleScheduleAnalysis(intval($uploadId),
527 intval($folderId), $scanOptions,
true);
528 if ($info->getCode() == 201) {
529 $info =
new Info($info->getCode(), intval($uploadId), $info->getType());
532 $info =
new Info(201, intval($uploadId), InfoType::INFO);
534 if (array_key_exists(
"mainLicense", $reqBody) &&
535 ! empty($reqBody[
"mainLicense"])) {
539 $mainLicense = $licenseDao
540 ->getLicenseByShortName($reqBody[
"mainLicense"]);
541 if ($mainLicense !==
null) {
543 $clearingDao =
$container->get(
'dao.clearing');
544 $clearingDao->makeMainLicense($uploadId,
545 $this->restHelper->getGroupId(), $mainLicense->getId());
548 return $response->withJson($info->getArray(), $info->getCode());
562 $id = intval($args[
'id']);
563 $query = $request->getQueryParams();
565 if ($apiVersion == ApiVersion::V2) {
566 $page = $query[
'page'] ??
"";
567 $limit = $query[
'limit'] ??
"";
569 $page = $request->getHeaderLine(
"page");
570 $limit = $request->getHeaderLine(
"limit");
572 if (! array_key_exists(self::AGENT_PARAM, $query)) {
575 $agents = explode(
",", $query[self::AGENT_PARAM]);
577 if (array_key_exists(self::CONTAINER_PARAM, $query)) {
578 $containers = (strcasecmp($query[self::CONTAINER_PARAM],
"true") === 0);
582 if (array_key_exists(
'license', $query)) {
583 $license = (strcasecmp($query[
'license'],
"true") === 0);
587 if (array_key_exists(
'copyright', $query)) {
588 $copyright = (strcasecmp($query[
'copyright'],
"true") === 0);
591 if (!$license && !$copyright) {
593 "'license' and 'copyright' atleast one should be true.");
604 if ((! ($page===
'') && (! is_numeric($page) || $page < 1)) ||
605 (! ($limit===
'') && (! is_numeric($limit) || $limit < 1))) {
607 "page and limit need to be positive integers!");
618 }
else if ($limit > 1000) {
623 list($licenseList, $count) = $uploadHelper->getUploadLicenseList($id, $agents, $containers, $license, $copyright, $page-1, $limit, $apiVersion);
624 $totalPages = intval(ceil($count / $limit));
625 return $response->withHeader(
"X-Total-Pages", $totalPages)->withJson($licenseList, 200);
639 $id = intval($args[
'id']);
643 $licenseList = $uploadHelper->getUploadCopyrightList($id);
644 return $response->withJson($licenseList, 200);
656 public function updateUpload($request, $response, $args)
658 $id = intval($args[
'id']);
659 $query = $request->getQueryParams();
660 $userDao = $this->restHelper->getUserDao();
661 $userId = $this->restHelper->getUserId();
662 $groupId = $this->restHelper->getGroupId();
665 $perm = $userDao->isAdvisorOrAdmin($userId, $groupId);
668 "Can not update upload.");
670 $uploadBrowseProxy =
new UploadBrowseProxy(
673 $this->dbHelper->getDbManager()
680 $newDescription =
null;
682 if ($isJsonRequest) {
685 $body = $request->getBody();
686 $bodyContent = $body->getContents();
691 if (array_key_exists(self::FILTER_ASSIGNEE, $query)) {
692 $assignee = filter_var($query[self::FILTER_ASSIGNEE], FILTER_VALIDATE_INT);
693 $userList = $userDao->getUserChoices($groupId);
694 if (!array_key_exists($assignee, $userList)) {
695 throw new HttpNotFoundException(
696 "New assignee does not have permission on upload.");
698 $uploadBrowseProxy->updateTable(
"assignee", $id, $assignee);
702 array_key_exists(self::FILTER_STATUS, $query) &&
703 in_array(strtolower($query[self::FILTER_STATUS]), self::VALID_STATUS)
705 $newStatus = strtolower($query[self::FILTER_STATUS]);
707 if (in_array($newStatus, [
"closed",
"rejected"])) {
708 if ($isJsonRequest && array_key_exists(
"comment", $bodyContent)) {
709 $comment = $bodyContent[
"comment"];
711 $comment = $bodyContent;
715 if ($newStatus == self::VALID_STATUS[1]) {
716 $status = UploadStatus::IN_PROGRESS;
717 } elseif ($newStatus == self::VALID_STATUS[2]) {
718 $status = UploadStatus::CLOSED;
719 } elseif ($newStatus == self::VALID_STATUS[3]) {
720 $status = UploadStatus::REJECTED;
722 $status = UploadStatus::OPEN;
724 $uploadBrowseProxy->setStatusAndComment($id, $status, $comment);
729 array_key_exists(self::FILTER_NAME, $bodyContent) &&
730 strlen(
trim($bodyContent[self::FILTER_NAME])) > 0
732 $newName =
trim($bodyContent[self::FILTER_NAME]);
737 array_key_exists(
"uploadDescription", $bodyContent) &&
738 strlen(
trim($bodyContent[
"uploadDescription"])) > 0
740 $newDescription =
trim($bodyContent[
"uploadDescription"]);
742 if ($newName !=
null || $newDescription !=
null) {
744 $uploadProperties = $this->restHelper->getPlugin(
'upload_properties');
745 $updated = $uploadProperties->UpdateUploadProperties($id, $newName, $newDescription);
747 throw new HttpBadRequestException(
"Invalid request to update upload name and description.");
751 $returnVal =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
752 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
762 $itemTreeBounds = $this->restHelper->getUploadDao()->getParentItemBounds(
764 if ($itemTreeBounds ===
false || empty($itemTreeBounds->getLeft())) {
766 "Ununpack job not started. Please check job status at " .
767 "/api/v1/jobs?upload=" . $id))
768 ->setHeaders([
'Retry-After' =>
'60',
769 'Look-at' =>
"/api/v1/jobs?upload=" . $id]);
787 $agentList = array_keys(AgentRef::AGENT_LIST);
788 $intersectArray = array_intersect($agents, $agentList);
790 if (count($agents) != count($intersectArray)) {
792 implode(
", ", $agentList) .
". " . implode(
",", $agents) .
" passed.");
795 foreach ($agents as $agent) {
796 if (!
$agentDao->arsTableExists($agent)) {
798 "Agent $agent not scheduled for the upload. " .
799 "Please POST to /jobs");
805 $agentList = $scanProxy->createAgentStatus($agents);
807 foreach ($agentList as $agent) {
808 if (! array_key_exists(
'currentAgentId', $agent)) {
810 "Agent " . $agent[
"agentName"] .
811 " not scheduled for the upload. Please POST to /jobs");
813 if (array_key_exists(
'isAgentRunning', $agent) &&
814 $agent[
'isAgentRunning']) {
816 "Agent " . $agent[
"agentName"] .
" is running. " .
817 "Please check job status at /api/v1/jobs?upload=" . $uploadId))
818 ->setHeaders([
'Retry-After' =>
'60',
819 'Look-at' =>
"/api/v1/jobs?upload=" . $uploadId]);
838 if (!$commu_status) {
844 $uploadPermissionObj =
$restHelper->getPlugin(
'upload_permissions');
846 $dbManager = $this->dbHelper->getDbManager();
850 $folder_pk = intval($reqBody[
'folderId']);
851 $upload_pk = intval($args[
'id']);
853 $allUploadsPerm = $reqBody[
'allUploadsPermission'] ? 1 : 0;
854 $newgroup = intval($reqBody[
'groupId']);
855 $newperm = $this->getEquivalentValueForPermission($reqBody[
'newPermission']);
856 $public_perm = isset($reqBody[
'publicPermission']) ? $this->getEquivalentValueForPermission($reqBody[
'publicPermission']) : -1;
858 $query =
"SELECT perm, perm_upload_pk FROM perm_upload WHERE upload_fk=$1 and group_fk=$2;";
859 $result = $dbManager->getSingleRow($query, [$upload_pk, $newgroup], __METHOD__.
".getOldPerm");
862 if (!empty($result)) {
863 $perm_upload_pk = intVal($result[
'perm_upload_pk']);
867 $uploadPermissionObj->editPermissionsForUpload($commu_status, $folder_pk, $upload_pk, $allUploadsPerm, $perm_upload_pk, $perm, $newgroup, $newperm, $public_perm);
869 $returnVal =
new Info(202,
"Permissions updated successfully!", InfoType::INFO);
870 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
873 public function getEquivalentValueForPermission($perm)
880 case 'clearing_admin':
881 return Auth::PERM_CADMIN;
901 $upload_pk = intval($args[
'id']);
903 $publicPerm = $this->restHelper->getUploadPermissionDao()->getPublicPermission($upload_pk);
904 $permGroups = $this->restHelper->getUploadPermissionDao()->getPermissionGroups($upload_pk);
907 $finalPermGroups = [];
908 foreach ($permGroups as $value) {
909 $groupPerm =
new GroupPermission($value[
'perm'], $value[
'group_pk'], $value[
'group_name']);
910 $finalPermGroups[] = $groupPerm->getArray($apiVersion);
912 $res =
new Permissions($publicPerm, $finalPermGroups);
913 return $response->withJson($res->getArray($apiVersion), 200);
925 public function getMainLicenses($request, $response, $args)
927 $uploadId = intval($args[
'id']);
931 $clearingDao = $this->container->get(
'dao.clearing');
932 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
933 $licenseDao = $this->container->get(
'dao.license');
936 foreach ($licenseIds as $value) {
937 $licenseId = intval($value);
938 $obligations = $licenseDao->getLicenseObligations([$licenseId],
940 $obligations = array_merge($obligations,
941 $licenseDao->getLicenseObligations([$licenseId],
true));
942 $obligationList = [];
943 foreach ($obligations as $obligation) {
945 $obligation[
'ob_pk'],
946 $obligation[
'ob_topic'],
947 $obligation[
'ob_type'],
948 $obligation[
'ob_text'],
949 $obligation[
'ob_classification'],
950 $obligation[
'ob_comment']
953 $license = $licenseDao->getLicenseById($licenseId);
956 $license->getShortName(),
957 $license->getFullName(),
963 $licenses[] = $licenseObj->getArray();
965 return $response->withJson($licenses, 200);
977 public function setMainLicense($request, $response, $args)
979 $uploadId = intval($args[
'id']);
981 $shortName = $body[
'shortName'];
982 $licenseDao = $this->container->get(
'dao.license');
983 $clearingDao = $this->container->get(
'dao.clearing');
987 if (empty($shortName)) {
988 throw new HttpBadRequestException(
"Short name missing from request.");
990 $license = $licenseDao->getLicenseByShortName($shortName,
991 $this->restHelper->getGroupId());
993 if ($license ===
null) {
994 throw new HttpNotFoundException(
995 "No license with shortname '$shortName' found.");
998 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
999 if (in_array($license->getId(), $licenseIds)) {
1000 throw new HttpBadRequestException(
1001 "License already exists for this upload.");
1005 $clearingDao = $this->container->get(
'dao.clearing');
1006 $clearingDao->makeMainLicense($uploadId, $this->restHelper->getGroupId(), $license->getId());
1007 $returnVal =
new Info(200,
"Successfully added new main license", InfoType::INFO);
1008 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1020 public function removeMainLicense($request, $response, $args)
1022 $uploadId = intval($args[
'id']);
1023 $shortName = $args[
'shortName'];
1024 $licenseDao = $this->container->get(
'dao.license');
1025 $clearingDao = $this->container->get(
'dao.clearing');
1026 $license = $licenseDao->getLicenseByShortName($shortName, $this->restHelper->getGroupId());
1030 if ($license ===
null) {
1031 throw new HttpNotFoundException(
1032 "No license with shortname '$shortName' found.");
1034 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
1035 if (!in_array($license->getId(), $licenseIds)) {
1036 throw new HttpBadRequestException(
1037 "License '$shortName' is not a main license for this upload.");
1040 $clearingDao = $this->container->get(
'dao.clearing');
1041 $clearingDao->removeMainLicense($uploadId, $this->restHelper->getGroupId(), $license->getId());
1042 $returnVal =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
1044 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1058 $uploadId = intval($args[
'id']);
1059 $uploadDao = $this->restHelper->getUploadDao();
1063 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1066 array(UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
1067 UploadTreeProxy::OPT_GROUP_ID => $this->restHelper->getGroupId()),
1068 $uploadTreeTableName,
1069 'no_license_uploadtree' . $uploadId);
1071 $filesOfInterest = $noLicenseUploadTreeView->count();
1074 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
1075 UploadTreeProxy::OPT_GROUP_ID => $this->restHelper->getGroupId()),
1076 $uploadTreeTableName,
1077 'already_cleared_uploadtree' . $uploadId);
1078 $filesToBeCleared = $nonClearedUploadTreeView->count();
1080 $filesAlreadyCleared = $filesOfInterest - $filesToBeCleared;
1083 "totalFilesOfInterest" => intval($filesOfInterest),
1084 "totalFilesCleared" => intval($filesAlreadyCleared),
1086 return $response->withJson($res, 200);
1100 $agentDao = $this->container->get(
'dao.agent');
1101 $clearingDao = $this->container->get(
'dao.clearing');
1102 $licenseDao = $this->container->get(
'dao.license');
1104 $uploadId = intval($args[
'id']);
1105 $uploadDao = $this->restHelper->getUploadDao();
1106 $query = $request->getQueryParams();
1107 $selectedAgentId = $query[
'agentId'] ??
null;
1111 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
1115 $scannerAgents = array_keys($this->agentNames);
1117 $scanJobProxy->createAgentStatus($scannerAgents);
1118 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1119 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1120 $editedLicenses = $clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $this->restHelper->getGroupId());
1121 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
1122 $scannedLicenses = $licenseDao->getLicenseHistogram($itemTreeBounds, $selectedAgentIds);
1123 $allScannerLicenseNames = array_keys($scannedLicenses);
1124 $allEditedLicenseNames = array_keys($editedLicenses);
1125 $allLicNames = array_unique(array_merge($allScannerLicenseNames, $allEditedLicenseNames));
1126 $realLicNames = array_diff($allLicNames, array(LicenseDao::NO_LICENSE_FOUND));
1127 $totalScannerLicenseCount = 0;
1128 $editedTotalLicenseCount = 0;
1131 foreach ($realLicNames as $licenseShortName) {
1133 if (array_key_exists($licenseShortName, $scannedLicenses)) {
1134 $count = $scannedLicenses[$licenseShortName][
'unique'];
1135 $rfId = $scannedLicenses[$licenseShortName][
'rf_pk'];
1137 $rfId = $editedLicenses[$licenseShortName][
'rf_pk'];
1139 $editedCount = array_key_exists($licenseShortName, $editedLicenses) ? $editedLicenses[$licenseShortName][
'count'] : 0;
1140 $totalScannerLicenseCount += $count;
1141 $editedTotalLicenseCount += $editedCount;
1142 $scannerCountLink = $count;
1143 $editedLink = $editedCount;
1145 $res[] = array($scannerCountLink, $editedLink, array($licenseShortName, $rfId));
1150 foreach ($res as $item) {
1152 "id" => intval($item[2][1]),
1153 "name" => $item[2][0],
1154 "scannerCount" => intval($item[0]),
1155 "concludedCount" => intval($item[1]),
1158 return $response->withJson($outputArray, 200);
1172 $uploadId = intval($args[
'id']);
1176 $scannerAgents = array_keys($this->agentNames);
1177 $agentDao = $this->container->get(
'dao.agent');
1179 $res = $scanJobProxy->createAgentStatus($scannerAgents);
1182 foreach ($res as &$item) {
1183 $successfulAgents = [];
1184 if (count($item[
'successfulAgents']) > 0) {
1185 $item[
'isAgentRunning'] =
false;
1187 $item[
'currentAgentId'] =
$agentDao->getCurrentAgentRef($item[
"agentName"])->getAgentId();
1188 $item[
'currentAgentRev'] =
"";
1190 foreach ($item[
'successfulAgents'] as &$agent) {
1191 $successfulAgent =
new SuccessfulAgent(intval($agent[
'agent_id']), $agent[
'agent_rev'], $agent[
'agent_name']);
1194 $agent =
new Agent($successfulAgents, $item[
'uploadId'], $item[
'agentName'], $item[
'currentAgentId'], $item[
'currentAgentRev'], $item[
'isAgentRunning']);
1197 return $response->withJson($outputArray, 200);
1211 $uploadId = intval($args[
'id']);
1215 $clearingDao = $this->container->get(
'dao.clearing');
1216 $uploadDao = $this->restHelper->getUploadDao();
1217 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1218 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1219 $res = $clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $this->restHelper->getGroupId());
1222 foreach ($res as $key => $value) {
1223 $editedLicense =
new EditedLicense(intval($value[
"rf_pk"]), $key, intval($value[
"count"]), $value[
"spdx_id"]);
1226 return $response->withJson($outputArray, 200);
1238 public function getReuseReportSummary($request, $response, $args)
1240 $uploadId = intval($args[
'id']);
1244 $reuseReportProcess = $this->container->get(
'businessrules.reusereportprocessor');
1245 $res = $reuseReportProcess->getReuseSummary($uploadId);
1246 return $response->withJson($res, 200);
1260 $uploadId = intval($args[
'id']);
1261 $query = $request->getQueryParams();
1262 $selectedAgentId = $query[
'agentId'] ??
null;
1263 $licenseDao = $this->container->get(
'dao.license');
1266 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
1269 $scannerAgents = array_keys(AgentRef::AGENT_LIST);
1270 $scanJobProxy =
new ScanJobProxy($this->agentDao, $uploadId);
1271 $scanJobProxy->createAgentStatus($scannerAgents);
1272 $uploadDao = $this->restHelper->getUploadDao();
1273 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1274 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1275 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
1276 $res = $licenseDao->getLicenseHistogram($itemTreeBounds, $selectedAgentIds);
1279 foreach ($res as $key => $value) {
1280 $scannedLicense =
new ScannedLicense($licenseDao->getLicenseByShortName($key)->getId(), $key, $value[
'count'], $value[
'unique'], $value[
'spdx_id']);
1283 return $response->withJson($outputArray, 200);
1296 $agentDao = $this->container->get(
'dao.agent');
1297 $uploadId = intval($args[
'id']);
1301 $scannerAgents = array_keys($this->agentNames);
1303 $scanJobProxy->createAgentStatus($scannerAgents);
1306 foreach ($scanJobProxy->getSuccessfulAgents() as $agent) {
1308 "id" => $agent->getAgentId(),
1309 "name" => $agent->getAgentName(),
1310 "revision" => $agent->getAgentRevision(),
1313 return $response->withJson($res, 200);
1327 $uploadId = intval($args[
'id']);
1328 if (!$this->dbHelper->doesIdExist(
"upload",
"upload_pk", $uploadId)) {
1329 $returnVal =
new Info(404,
"Upload does not exist", InfoType::ERROR);
1330 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1332 $uploadDao = $this->restHelper->getUploadDao();
1333 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
1334 $uploadDao->getUploadtreeTableName($uploadId));
1335 if ($itemTreeBounds ===
false) {
1336 $error =
new Info(500,
"Unable to get top item.", InfoType::ERROR);
1337 return $response->withJson($error->getArray(), $error->getCode());
1339 $info =
new Info(200, $itemTreeBounds->getItemId(), InfoType::INFO);
1340 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)
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.
char * trim(char *ptext)
Trimming whitespace.