From 4898cb1a780bd4a5b98e16ff84da3c19333925e3 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 16 Apr 2024 12:06:19 -0600 Subject: [PATCH] chore(core): Endpoint for Content Reporting #27755 (#28080) * #27755 fixes * #27755 adding postman test * #27755 adding a case --------- Co-authored-by: Freddy Montes <751424+fmontes@users.noreply.github.com> --- ...nt_Report_Resource.postman_collection.json | 154 +++++++++++++++++- .../api/v1/content/FolderContentReport.java | 14 +- .../api/v1/content/SiteContentReport.java | 3 +- 3 files changed, 165 insertions(+), 6 deletions(-) diff --git a/dotCMS/src/curl-test/Content_Report_Resource.postman_collection.json b/dotCMS/src/curl-test/Content_Report_Resource.postman_collection.json index 2ce6b5405675..e41cd4eb3709 100644 --- a/dotCMS/src/curl-test/Content_Report_Resource.postman_collection.json +++ b/dotCMS/src/curl-test/Content_Report_Resource.postman_collection.json @@ -1,9 +1,9 @@ { "info": { - "_postman_id": "4210216c-e41b-413e-8e1c-f096844fd274", + "_postman_id": "ec804d51-d4b4-485a-8efb-2d077df5c8a8", "name": "Content Report Resource", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "5403727" + "_exporter_id": "781456" }, "item": [ { @@ -788,6 +788,156 @@ } ], "description": "Genrates a Content Report for a test Folder, containing a few Content Types." + }, + { + "name": "404", + "item": [ + { + "name": "Site does not exist", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"HTTP Status code must be 404\", function () {", + " pm.response.to.have.status(404);", + "});", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "{{serverURL}}/api/v1/contentreport/site/doesnotexist", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "contentreport", + "site", + "doesnotexist" + ] + }, + "description": "Generates a report using the Site Key." + }, + "response": [] + }, + { + "name": "Folder does not exist", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"HTTP Status code must be 404\", function () {", + " pm.response.to.have.status(404);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "{{serverURL}}/api/v1/contentreport/folder/12345", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "contentreport", + "folder", + "12345" + ] + }, + "description": "Generates a report using the Folder ID." + }, + "response": [] + }, + { + "name": "On folder site does not exist", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"HTTP Status code must be 404\", function () {", + " pm.response.to.have.status(404);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "{{serverURL}}/api/v1/contentreport/folder/{{testFolderId}}?site=doesnotexist", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "contentreport", + "folder", + "{{testFolderId}}" + ], + "query": [ + { + "key": "site", + "value": "doesnotexist" + } + ] + }, + "description": "Generates a report using the Folder ID." + }, + "response": [] + } + ] } ], "event": [ diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/FolderContentReport.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/FolderContentReport.java index 38dc6168d95d..f3482ce51f36 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/FolderContentReport.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/FolderContentReport.java @@ -4,6 +4,7 @@ import com.dotcms.util.pagination.ContentReportPaginator; import com.dotmarketing.beans.Host; import com.dotmarketing.business.APILocator; +import com.dotmarketing.exception.DoesNotExistException; import com.dotmarketing.exception.DotDataException; import com.dotmarketing.exception.DotSecurityException; import com.dotmarketing.portlets.contentlet.business.HostAPI; @@ -18,6 +19,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -51,10 +53,16 @@ public FolderContentReport(final User user) { @Override public List generateContentReport(final ContentReportParams params) throws DotDataException, DotSecurityException { final String folder = params.extraParam(ContentReportPaginator.FOLDER_PARAM); - final String site = params.extraParam(ContentReportPaginator.SITE_PARAM); - final Optional folderOpt = this.resolveFolder(folder, site, user); + final String siteId = params.extraParam(ContentReportPaginator.SITE_PARAM); + if (Objects.nonNull(siteId)) { + final Host site = this.siteAPI.get().find(siteId, params.user(), false); + if (null == site || UtilMethods.isNotSet(site.getIdentifier())) { + throw new DoesNotExistException("The site with the given ID does not exist: " + siteId); + } + } + final Optional folderOpt = this.resolveFolder(folder, siteId, user); if (folderOpt.isEmpty()) { - return List.of(); + throw new DoesNotExistException("The folder with the given ID or path does not exist: " + folder); } final List> contentReport = this.folderAPI.get().getContentReport(folderOpt.get(), params.orderBy(), diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/SiteContentReport.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/SiteContentReport.java index 6d015fbf00d5..628a35489788 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/SiteContentReport.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/SiteContentReport.java @@ -9,6 +9,7 @@ import com.dotmarketing.business.APILocator; import com.dotmarketing.business.DotStateException; import com.dotmarketing.common.util.SQLUtil; +import com.dotmarketing.exception.DoesNotExistException; import com.dotmarketing.exception.DotDataException; import com.dotmarketing.exception.DotSecurityException; import com.dotmarketing.portlets.contentlet.business.HostAPI; @@ -50,7 +51,7 @@ public List generateContentReport(final ContentReportParams p final String siteId = params.extraParam(ContentReportPaginator.SITE_PARAM); final Host site = this.siteAPI.get().find(siteId, params.user(), false); if (null == site || UtilMethods.isNotSet(site.getIdentifier())) { - return List.of(); + throw new DoesNotExistException("The site with the given ID does not exist: " + siteId); } final String orderByParam = SQLUtil.getOrderByAndDirectionSql(params.orderBy(), params.orderDirection());