Skip to content

Commit

Permalink
chore(core): Endpoint for Content Reporting #27755 (#28080)
Browse files Browse the repository at this point in the history
* #27755 fixes

* #27755 adding postman test

* #27755 adding a case

---------

Co-authored-by: Freddy Montes <[email protected]>
  • Loading branch information
jdotcms and fmontes authored Apr 16, 2024
1 parent e3d8121 commit 4898cb1
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 6 deletions.
154 changes: 152 additions & 2 deletions dotCMS/src/curl-test/Content_Report_Resource.postman_collection.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -51,10 +53,16 @@ public FolderContentReport(final User user) {
@Override
public List<ContentReportView> 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<Folder> 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<Folder> 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<Map<String, Object>> contentReport =
this.folderAPI.get().getContentReport(folderOpt.get(), params.orderBy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,7 +51,7 @@ public List<ContentReportView> 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());
Expand Down

0 comments on commit 4898cb1

Please sign in to comment.