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']);
287 $dbManager = $this->restHelper->getDbHelper()->getDbManager();
288 $uploadDao = $this->restHelper->getUploadDao();
289 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($id);
290 $itemTreeBounds = $uploadDao->getParentItemBounds($id,$uploadTreeTableName);
291 $sql =
"SELECT pfile_fk, ufile_name FROM $uploadTreeTableName " .
292 "WHERE uploadtree_pk=$1";
293 $params = array($itemTreeBounds->getItemId());
294 $descendants = $dbManager->getSingleRow($sql, $params,
295 __METHOD__ .
"." . $uploadTreeTableName);
296 if (empty($descendants)) {
297 throw new HttpNotFoundException(
"Upload file not found.");
299 $path=
RepPath(($descendants[
'pfile_fk']));
300 $responseFile = $ui_download->getDownload($path, $descendants[
'ufile_name']);
301 $responseContent = $responseFile->getFile();
302 $newResponse = $response->withHeader(
'Content-Description',
304 ->withHeader(
'Content-Type',
305 $responseContent->getMimeType())
306 ->withHeader(
'Content-Disposition',
307 $responseFile->headers->get(
'Content-Disposition'))
308 ->withHeader(
'Cache-Control',
'must-revalidate')
309 ->withHeader(
'Pragma',
'private')
310 ->withHeader(
'Content-Length', filesize($responseContent->getPathname()));
311 $sf =
new StreamFactory();
312 return $newResponse->withBody(
313 $sf->createStreamFromFile($responseContent->getPathname())
328 $id = intval($args[
'id']);
329 $query = $request->getQueryParams();
330 $selectedAgentId = $query[
'agentId'] ??
null;
331 $agentDao = $this->container->get(
'dao.agent');
333 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
338 $uploadSummary = $uploadHelper->generateUploadSummary($id, $this->restHelper->getGroupId());
339 $browseLicense = $this->restHelper->getPlugin(
'license');
340 $uploadDao = $this->restHelper->getUploadDao();
341 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($id);
342 $itemTreeBounds = $uploadDao->getParentItemBounds($id, $uploadTreeTableName);
344 $scannerAgents = array_keys(AgentRef::AGENT_LIST);
345 $scanJobProxy->createAgentStatus($scannerAgents);
346 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
347 $res = $browseLicense->createLicenseHistogram(
"",
"", $itemTreeBounds, $selectedAgentIds, $this->restHelper->getGroupId());
348 $uploadSummary->setUniqueConcludedLicenses($res[
'editedUniqueLicenseCount']);
349 $uploadSummary->setTotalConcludedLicenses($res[
'editedLicenseCount']);
350 $uploadSummary->setTotalLicenses($res[
'scannerLicenseCount']);
351 $uploadSummary->setUniqueLicenses($res[
'uniqueLicenseCount']);
352 $uploadSummary->setConcludedNoLicenseFoundCount($res[
'editedNoLicenseFoundCount']);
353 $uploadSummary->setFileCount($res[
'fileCount']);
354 $uploadSummary->setNoScannerLicenseFoundCount($res[
'noScannerLicenseFoundCount']);
355 $uploadSummary->setScannerUniqueLicenseCount($res[
'scannerUniqueLicenseCount']);
357 return $response->withJson($uploadSummary->getArray(), 200);
371 require_once dirname(__DIR__, 4) .
"/delagent/ui/delete-helper.php";
372 $id = intval($args[
'id']);
375 $result = TryToDelete($id, $this->restHelper->getUserId(),
376 $this->restHelper->getGroupId(), $this->restHelper->getUploadDao());
383 $result->getDeleteMessageString());
385 $returnVal =
new Info(202,
"Delete Job for file with id " . $id,
387 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
401 $queryParams = $request->getQueryParams();
402 $action = $queryParams[
'action'] ??
"";
404 $action = $request->getHeaderLine(
'action');
406 if (strtolower($action) ==
"move") {
411 return $this->
changeUpload($request, $response, $args, $copy);
426 $queryParams = $request->getQueryParams();
428 $paramType = ($isApiVersionV2) ?
'parameter' :
'header';
430 if ((!$isApiVersionV2 && !$request->hasHeader(
'folderId') || $isApiVersionV2 && !isset($queryParams[
'folderId']))
431 || !is_numeric($newFolderID = ($isApiVersionV2 ? $queryParams[
'folderId'] : $request->getHeaderLine(
'folderId')))) {
432 throw new HttpBadRequestException(
"For API version " . ($isApiVersionV2 ?
'V2' :
'V1') .
", 'folderId' $paramType should be present and an integer.");
435 $id = intval($args[
'id']);
436 $returnVal = $this->restHelper->copyUpload($id, $newFolderID, $isCopy);
437 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
449 public function postUpload($request, $response, $args)
453 $uploadType = $reqBody[
'uploadType'] ??
null;
454 $folderId = $reqBody[
'folderId'] ??
null;
455 $description = $reqBody[
'uploadDescription'] ??
"";
456 $public = $reqBody[
'public'] ??
null;
457 $applyGlobal = filter_var($reqBody[
'applyGlobal'] ??
null,
458 FILTER_VALIDATE_BOOLEAN);
459 $ignoreScm = $reqBody[
'ignoreScm'] ??
null;
460 $excludefolder = $reqBody[
'excludefolder'] ??
false;
462 $uploadType = $request->getHeaderLine(
'uploadType');
463 $folderId = $request->getHeaderLine(
'folderId');
464 $description = $request->getHeaderLine(
'uploadDescription');
465 $public = $request->getHeaderLine(
'public');
466 $applyGlobal = filter_var($request->getHeaderLine(
'applyGlobal'),
467 FILTER_VALIDATE_BOOLEAN);
468 $ignoreScm = $request->getHeaderLine(
'ignoreScm');
471 $public = empty($public) ?
'protected' : $public;
473 if (empty($uploadType)) {
474 throw new HttpBadRequestException(
"Require uploadType");
477 if (array_key_exists(
'scanOptions', $reqBody)) {
478 if ($uploadType ==
'file') {
479 $scanOptions = json_decode($reqBody[
'scanOptions'],
true);
480 if (json_last_error() !== JSON_ERROR_NONE || ! is_array($scanOptions)) {
481 throw new HttpBadRequestException(
"Invalid scanOptions JSON");
484 $scanOptions = $reqBody[
'scanOptions'];
488 if (! is_array($scanOptions)) {
492 $uploadHelper =
new UploadHelper();
494 if ($uploadType !=
"file" && (empty($reqBody) ||
495 ! array_key_exists(
"location", $reqBody))) {
496 throw new HttpBadRequestException(
497 "Require location object if uploadType != file");
499 if (empty($folderId) ||
500 !is_numeric($folderId) ||
501 intval($folderId) <= 0) {
502 throw new HttpBadRequestException(
"folderId must be a positive integer!");
505 $allFolderIds = $this->restHelper->getFolderDao()->getAllFolderIds();
506 if (!in_array($folderId, $allFolderIds)) {
507 throw new HttpNotFoundException(
"folderId $folderId does not exists!");
509 if (!$this->restHelper->getFolderDao()->isFolderAccessible($folderId,
510 $this->restHelper->getUserId())) {
511 throw new HttpForbiddenException(
"folderId $folderId is not accessible!");
514 $locationObject = [];
515 if (array_key_exists(
"location", $reqBody)) {
516 $locationObject = $reqBody[
"location"];
517 } elseif ($uploadType !=
'file') {
518 throw new HttpBadRequestException(
519 "Require location object if uploadType != file");
523 $uploadResponse = $uploadHelper->createNewUpload($locationObject,
524 $folderId, $description, $public, $ignoreScm, $uploadType,
525 $applyGlobal, $excludefolder);
527 $uploadResponse = $uploadHelper->createNewUpload($locationObject,
528 $folderId, $description, $public, $ignoreScm, $uploadType,
531 $status = $uploadResponse[0];
532 $message = $uploadResponse[1];
533 $statusDescription = $uploadResponse[2];
535 throw new HttpInternalServerErrorException($message .
"\n" .
539 $uploadId = $uploadResponse[3];
540 if (! empty($scanOptions)) {
541 $info = $uploadHelper->handleScheduleAnalysis(intval($uploadId),
543 if ($info->getCode() == 201) {
544 $info =
new Info($info->getCode(), intval($uploadId), $info->getType());
547 $info =
new Info(201, intval($uploadId), InfoType::INFO);
549 if (array_key_exists(
"mainLicense", $reqBody) &&
550 ! empty($reqBody[
"mainLicense"])) {
554 $mainLicense = $licenseDao
555 ->getLicenseByShortName($reqBody[
"mainLicense"]);
556 if ($mainLicense !==
null) {
558 $clearingDao =
$container->get(
'dao.clearing');
559 $clearingDao->makeMainLicense($uploadId,
560 $this->restHelper->getGroupId(), $mainLicense->getId());
563 return $response->withJson($info->getArray(), $info->getCode());
577 $id = intval($args[
'id']);
578 $query = $request->getQueryParams();
580 if ($apiVersion == ApiVersion::V2) {
581 $page = $query[
'page'] ??
"";
582 $limit = $query[
'limit'] ??
"";
584 $page = $request->getHeaderLine(
"page");
585 $limit = $request->getHeaderLine(
"limit");
587 if (! array_key_exists(self::AGENT_PARAM, $query)) {
590 $agents = explode(
",", $query[self::AGENT_PARAM]);
592 if (array_key_exists(self::CONTAINER_PARAM, $query)) {
593 $containers = (strcasecmp($query[self::CONTAINER_PARAM],
"true") === 0);
597 if (array_key_exists(
'license', $query)) {
598 $license = (strcasecmp($query[
'license'],
"true") === 0);
602 if (array_key_exists(
'copyright', $query)) {
603 $copyright = (strcasecmp($query[
'copyright'],
"true") === 0);
606 if (!$license && !$copyright) {
608 "'license' and 'copyright' atleast one should be true.");
619 if ((! ($page===
'') && (! is_numeric($page) || $page < 1)) ||
620 (! ($limit===
'') && (! is_numeric($limit) || $limit < 1))) {
622 "page and limit need to be positive integers!");
633 }
else if ($limit > 1000) {
638 list($licenseList, $count) = $uploadHelper->getUploadLicenseList($id, $agents, $containers, $license, $copyright, $page-1, $limit, $apiVersion);
639 $totalPages = intval(ceil($count / $limit));
640 return $response->withHeader(
"X-Total-Pages", $totalPages)->withJson($licenseList, 200);
654 $id = intval($args[
'id']);
658 $licenseList = $uploadHelper->getUploadCopyrightList($id);
659 return $response->withJson($licenseList, 200);
671 public function updateUpload($request, $response, $args)
673 $id = intval($args[
'id']);
674 $query = $request->getQueryParams();
675 $userDao = $this->restHelper->getUserDao();
676 $userId = $this->restHelper->getUserId();
677 $groupId = $this->restHelper->getGroupId();
680 $perm = $userDao->isAdvisorOrAdmin($userId, $groupId);
683 "Can not update upload.");
685 $uploadBrowseProxy =
new UploadBrowseProxy(
688 $this->dbHelper->getDbManager()
695 $newDescription =
null;
697 if ($isJsonRequest) {
700 $body = $request->getBody();
701 $bodyContent = $body->getContents();
706 if (array_key_exists(self::FILTER_ASSIGNEE, $query)) {
707 $assignee = filter_var($query[self::FILTER_ASSIGNEE], FILTER_VALIDATE_INT);
708 $userList = $userDao->getUserChoices($groupId);
709 if (!array_key_exists($assignee, $userList)) {
710 throw new HttpNotFoundException(
711 "New assignee does not have permission on upload.");
713 $uploadBrowseProxy->updateTable(
"assignee", $id, $assignee);
717 array_key_exists(self::FILTER_STATUS, $query) &&
718 in_array(strtolower($query[self::FILTER_STATUS]), self::VALID_STATUS)
720 $newStatus = strtolower($query[self::FILTER_STATUS]);
722 if (in_array($newStatus, [
"closed",
"rejected"])) {
723 if ($isJsonRequest && array_key_exists(
"comment", $bodyContent)) {
724 $comment = $bodyContent[
"comment"];
726 $comment = $bodyContent;
730 if ($newStatus == self::VALID_STATUS[1]) {
731 $status = UploadStatus::IN_PROGRESS;
732 } elseif ($newStatus == self::VALID_STATUS[2]) {
733 $status = UploadStatus::CLOSED;
734 } elseif ($newStatus == self::VALID_STATUS[3]) {
735 $status = UploadStatus::REJECTED;
737 $status = UploadStatus::OPEN;
739 $uploadBrowseProxy->setStatusAndComment($id, $status, $comment);
744 array_key_exists(self::FILTER_NAME, $bodyContent) &&
745 strlen(
trim($bodyContent[self::FILTER_NAME])) > 0
747 $newName =
trim($bodyContent[self::FILTER_NAME]);
752 array_key_exists(
"uploadDescription", $bodyContent) &&
753 strlen(
trim($bodyContent[
"uploadDescription"])) > 0
755 $newDescription =
trim($bodyContent[
"uploadDescription"]);
757 if ($newName !=
null || $newDescription !=
null) {
759 $uploadProperties = $this->restHelper->getPlugin(
'upload_properties');
760 $updated = $uploadProperties->UpdateUploadProperties($id, $newName, $newDescription);
762 throw new HttpBadRequestException(
"Invalid request to update upload name and description.");
766 $returnVal =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
767 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
777 $itemTreeBounds = $this->restHelper->getUploadDao()->getParentItemBounds(
779 if ($itemTreeBounds ===
false || empty($itemTreeBounds->getLeft())) {
781 "Ununpack job not started. Please check job status at " .
782 "/api/v1/jobs?upload=" . $id))
783 ->setHeaders([
'Retry-After' =>
'60',
784 'Look-at' =>
"/api/v1/jobs?upload=" . $id]);
802 $agentList = array_keys(AgentRef::AGENT_LIST);
803 $intersectArray = array_intersect($agents, $agentList);
805 if (count($agents) != count($intersectArray)) {
807 implode(
", ", $agentList) .
". " . implode(
",", $agents) .
" passed.");
810 foreach ($agents as $agent) {
811 if (!
$agentDao->arsTableExists($agent)) {
813 "Agent $agent not scheduled for the upload. " .
814 "Please POST to /jobs");
820 $agentList = $scanProxy->createAgentStatus($agents);
822 foreach ($agentList as $agent) {
823 if (! array_key_exists(
'currentAgentId', $agent)) {
825 "Agent " . $agent[
"agentName"] .
826 " not scheduled for the upload. Please POST to /jobs");
828 if (array_key_exists(
'isAgentRunning', $agent) &&
829 $agent[
'isAgentRunning']) {
831 "Agent " . $agent[
"agentName"] .
" is running. " .
832 "Please check job status at /api/v1/jobs?upload=" . $uploadId))
833 ->setHeaders([
'Retry-After' =>
'60',
834 'Look-at' =>
"/api/v1/jobs?upload=" . $uploadId]);
853 if (!$commu_status) {
859 $uploadPermissionObj =
$restHelper->getPlugin(
'upload_permissions');
861 $dbManager = $this->dbHelper->getDbManager();
865 $folder_pk = intval($reqBody[
'folderId']);
866 $upload_pk = intval($args[
'id']);
868 $allUploadsPerm = $reqBody[
'allUploadsPermission'] ? 1 : 0;
869 $newgroup = intval($reqBody[
'groupId']);
870 $newperm = $this->getEquivalentValueForPermission($reqBody[
'newPermission']);
871 $public_perm = isset($reqBody[
'publicPermission']) ? $this->getEquivalentValueForPermission($reqBody[
'publicPermission']) : -1;
873 $query =
"SELECT perm, perm_upload_pk FROM perm_upload WHERE upload_fk=$1 and group_fk=$2;";
874 $result = $dbManager->getSingleRow($query, [$upload_pk, $newgroup], __METHOD__.
".getOldPerm");
877 if (!empty($result)) {
878 $perm_upload_pk = intVal($result[
'perm_upload_pk']);
882 $uploadPermissionObj->editPermissionsForUpload($commu_status, $folder_pk, $upload_pk, $allUploadsPerm, $perm_upload_pk, $perm, $newgroup, $newperm, $public_perm);
884 $returnVal =
new Info(202,
"Permissions updated successfully!", InfoType::INFO);
885 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
888 public function getEquivalentValueForPermission($perm)
895 case 'clearing_admin':
896 return Auth::PERM_CADMIN;
916 $upload_pk = intval($args[
'id']);
918 $publicPerm = $this->restHelper->getUploadPermissionDao()->getPublicPermission($upload_pk);
919 $permGroups = $this->restHelper->getUploadPermissionDao()->getPermissionGroups($upload_pk);
922 $finalPermGroups = [];
923 foreach ($permGroups as $value) {
924 $groupPerm =
new GroupPermission($value[
'perm'], $value[
'group_pk'], $value[
'group_name']);
925 $finalPermGroups[] = $groupPerm->getArray($apiVersion);
927 $res =
new Permissions($publicPerm, $finalPermGroups);
928 return $response->withJson($res->getArray($apiVersion), 200);
940 public function getMainLicenses($request, $response, $args)
942 $uploadId = intval($args[
'id']);
946 $clearingDao = $this->container->get(
'dao.clearing');
947 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
948 $licenseDao = $this->container->get(
'dao.license');
951 foreach ($licenseIds as $value) {
952 $licenseId = intval($value);
953 $obligations = $licenseDao->getLicenseObligations([$licenseId],
955 $obligations = array_merge($obligations,
956 $licenseDao->getLicenseObligations([$licenseId],
true));
957 $obligationList = [];
958 foreach ($obligations as $obligation) {
960 $obligation[
'ob_pk'],
961 $obligation[
'ob_topic'],
962 $obligation[
'ob_type'],
963 $obligation[
'ob_text'],
964 $obligation[
'ob_classification'],
965 $obligation[
'ob_comment']
968 $license = $licenseDao->getLicenseById($licenseId);
971 $license->getShortName(),
972 $license->getFullName(),
978 $licenses[] = $licenseObj->getArray();
980 return $response->withJson($licenses, 200);
992 public function setMainLicense($request, $response, $args)
994 $uploadId = intval($args[
'id']);
996 $shortName = $body[
'shortName'];
997 $licenseDao = $this->container->get(
'dao.license');
998 $clearingDao = $this->container->get(
'dao.clearing');
1002 if (empty($shortName)) {
1003 throw new HttpBadRequestException(
"Short name missing from request.");
1005 $license = $licenseDao->getLicenseByShortName($shortName,
1006 $this->restHelper->getGroupId());
1008 if ($license ===
null) {
1009 throw new HttpNotFoundException(
1010 "No license with shortname '$shortName' found.");
1013 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
1014 if (in_array($license->getId(), $licenseIds)) {
1015 throw new HttpBadRequestException(
1016 "License already exists for this upload.");
1020 $clearingDao = $this->container->get(
'dao.clearing');
1021 $clearingDao->makeMainLicense($uploadId, $this->restHelper->getGroupId(), $license->getId());
1022 $returnVal =
new Info(200,
"Successfully added new main license", InfoType::INFO);
1023 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1035 public function removeMainLicense($request, $response, $args)
1037 $uploadId = intval($args[
'id']);
1038 $shortName = $args[
'shortName'];
1039 $licenseDao = $this->container->get(
'dao.license');
1040 $clearingDao = $this->container->get(
'dao.clearing');
1041 $license = $licenseDao->getLicenseByShortName($shortName, $this->restHelper->getGroupId());
1045 if ($license ===
null) {
1046 throw new HttpNotFoundException(
1047 "No license with shortname '$shortName' found.");
1049 $licenseIds = $clearingDao->getMainLicenseIds($uploadId, $this->restHelper->getGroupId());
1050 if (!in_array($license->getId(), $licenseIds)) {
1051 throw new HttpBadRequestException(
1052 "License '$shortName' is not a main license for this upload.");
1055 $clearingDao = $this->container->get(
'dao.clearing');
1056 $clearingDao->removeMainLicense($uploadId, $this->restHelper->getGroupId(), $license->getId());
1057 $returnVal =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
1059 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1073 $uploadId = intval($args[
'id']);
1074 $uploadDao = $this->restHelper->getUploadDao();
1078 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1081 array(UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
1082 UploadTreeProxy::OPT_GROUP_ID => $this->restHelper->getGroupId()),
1083 $uploadTreeTableName,
1084 'no_license_uploadtree' . $uploadId);
1086 $filesOfInterest = $noLicenseUploadTreeView->count();
1089 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
1090 UploadTreeProxy::OPT_GROUP_ID => $this->restHelper->getGroupId()),
1091 $uploadTreeTableName,
1092 'already_cleared_uploadtree' . $uploadId);
1093 $filesToBeCleared = $nonClearedUploadTreeView->count();
1095 $filesAlreadyCleared = $filesOfInterest - $filesToBeCleared;
1098 "totalFilesOfInterest" => intval($filesOfInterest),
1099 "totalFilesCleared" => intval($filesAlreadyCleared),
1101 return $response->withJson($res, 200);
1115 $agentDao = $this->container->get(
'dao.agent');
1116 $clearingDao = $this->container->get(
'dao.clearing');
1117 $licenseDao = $this->container->get(
'dao.license');
1119 $uploadId = intval($args[
'id']);
1120 $uploadDao = $this->restHelper->getUploadDao();
1121 $query = $request->getQueryParams();
1122 $selectedAgentId = $query[
'agentId'] ??
null;
1126 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
1130 $scannerAgents = array_keys($this->agentNames);
1132 $scanJobProxy->createAgentStatus($scannerAgents);
1133 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1134 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1135 $editedLicenses = $clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $this->restHelper->getGroupId());
1136 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
1137 $scannedLicenses = $licenseDao->getLicenseHistogram($itemTreeBounds, $selectedAgentIds);
1138 $allScannerLicenseNames = array_keys($scannedLicenses);
1139 $allEditedLicenseNames = array_keys($editedLicenses);
1140 $allLicNames = array_unique(array_merge($allScannerLicenseNames, $allEditedLicenseNames));
1141 $realLicNames = array_diff($allLicNames, array(LicenseDao::NO_LICENSE_FOUND));
1142 $totalScannerLicenseCount = 0;
1143 $editedTotalLicenseCount = 0;
1146 foreach ($realLicNames as $licenseShortName) {
1148 if (array_key_exists($licenseShortName, $scannedLicenses)) {
1149 $count = $scannedLicenses[$licenseShortName][
'unique'];
1150 $rfId = $scannedLicenses[$licenseShortName][
'rf_pk'];
1152 $rfId = $editedLicenses[$licenseShortName][
'rf_pk'];
1154 $editedCount = array_key_exists($licenseShortName, $editedLicenses) ? $editedLicenses[$licenseShortName][
'count'] : 0;
1155 $totalScannerLicenseCount += $count;
1156 $editedTotalLicenseCount += $editedCount;
1157 $scannerCountLink = $count;
1158 $editedLink = $editedCount;
1160 $res[] = array($scannerCountLink, $editedLink, array($licenseShortName, $rfId));
1165 foreach ($res as $item) {
1167 "id" => intval($item[2][1]),
1168 "name" => $item[2][0],
1169 "scannerCount" => intval($item[0]),
1170 "concludedCount" => intval($item[1]),
1173 return $response->withJson($outputArray, 200);
1187 $uploadId = intval($args[
'id']);
1191 $scannerAgents = array_keys($this->agentNames);
1192 $agentDao = $this->container->get(
'dao.agent');
1194 $res = $scanJobProxy->createAgentStatus($scannerAgents);
1197 foreach ($res as &$item) {
1198 $successfulAgents = [];
1199 if (count($item[
'successfulAgents']) > 0) {
1200 $item[
'isAgentRunning'] =
false;
1202 $item[
'currentAgentId'] =
$agentDao->getCurrentAgentRef($item[
"agentName"])->getAgentId();
1203 $item[
'currentAgentRev'] =
"";
1205 foreach ($item[
'successfulAgents'] as &$agent) {
1206 $successfulAgent =
new SuccessfulAgent(intval($agent[
'agent_id']), $agent[
'agent_rev'], $agent[
'agent_name']);
1209 $agent =
new Agent($successfulAgents, $item[
'uploadId'], $item[
'agentName'], $item[
'currentAgentId'], $item[
'currentAgentRev'], $item[
'isAgentRunning']);
1212 return $response->withJson($outputArray, 200);
1226 $uploadId = intval($args[
'id']);
1230 $clearingDao = $this->container->get(
'dao.clearing');
1231 $uploadDao = $this->restHelper->getUploadDao();
1232 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1233 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1234 $res = $clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $this->restHelper->getGroupId());
1237 foreach ($res as $key => $value) {
1238 $editedLicense =
new EditedLicense(intval($value[
"rf_pk"]), $key, intval($value[
"count"]), $value[
"spdx_id"]);
1241 return $response->withJson($outputArray, 200);
1253 public function getReuseReportSummary($request, $response, $args)
1255 $uploadId = intval($args[
'id']);
1259 $reuseReportProcess = $this->container->get(
'businessrules.reusereportprocessor');
1260 $res = $reuseReportProcess->getReuseSummary($uploadId);
1261 return $response->withJson($res, 200);
1275 $uploadId = intval($args[
'id']);
1276 $query = $request->getQueryParams();
1277 $selectedAgentId = $query[
'agentId'] ??
null;
1278 $licenseDao = $this->container->get(
'dao.license');
1281 if ($selectedAgentId !==
null && !$this->dbHelper->doesIdExist(
"agent",
"agent_pk", $selectedAgentId)) {
1284 $scannerAgents = array_keys(AgentRef::AGENT_LIST);
1285 $scanJobProxy =
new ScanJobProxy($this->agentDao, $uploadId);
1286 $scanJobProxy->createAgentStatus($scannerAgents);
1287 $uploadDao = $this->restHelper->getUploadDao();
1288 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
1289 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1290 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
1291 $res = $licenseDao->getLicenseHistogram($itemTreeBounds, $selectedAgentIds);
1294 foreach ($res as $key => $value) {
1304 return $response->withJson($outputArray, 200);
1317 $agentDao = $this->container->get(
'dao.agent');
1318 $uploadId = intval($args[
'id']);
1322 $scannerAgents = array_keys($this->agentNames);
1324 $scanJobProxy->createAgentStatus($scannerAgents);
1327 foreach ($scanJobProxy->getSuccessfulAgents() as $agent) {
1329 "id" => $agent->getAgentId(),
1330 "name" => $agent->getAgentName(),
1331 "revision" => $agent->getAgentRevision(),
1334 return $response->withJson($res, 200);
1348 $uploadId = intval($args[
'id']);
1349 if (!$this->dbHelper->doesIdExist(
"upload",
"upload_pk", $uploadId)) {
1350 $returnVal =
new Info(404,
"Upload does not exist", InfoType::ERROR);
1351 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
1353 $uploadDao = $this->restHelper->getUploadDao();
1354 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
1355 $uploadDao->getUploadtreeTableName($uploadId));
1356 if ($itemTreeBounds ===
false) {
1357 $error =
new Info(500,
"Unable to get top item.", InfoType::ERROR);
1358 return $response->withJson($error->getArray(), $error->getCode());
1360 $info =
new Info(200, $itemTreeBounds->getItemId(), InfoType::INFO);
1361 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.