13 namespace Fossology\UI\Api\Controllers;
22 use Psr\Http\Message\ServerRequestInterface;
58 const TYPE_COPYRIGHT = 1;
61 const TYPE_AUTHOR = 8;
63 const TYPE_KEYWORD = 32;
65 const TYPE_COPYRIGHT_USERFINDINGS = 128;
66 const TYPE_COPYRIGHT_SCANCODE = 256;
67 const TYPE_EMAIL_SCANCODE = 512;
68 const TYPE_URL_SCANCODE = 1024;
69 const TYPE_AUTHOR_SCANCODE = 2048;
74 $this->copyrightDao = $this->container->get(
'dao.copyright');
75 $this->copyrightHist = $this->restHelper->getPlugin(
'ajax-copyright-hist');
88 return $this->
getFileCX($request, $response, $args, self::TYPE_COPYRIGHT);
101 return $this->
getFileCX($request, $response, $args, self::TYPE_COPYRIGHT_USERFINDINGS);
114 return $this->
getFileCX($request, $response, $args, self::TYPE_COPYRIGHT_SCANCODE);
127 return $this->
getFileCX($request, $response, $args, self::TYPE_EMAIL);
140 return $this->
getFileCX($request, $response, $args, self::TYPE_EMAIL_SCANCODE);
153 return $this->
getFileCX($request, $response, $args, self::TYPE_URL);
166 return $this->
getFileCX($request, $response, $args, self::TYPE_URL_SCANCODE);
179 return $this->
getFileCX($request, $response, $args, self::TYPE_AUTHOR);
192 return $this->
getFileCX($request, $response, $args, self::TYPE_AUTHOR_SCANCODE);
205 return $this->
getFileCX($request, $response, $args, self::TYPE_ECC);
218 return $this->
getFileCX($request, $response, $args, self::TYPE_KEYWORD);
231 return $this->
getFileCX($request, $response, $args, self::TYPE_IPRA);
244 return $this->
deleteFileCX($args, $response, self::TYPE_COPYRIGHT);
257 return $this->
deleteFileCX($args, $response, self::TYPE_COPYRIGHT_USERFINDINGS);
270 return $this->
deleteFileCX($args, $response, self::TYPE_COPYRIGHT_SCANCODE);
283 return $this->
deleteFileCX($args, $response, self::TYPE_EMAIL);
296 return $this->
deleteFileCX($args, $response, self::TYPE_EMAIL_SCANCODE);
308 return $this->
deleteFileCX($args, $response, self::TYPE_URL);
321 return $this->
deleteFileCX($args, $response, self::TYPE_URL_SCANCODE);
334 return $this->
deleteFileCX($args, $response, self::TYPE_AUTHOR);
347 return $this->
deleteFileCX($args, $response, self::TYPE_AUTHOR_SCANCODE);
360 return $this->
deleteFileCX($args, $response, self::TYPE_ECC);
373 return $this->
deleteFileCX($args, $response, self::TYPE_KEYWORD);
386 return $this->
deleteFileCX($args, $response, self::TYPE_IPRA);
399 return $this->
updateFileCx($request, $response, $args, self::TYPE_COPYRIGHT);
412 return $this->
updateFileCx($request, $response, $args, self::TYPE_COPYRIGHT_USERFINDINGS);
425 return $this->
updateFileCx($request, $response, $args, self::TYPE_COPYRIGHT_SCANCODE);
438 return $this->
updateFileCx($request, $response, $args, self::TYPE_EMAIL);
451 return $this->
updateFileCx($request, $response, $args, self::TYPE_EMAIL_SCANCODE);
464 return $this->
updateFileCx($request, $response, $args, self::TYPE_URL);
477 return $this->
updateFileCx($request, $response, $args, self::TYPE_URL_SCANCODE);
490 return $this->
updateFileCx($request, $response, $args, self::TYPE_AUTHOR);
503 return $this->
updateFileCx($request, $response, $args, self::TYPE_AUTHOR_SCANCODE);
516 return $this->
updateFileCx($request, $response, $args, self::TYPE_ECC);
529 return $this->
updateFileCx($request, $response, $args, self::TYPE_KEYWORD);
542 return $this->
updateFileCx($request, $response, $args, self::TYPE_IPRA);
555 return $this->
restoreFileCx($args, $response, self::TYPE_COPYRIGHT);
568 return $this->
restoreFileCx($args, $response, self::TYPE_COPYRIGHT_USERFINDINGS);
581 return $this->
restoreFileCx($args, $response, self::TYPE_COPYRIGHT_SCANCODE);
594 return $this->
restoreFileCx($args, $response, self::TYPE_EMAIL);
607 return $this->
restoreFileCx($args, $response, self::TYPE_EMAIL_SCANCODE);
620 return $this->
restoreFileCx($args, $response, self::TYPE_URL);
633 return $this->
restoreFileCx($args, $response, self::TYPE_URL_SCANCODE);
646 return $this->
restoreFileCx($args, $response, self::TYPE_AUTHOR);
659 return $this->
restoreFileCx($args, $response, self::TYPE_AUTHOR_SCANCODE);
672 return $this->
restoreFileCx($args, $response, self::TYPE_ECC);
685 return $this->
restoreFileCx($args, $response, self::TYPE_KEYWORD);
698 return $this->
restoreFileCx($args, $response, self::TYPE_IPRA);
712 return $this->
getTotalCX($request, $response, $args, self::TYPE_COPYRIGHT);
726 return $this->
getTotalCX($request, $response, $args, self::TYPE_COPYRIGHT_USERFINDINGS);
738 private function getTotalCX($request, $response, $args, $cxType)
741 $uploadPk = $args[
"id"];
742 $uploadTreeId = $args[
"itemId"];
743 $query = $request->getQueryParams();
749 if (!array_key_exists(self::COPYRIGHT_PARAM, $query)) {
751 "required query param with expected values 'active' or 'inactive");
754 if ($status ==
"active") {
756 }
else if ($status ==
"inactive") {
760 "parameter, expected values 'active' or 'inactive");
762 $uploadTreeTableName = $this->restHelper->getUploadDao()->getUploadtreeTableName($uploadPk);
764 if ($cxType == self::TYPE_COPYRIGHT) {
765 $agentId = $this->copyrightHist->getAgentId($uploadPk,
'copyright_ars');
766 $returnVal = $this->copyrightDao->getTotalCopyrights($uploadPk, $uploadTreeId, $uploadTreeTableName, $agentId,
'statement', $statusVal);
767 }
else if ($cxType == self::TYPE_COPYRIGHT_USERFINDINGS) {
768 $copyrightData = $this->copyrightDao->getUserCopyrights($uploadPk, $uploadTreeId, $uploadTreeTableName,
'userfindingcopyright', $statusVal);
769 $returnVal = $copyrightData[1];
771 return $response->withJson(array($version == ApiVersion::V2 ?
"totalCopyrights" :
"total_copyrights" => $returnVal), 200);
784 private function getFileCX($request, $response, $args, $cxType)
787 case self::TYPE_COPYRIGHT:
788 $dataType =
'statement';
789 $agentArs =
'copyright_ars';
791 case self::TYPE_COPYRIGHT_USERFINDINGS:
792 $dataType =
'userfindingcopyright';
793 $agentArs =
'copyright_ars';
795 case self::TYPE_COPYRIGHT_SCANCODE:
796 $dataType =
'scancode_statement';
797 $agentArs =
'scancode_ars';
799 case self::TYPE_EMAIL:
801 $agentArs =
'copyright_ars';
803 case self::TYPE_EMAIL_SCANCODE:
804 $dataType =
'scancode_email';
805 $agentArs =
'scancode_ars';
809 $agentArs =
'copyright_ars';
811 case self::TYPE_URL_SCANCODE:
812 $dataType =
'scancode_url';
813 $agentArs =
'scancode_ars';
815 case self::TYPE_AUTHOR:
816 $dataType =
'author';
817 $agentArs =
'copyright_ars';
819 case self::TYPE_AUTHOR_SCANCODE:
820 $dataType =
'scancode_author';
821 $agentArs =
'scancode_ars';
825 $agentArs =
'ecc_ars';
827 case self::TYPE_KEYWORD:
828 $dataType =
'keyword';
829 $agentArs =
'keyword_ars';
831 case self::TYPE_IPRA:
833 $agentArs =
'ipra_ars';
836 $dataType =
'statement';
837 $agentArs =
'copyright_ars';
840 $uploadPk = $args[
"id"];
841 $uploadTreeId = $args[
"itemId"];
842 $query = $request->getQueryParams();
843 if ($apiVersion == ApiVersion::V2) {
846 $limit = $request->getHeaderLine(self::LIMIT_PARAM);
849 if (!empty($limit)) {
850 $limit = filter_var($limit, FILTER_VALIDATE_INT);
853 "limit should be positive integer > 1");
858 if (!array_key_exists(self::COPYRIGHT_PARAM, $query)) {
860 "required query param with expected values 'active' or 'inactive");
863 if ($status ==
"active") {
865 }
else if ($status ==
"inactive") {
869 "parameter, expected values 'active' or 'inactive");
875 $agentId = $this->copyrightHist->getAgentId($uploadPk, $agentArs);
876 $uploadTreeTableName = $this->restHelper->getUploadDao()->getuploadTreeTableName($uploadPk);
877 if ($apiVersion == ApiVersion::V2) {
880 $page = $request->getHeaderLine(self::PAGE_PARAM);
882 if (empty($page) && $page !=
"0") {
885 if (!empty($page) || $page ==
"0") {
886 $page = filter_var($page, FILTER_VALIDATE_INT);
889 "page should be positive integer > 0");
892 $offset = $limit * ($page - 1);
893 if (self::TYPE_COPYRIGHT_USERFINDINGS == $cxType) {
894 list($rows, $iTotalRecords) = $this->copyrightDao
895 ->getUserCopyrights($uploadPk, $uploadTreeId, $uploadTreeTableName,
896 $dataType, $statusVal, $offset, $limit);
898 list($rows, $iTotalDisplayRecords, $iTotalRecords) = $this->copyrightHist
899 ->getCopyrights($uploadPk, $uploadTreeId, $uploadTreeTableName,
900 $agentId, $dataType,
'active', $statusVal, $offset, $limit);
902 foreach ($rows as $row) {
903 $row[
'count'] = intval($row[
'copyright_count']);
904 unset($row[
'copyright_count']);
907 $totalPages = intval(ceil($iTotalRecords / $limit));
908 if ($totalPages != 0 && $page > $totalPages) {
910 "Can not exceed total pages: $totalPages"))
911 ->setHeaders([
"X-Total-Pages" => $totalPages]);
913 return $response->withHeader(
"X-Total-Pages", $totalPages)->withJson($finalVal, 200);
929 $uploadDao = $this->restHelper->getUploadDao();
930 $uploadPk = intval($args[
'id']);
931 $uploadTreeId = intval($args[
'itemId']);
932 $copyrightHash = $args[
'hash'];
933 $userId = $this->restHelper->getUserId();
934 $cpTable = $this->copyrightHist->getTableName($dataType);
939 $uploadTreeTableName = $uploadDao->getUploadTreeTableName($uploadTreeId);
940 if (self::TYPE_COPYRIGHT_USERFINDINGS == $cxType) {
941 $tableName = $cpTable.
"_decision";
942 $decisions = $this->copyrightDao->getDecisionsFromHash($tableName, $copyrightHash,
943 $uploadPk, $uploadTreeTableName);
944 foreach ($decisions as $decision) {
945 $this->copyrightDao->removeDecision($tableName, $decision[
'pfile_fk'],
946 $decision[$tableName .
'_pk']);
949 $item = $uploadDao->getItemTreeBounds($uploadTreeId, $uploadTreeTableName);
950 $this->copyrightDao->updateTable($item, $copyrightHash,
'', $userId, $cpTable,
'delete');
952 $returnVal =
new Info(200,
"Successfully removed $delName.", InfoType::INFO);
953 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
968 $uploadPk = intval($args[
'id']);
969 $uploadTreeId = intval($args[
'itemId']);
970 $copyrightHash = ($args[
'hash']);
971 $userId = $this->restHelper->getUserId();
972 $cpTable = $this->copyrightHist->getTableName($dataType);
977 $uploadTreeTableName = $this->restHelper->getUploadDao()->getuploadTreeTableName($uploadTreeId);
978 if (self::TYPE_COPYRIGHT_USERFINDINGS == $cxType) {
979 $tableName = $cpTable.
"_decision";
980 $decisions = $this->copyrightDao->getDecisionsFromHash($tableName, $copyrightHash,
981 $uploadPk, $uploadTreeTableName);
982 foreach ($decisions as $decision) {
983 $this->copyrightDao->undoDecision($tableName, $decision[
'pfile_fk'],
984 $decision[$tableName .
'_pk']);
987 $item = $this->restHelper->getUploadDao()->getItemTreeBounds($uploadTreeId, $uploadTreeTableName);
988 $this->copyrightDao->updateTable($item, $copyrightHash,
'', $userId, $cpTable,
'rollback');
990 $returnVal =
new Info(200,
"Successfully restored $resName.", InfoType::INFO);
991 return $response->withJson($returnVal->getArray(), 200);
1007 $uploadTreeId = intval($args[
"itemId"]);
1008 $uploadPk = intval($args[
"id"]);
1009 $copyrightHash = $args[
"hash"];
1010 $userId = $this->restHelper->getUserId();
1011 $cpTable = $this->copyrightHist->getTableName($dataType);
1013 $content = $body[
'content'];
1018 $uploadTreeTableName = $this->restHelper->getUploadDao()->getuploadTreeTableName($uploadTreeId);
1019 if (self::TYPE_COPYRIGHT_USERFINDINGS == $cxType) {
1020 $tableName = $cpTable.
"_decision";
1021 $decisions = $this->copyrightDao->getDecisionsFromHash($tableName, $copyrightHash,
1022 $uploadPk, $uploadTreeTableName);
1023 foreach ($decisions as $decision) {
1024 $this->copyrightDao->saveDecision($tableName, $decision[
'pfile_fk'], $decision[
'user_fk'],
1025 $decision[
'clearing_decision_type_fk'], $decision[
'description'],
1026 $content, $decision[
'comment'], $decision[$tableName .
'_pk']);
1029 $item = $this->restHelper->getUploadDao()->getItemTreeBounds($uploadTreeId, $uploadTreeTableName);
1030 $this->copyrightDao->updateTable($item, $copyrightHash, $content, $userId, $cpTable);
1032 $returnVal =
new Info(200,
"Successfully Updated $resName.", InfoType::INFO);
1033 return $response->withJson($returnVal->getArray(), 200);
1045 case self::TYPE_COPYRIGHT:
1046 $dataType =
'statement';
1047 $dispName =
'copyright';
1049 case self::TYPE_COPYRIGHT_USERFINDINGS:
1050 $dataType =
'statement';
1051 $dispName =
'user-copyright';
1053 case self::TYPE_COPYRIGHT_SCANCODE:
1054 $dataType =
'scancode_statement';
1055 $dispName =
'scancode-copyright';
1057 case self::TYPE_EMAIL:
1058 $dispName = $dataType =
'email';
1060 case self::TYPE_EMAIL_SCANCODE:
1061 $dataType =
'scancode_email';
1062 $dispName =
'scancode-email';
1064 case self::TYPE_URL:
1065 $dispName = $dataType =
'url';
1067 case self::TYPE_URL_SCANCODE:
1068 $dataType =
'scancode_url';
1069 $dispName =
'scancode-url';
1071 case self::TYPE_AUTHOR:
1072 $dispName = $dataType =
'author';
1074 case self::TYPE_AUTHOR_SCANCODE:
1075 $dataType =
'scancode_author';
1076 $dispName =
'scancode-author';
1078 case self::TYPE_ECC:
1079 $dispName = $dataType =
'ecc';
1081 case self::TYPE_KEYWORD:
1082 $dispName = $dataType =
'keyword';
1084 case self::TYPE_IPRA:
1085 $dispName = $dataType =
'ipra';
1088 $dataType =
'statement';
1089 $dispName =
'copyright';
1091 return array($dataType, $dispName);
deleteFileEmail($request, $response, $args)
restoreFileScanCodeEmail($request, $response, $args)
convertTypeToTable(int $cxType)
getFileCopyrights($request, $response, $args)
deleteFileUserCopyright($request, $response, $args)
updateFileAuthor($request, $response, $args)
getFileKeyword($request, $response, $args)
updateFileEcc($request, $response, $args)
getFileScanCodeAuthor($request, $response, $args)
restoreFileEcc($request, $response, $args)
restoreFileScanCodeCopyright($request, $response, $args)
restoreFileScanCodeUrl($request, $response, $args)
updateFileScanCodeUrl($request, $response, $args)
restoreFileScanCodeAuthor($request, $response, $args)
updateFileScanCodeAuthor($request, $response, $args)
updateFileKeyword($request, $response, $args)
getFileUserCopyrights($request, $response, $args)
getFileAuthor($request, $response, $args)
deleteFileUrl($request, $response, $args)
updateFileUrl($request, $response, $args)
getTotalFileUserCopyrights($request, $response, $args)
getFileUrl($request, $response, $args)
updateFileScanCodeEmail($request, $response, $args)
updateFileIpra($request, $response, $args)
restoreFileCx($args, $response, $cxType)
getFileScanCodeUrl($request, $response, $args)
restoreFileUrl($request, $response, $args)
restoreFileEmail($request, $response, $args)
deleteFileScanCodeCopyright($request, $response, $args)
restoreFileCopyright($request, $response, $args)
deleteFileScanCodeAuthor($request, $response, $args)
const COPYRIGHT_FETCH_LIMIT
updateFileUserCopyright($request, $response, $args)
getFileEmail($request, $response, $args)
deleteFileEcc($request, $response, $args)
updateFileScanCodeCopyright($request, $response, $args)
deleteFileKeyword($request, $response, $args)
getFileEcc($request, $response, $args)
restoreFileIpra($request, $response, $args)
deleteFileAuthor($request, $response, $args)
deleteFileCX($args, $response, $cxType)
restoreFileKeyword($request, $response, $args)
getFileScanCodeCopyrights($request, $response, $args)
restoreFileAuthor($request, $response, $args)
deleteFileIpra($request, $response, $args)
restoreFileUserCopyright($request, $response, $args)
deleteFileScanCodeUrl($request, $response, $args)
getFileScanCodeEmail($request, $response, $args)
getFileCX($request, $response, $args, $cxType)
updateFileEmail($request, $response, $args)
deleteFileScanCodeEmail($request, $response, $args)
getFileIpra($request, $response, $args)
getTotalFileCopyrights($request, $response, $args)
updateFileCopyright($request, $response, $args)
deleteFileCopyright($request, $response, $args)
updateFileCx($request, $response, $args, $cxType)
getTotalCX($request, $response, $args, $cxType)
Base controller for REST calls.
isItemExists(int $uploadId, int $itemId)
getParsedBody(ServerRequestInterface $request)
Parse request body as JSON and return associative PHP array.
Override Slim response for withJson function.
static getVersion(ServerRequestInterface $request)
Different type of infos provided by REST.
Info model to contain general error and return values.
list_t type structure used to keep various lists. (e.g. there are multiple lists).