diff --git a/dotCMS/src/main/java/com/dotcms/rest/BundleResource.java b/dotCMS/src/main/java/com/dotcms/rest/BundleResource.java index a8323a1528e2..928cd3fc2a06 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/BundleResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/BundleResource.java @@ -54,8 +54,7 @@ import io.vavr.Tuple2; import io.vavr.control.Try; import java.io.Reader; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; import javax.ws.rs.QueryParam; import javax.ws.rs.core.StreamingOutput; @@ -85,11 +84,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URLDecoder; -import java.util.Date; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Locale; -import java.util.Set; import static com.dotcms.publisher.business.PublishAuditAPIImpl.NO_LIMIT_ASSETS; import static com.dotcms.publisher.business.PublishAuditStatus.Status.FAILED_TO_BUNDLE; @@ -374,7 +368,7 @@ public Response deleteEnvironmentPushHistory(@Context HttpServletRequest request @Produces("application/json") public Response deleteBundlesByIdentifiers(@Context final HttpServletRequest request, @Context final HttpServletResponse response, - final DeleteBundlesByIdentifierForm deleteBundlesByIdentifierForm) { + final DeleteBundlesByIdentifierForm deleteBundlesByIdentifierForm) throws DotDataException { final InitDataObject initData = new WebResource.InitBuilder(webResource) .requiredBackendUser(true) @@ -383,6 +377,10 @@ public Response deleteBundlesByIdentifiers(@Context final HttpServletRequest r .rejectWhenNoUser(true) .init(); + if (!UtilMethods.isSet(deleteBundlesByIdentifierForm) || !UtilMethods.isSet(deleteBundlesByIdentifierForm.getIdentifiers())) { + throw new IllegalArgumentException("List of body to delete is mandatory"); + } + Logger.info(this, "Deleting the bundles: " + deleteBundlesByIdentifierForm.getIdentifiers() + " by the user: " + initData.getUser().getUserId()); @@ -413,10 +411,48 @@ public Response deleteBundlesByIdentifiers(@Context final HttpServletRequest r } }); - return Response.ok(new ResponseEntityView( - "Removing bundles in a separated process, the result of the operation will be notified")).build(); + return buildResponseToDeleteEndpoint(deleteBundlesByIdentifierForm); } // deleteBundlesByIdentifiers. + private static Response buildResponseToDeleteEndpoint(final DeleteBundlesByIdentifierForm deleteBundlesByIdentifierForm) + throws DotDataException { + + final List existingBundles = new ArrayList<>(); + final List notExistingBundles = new ArrayList<>(); + + for (String identifier : deleteBundlesByIdentifierForm.getIdentifiers()) { + final Bundle bundleById = APILocator.getBundleAPI().getBundleById(identifier); + + if (UtilMethods.isSet(bundleById)) { + existingBundles.add(identifier); + } else { + notExistingBundles.add(identifier); + } + } + + final StringBuffer message = new StringBuffer(); + + if (!existingBundles.isEmpty()) { + message.append(String.format( + "Removing the follow bundles in a separated process, the result of the operation will be notified: %s", + existingBundles.stream().collect(Collectors.joining(", "))) + ); + } + + if (!existingBundles.isEmpty() && !notExistingBundles.isEmpty()) { + message.append(", "); + } + + if (!notExistingBundles.isEmpty()) { + message.append(String.format( + "The following bundles were not deleted because they don't exist: %s", + notExistingBundles.stream().collect(Collectors.joining(", "))) + ); + } + + return Response.ok(new ResponseEntityView(message)).build(); + } + private void sendErrorDeleteBundleMessage(final InitDataObject initData, final Locale locale, final Exception e) { diff --git a/dotcms-postman/src/main/resources/postman/Bundle_Resource.postman_collection.json b/dotcms-postman/src/main/resources/postman/Bundle_Resource.postman_collection.json index 0b54d118ac12..56eb4321b94f 100644 --- a/dotcms-postman/src/main/resources/postman/Bundle_Resource.postman_collection.json +++ b/dotcms-postman/src/main/resources/postman/Bundle_Resource.postman_collection.json @@ -1,9 +1,9 @@ { "info": { - "_postman_id": "ca8ea061-cf7f-411f-884b-f7f1235a6232", + "_postman_id": "dc421cae-0191-4998-953e-d7f51d601d2e", "name": "Bundle Resource", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "4500400" + "_exporter_id": "30436704" }, "item": [ { @@ -38,7 +38,6 @@ "header": [ { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", "type": "text" } @@ -84,10 +83,493 @@ "});", "", "pm.test(\"Valid response\", function () {", - " pm.expect(pm.response.text()).to.include(\"Removing bundles in a separated process\");", + " pm.expect(pm.response.text()).to.include(\"The following bundles were not deleted because they don't exist: n0ex1st-18c1-4eb0-815e-981619635532\");", "});", "" ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\n\t\"identifiers\":[\"n0ex1st-18c1-4eb0-815e-981619635532\"]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/bundle/ids", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "bundle", + "ids" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "existing bundle", + "item": [ + { + "name": "Create a Content Type", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = pm.response.json();", + "", + "", + "pm.test(\"Status code should be ok 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "pm.collectionVariables.set(\"contentTypeId\", jsonData.entity[0].id);", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "basic", + "basic": [ + { + "key": "password", + "value": "admin", + "type": "string" + }, + { + "key": "username", + "value": "admin@dotcms.com", + "type": "string" + } + ] + }, + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"defaultType\":false,\n \"icon\":null,\n \"fixed\":false,\n \"system\":false,\n \"clazz\":\"com.dotcms.contenttype.model.type.ImmutableSimpleContentType\",\n \"description\":\"\",\n \"host\":\"8a7d5e23-da1e-420a-b4f0-471e7da8ea2d\",\n \"folder\":\"SYSTEM_FOLDER\",\n \"name\":\"bundle removal contentlet type\",\n \"systemActionMappings\":{\"NEW\":\"\"},\n \"workflow\":[\"d61a59e1-a49c-46f2-a929-db2b4bfa88b2\"]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/v1/contenttype", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "contenttype" + ] + } + }, + "response": [] + }, + { + "name": "Add Field to Content Type", + "request": { + "auth": { + "type": "basic", + "basic": [ + { + "key": "password", + "value": "admin", + "type": "string" + }, + { + "key": "username", + "value": "admin@dotcms.com", + "type": "string" + } + ] + }, + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"layout\":[\n {\"divider\":{\n \"clazz\":\"com.dotcms.contenttype.model.field.ImmutableRowField\",\n \"contentTypeId\":\"{{contentTypeId}}\",\n \"dataType\":\"SYSTEM\",\n \"fieldContentTypeProperties\":[],\n \"fieldType\":\"Row\",\n \"fieldTypeLabel\":\"Row\",\n \"fieldVariables\":[],\n \"fixed\":false,\n \"iDate\":1667572217000,\n \"indexed\":false,\n \"listed\":false,\n \"modDate\":1667572217000,\n \"name\":\"Row Field\",\n \"readOnly\":false,\n \"required\":false,\n \"searchable\":false,\n \"sortOrder\":-1,\n \"unique\":false},\n \"columns\":[\n {\n \"columnDivider\":{\n \"clazz\":\"com.dotcms.contenttype.model.field.ImmutableColumnField\",\n \"contentTypeId\":\"{{contentTypeId}}\",\n \"dataType\":\"SYSTEM\",\n \"fieldContentTypeProperties\":[],\n \"fieldType\":\"Column\",\n \"fieldTypeLabel\":\"Column\",\n \"fieldVariables\":[],\n \"fixed\":false,\n \"iDate\":1667572217000,\n \"indexed\":false,\n \"listed\":false,\n \"modDate\":1667572217000,\n \"name\":\"Column Field\",\n \"readOnly\":false,\n \"required\":false,\n \"searchable\":false,\n \"sortOrder\":-1,\n \"unique\":false\n },\n \"fields\":[\n {\n \"clazz\":\"com.dotcms.contenttype.model.field.ImmutableTextField\",\n \"name\":\"title\",\n \"dataType\":\"TEXT\",\n \"regexCheck\":\"\",\n \"defaultValue\":\"\",\n \"hint\":\"\",\n \"required\":false,\n \"searchable\":false,\n \"indexed\":false,\n \"listed\":false,\n \"unique\":false,\n \"id\":null\n }\n ]\n }\n ]\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/v3/contenttype/{{contentTypeId}}/fields/move", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v3", + "contenttype", + "{{contentTypeId}}", + "fields", + "move" + ] + } + }, + "response": [] + }, + { + "name": "Create contentlet", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = pm.response.json();", + "", + "", + "pm.test(\"Status code should be ok 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "pm.collectionVariables.set(\"content1_id\", jsonData.entity.identifier);", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "basic", + "basic": [ + { + "key": "password", + "value": "admin", + "type": "string" + }, + { + "key": "username", + "value": "admin@dotcms.com", + "type": "string" + } + ] + }, + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{ \n \"contentlet\" : {\n \"title\" : \"content_1\",\n \"languageId\" : 1,\n \"stInode\": \"{{contentTypeId}}\"\n }\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/v1/workflow/actions/default/fire/PUBLISH", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "workflow", + "actions", + "default", + "fire", + "PUBLISH" + ] + } + }, + "response": [] + }, + { + "name": "Add Content type to Bundle", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Bundle uploaded sucessfully\", function () {", + " pm.response.to.have.status(200);", + "", + " var jsonData = pm.response.json();", + " pm.collectionVariables.set(\"bundleId\", jsonData[\"bundleId\"]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "basic", + "basic": [ + { + "key": "password", + "value": "admin", + "type": "string" + }, + { + "key": "username", + "value": "admin@dotcms.com", + "type": "string" + } + ] + }, + "method": "POST", + "header": [ + { + "key": "Origin", + "value": "{{serverURL}}", + "type": "text" + } + ], + "body": { + "mode": "formdata", + "formdata": [] + }, + "url": { + "raw": "{{serverURL}}/DotAjaxDirector/com.dotcms.publisher.ajax.RemotePublishAjaxAction/cmd/addToBundle?assetIdentifier={{contentTypeId}}&bundleName=test_bundle_removal_by_id", + "host": [ + "{{serverURL}}" + ], + "path": [ + "DotAjaxDirector", + "com.dotcms.publisher.ajax.RemotePublishAjaxAction", + "cmd", + "addToBundle" + ], + "query": [ + { + "key": "assetIdentifier", + "value": "{{contentTypeId}}" + }, + { + "key": "bundleName", + "value": "test_bundle_removal_by_id" + } + ] + } + }, + "response": [] + }, + { + "name": "Add Content to Bundle", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Bundle uploaded sucessfully\", function () {", + " pm.response.to.have.status(200);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "basic", + "basic": [ + { + "key": "password", + "value": "admin", + "type": "string" + }, + { + "key": "username", + "value": "admin@dotcms.com", + "type": "string" + } + ] + }, + "method": "POST", + "header": [ + { + "key": "Origin", + "value": "{{serverURL}}", + "type": "text" + } + ], + "body": { + "mode": "formdata", + "formdata": [] + }, + "url": { + "raw": "{{serverURL}}/DotAjaxDirector/com.dotcms.publisher.ajax.RemotePublishAjaxAction/cmd/addToBundle?assetIdentifier={{content1_id}}&bundleName=test_bundle_removal_by_id", + "host": [ + "{{serverURL}}" + ], + "path": [ + "DotAjaxDirector", + "com.dotcms.publisher.ajax.RemotePublishAjaxAction", + "cmd", + "addToBundle" + ], + "query": [ + { + "key": "assetIdentifier", + "value": "{{content1_id}}" + }, + { + "key": "bundleName", + "value": "test_bundle_removal_by_id" + } + ] + } + }, + "response": [] + }, + { + "name": "Delete Bundle", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code should be 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "var bundleId = pm.collectionVariables.get(\"bundleId\");", + "", + "pm.test(\"Valid response\", function () {", + " pm.expect(pm.response.text()).to.include(\"Removing the follow bundles in a separated process, the result of the operation will be notified: \" + bundleId);", + "});", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "auth": { + "type": "basic", + "basic": [ + { + "key": "username", + "value": "admin@dotcms.com", + "type": "string" + }, + { + "key": "password", + "value": "admin", + "type": "string" + } + ] + }, + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\n\t\"identifiers\":[\"{{bundleId}}\"]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/bundle/ids", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "bundle", + "ids" + ] + } + }, + "response": [] + }, + { + "name": "Check removed bundle", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var expectedHttpStatus = 404;", + "var maxNumberOfTries = 5;", + "var sleepBetweenTries = 500;", + "", + "if (!pm.collectionVariables.get(\"getBundleTries\")) {", + " pm.collectionVariables.set(\"getBundleTries\", 1);", + "}", + "", + "if ((pm.response.code != expectedHttpStatus) && (pm.collectionVariables.get(\"getBundleTries\") < maxNumberOfTries)) {", + " var tries = parseInt(pm.collectionVariables.get(\"getBundleTries\"), 10);", + " pm.collectionVariables.set(\"getBundleTries\", tries + 1);", + " setTimeout(function() {}, sleepBetweenTries);", + " postman.setNextRequest(\"Check removed bundle\");", + " } else {", + " pm.collectionVariables.unset(\"getBundleTries\");", + " pm.test(\"Status code for get bundle is \" + expectedHttpStatus, function () {", + " pm.response.to.have.status(expectedHttpStatus);", + " });", + "}", + "" + ], "type": "text/javascript" } } @@ -97,44 +579,29 @@ "type": "basic", "basic": [ { - "key": "username", - "value": "admin@dotcms.com", + "key": "password", + "value": "admin", "type": "string" }, { - "key": "password", - "value": "admin", + "key": "username", + "value": "admin@dotcms.com", "type": "string" } ] }, - "method": "DELETE", - "header": [ - { - "key": "Content-Type", - "name": "Content-Type", - "value": "application/json", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n\t\n\t\"identifiers\":[\"n0ex1st-18c1-4eb0-815e-981619635532\"]\n}", - "options": { - "raw": { - "language": "json" - } - } - }, + "method": "GET", + "header": [], "url": { - "raw": "{{serverURL}}/api/bundle/ids", + "raw": "{{serverURL}}/api/bundle/{{bundleId}}/assets", "host": [ "{{serverURL}}" ], "path": [ "api", "bundle", - "ids" + "{{bundleId}}", + "assets" ] } }, @@ -143,7 +610,7 @@ ] }, { - "name": "existing bundle", + "name": "existing and not existing bundle", "item": [ { "name": "Create a Content Type", @@ -163,22 +630,18 @@ "", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], "request": { "auth": { - "type": "basic", - "basic": [ - { - "key": "password", - "value": "admin", - "type": "string" - }, + "type": "bearer", + "bearer": [ { - "key": "username", - "value": "admin@dotcms.com", + "key": "token", + "value": "{{jwt}}", "type": "string" } ] @@ -212,16 +675,11 @@ "name": "Add Field to Content Type", "request": { "auth": { - "type": "basic", - "basic": [ - { - "key": "password", - "value": "admin", - "type": "string" - }, + "type": "bearer", + "bearer": [ { - "key": "username", - "value": "admin@dotcms.com", + "key": "token", + "value": "{{jwt}}", "type": "string" } ] @@ -272,22 +730,18 @@ "", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], "request": { "auth": { - "type": "basic", - "basic": [ - { - "key": "password", - "value": "admin", - "type": "string" - }, + "type": "bearer", + "bearer": [ { - "key": "username", - "value": "admin@dotcms.com", + "key": "token", + "value": "{{jwt}}", "type": "string" } ] @@ -330,7 +784,8 @@ "exec": [ "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } }, { @@ -344,22 +799,18 @@ " pm.collectionVariables.set(\"bundleId\", jsonData[\"bundleId\"]);", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], "request": { "auth": { - "type": "basic", - "basic": [ - { - "key": "password", - "value": "admin", - "type": "string" - }, + "type": "bearer", + "bearer": [ { - "key": "username", - "value": "admin@dotcms.com", + "key": "token", + "value": "{{jwt}}", "type": "string" } ] @@ -368,8 +819,8 @@ "header": [ { "key": "Origin", - "type": "text", - "value": "{{serverURL}}" + "value": "{{serverURL}}", + "type": "text" } ], "body": { @@ -410,7 +861,8 @@ "exec": [ "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } }, { @@ -421,22 +873,18 @@ " pm.response.to.have.status(200);", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], "request": { "auth": { - "type": "basic", - "basic": [ - { - "key": "password", - "value": "admin", - "type": "string" - }, + "type": "bearer", + "bearer": [ { - "key": "username", - "value": "admin@dotcms.com", + "key": "token", + "value": "{{jwt}}", "type": "string" } ] @@ -445,8 +893,8 @@ "header": [ { "key": "Origin", - "type": "text", - "value": "{{serverURL}}" + "value": "{{serverURL}}", + "type": "text" } ], "body": { @@ -489,27 +937,25 @@ " pm.response.to.have.status(200);", "});", "", + "var bundleId = pm.collectionVariables.get(\"bundleId\");", + "", "pm.test(\"Valid response\", function () {", - " pm.expect(pm.response.text()).to.include(\"Removing bundles in a separated process\");", + " pm.expect(pm.response.text()).to.include('Removing the follow bundles in a separated process, the result of the operation will be notified: ' + bundleId + \", The following bundles were not deleted because they don't exist: n0ex1st-18c1-4eb0-815e-981619635532\");", "});", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], "request": { "auth": { - "type": "basic", - "basic": [ - { - "key": "username", - "value": "admin@dotcms.com", - "type": "string" - }, + "type": "bearer", + "bearer": [ { - "key": "password", - "value": "admin", + "key": "token", + "value": "{{jwt}}", "type": "string" } ] @@ -518,14 +964,13 @@ "header": [ { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", "type": "text" } ], "body": { "mode": "raw", - "raw": "{\n\t\n\t\"identifiers\":[\"{{bundleId}}\"]\n}", + "raw": "{\n\t\n\t\"identifiers\":[\"{{bundleId}}\", \"n0ex1st-18c1-4eb0-815e-981619635532\"]\n}", "options": { "raw": { "language": "json" @@ -574,22 +1019,18 @@ "}", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], "request": { "auth": { - "type": "basic", - "basic": [ - { - "key": "password", - "value": "admin", - "type": "string" - }, + "type": "bearer", + "bearer": [ { - "key": "username", - "value": "admin@dotcms.com", + "key": "token", + "value": "{{jwt}}", "type": "string" } ] @@ -612,6 +1053,137 @@ "response": [] } ] + }, + { + "name": "empty_body", + "item": [ + { + "name": "Delete Bundle With empty body", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code should be 400\", function () {", + " pm.response.to.have.status(400);", + "});", + "", + "pm.test(\"Valid response\", function () {", + " pm.expect(pm.response.text()).to.include(\"List of body to delete is mandatory\");", + "});", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/bundle/ids", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "bundle", + "ids" + ] + } + }, + "response": [] + }, + { + "name": "Delete Bundle With empty identifiers list", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code should be 400\", function () {", + " pm.response.to.have.status(400);", + "});", + "", + "pm.test(\"Valid response\", function () {", + " pm.expect(pm.response.text()).to.include(\"List of body to delete is mandatory\");", + "});", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\n\t\"identifiers\":[]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/bundle/ids", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "bundle", + "ids" + ] + } + }, + "response": [] + } + ] } ], "description": "Path: /api/bundle/ids", @@ -1302,13 +1874,13 @@ "header": [ { "key": "Content-Type", - "type": "text", - "value": "application/octet-stream" + "value": "application/octet-stream", + "type": "text" }, { "key": "Content-Disposition", - "type": "text", - "value": "attachment" + "value": "attachment", + "type": "text" } ], "body": { @@ -1382,13 +1954,13 @@ "header": [ { "key": "Content-Type", - "type": "text", - "value": "application/octet-stream" + "value": "application/octet-stream", + "type": "text" }, { "key": "Content-Disposition", - "type": "text", - "value": "attachment" + "value": "attachment", + "type": "text" } ], "body": { @@ -1451,13 +2023,13 @@ "header": [ { "key": "Content-Type", - "type": "text", - "value": "application/octet-stream" + "value": "application/octet-stream", + "type": "text" }, { "key": "Content-Disposition", - "type": "text", - "value": "attachment" + "value": "attachment", + "type": "text" } ], "url": { @@ -1524,13 +2096,13 @@ "header": [ { "key": "Content-Type", - "type": "text", - "value": "application/octet-stream" + "value": "application/octet-stream", + "type": "text" }, { "key": "Content-Disposition", - "type": "text", - "value": "attachment" + "value": "attachment", + "type": "text" } ], "body": { @@ -1730,13 +2302,13 @@ "header": [ { "key": "Content-Type", - "type": "text", - "value": "application/octet-stream" + "value": "application/octet-stream", + "type": "text" }, { "key": "Content-Disposition", - "type": "text", - "value": "attachment" + "value": "attachment", + "type": "text" } ], "body": { @@ -1898,8 +2470,8 @@ "header": [ { "key": "Origin", - "type": "text", - "value": "{{serverURL}}" + "value": "{{serverURL}}", + "type": "text" } ], "body": { @@ -1977,8 +2549,8 @@ "header": [ { "key": "Origin", - "type": "text", - "value": "{{serverURL}}" + "value": "{{serverURL}}", + "type": "text" } ], "body": { @@ -2057,8 +2629,8 @@ "header": [ { "key": "Origin", - "type": "text", - "value": "{{serverURL}}" + "value": "{{serverURL}}", + "type": "text" } ], "body": { @@ -2137,8 +2709,8 @@ "header": [ { "key": "Origin", - "type": "text", - "value": "{{serverURL}}" + "value": "{{serverURL}}", + "type": "text" } ], "body": { @@ -2361,6 +2933,67 @@ ] } ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "packages": {}, + "exec": [ + " const serverURL = pm.environment.get('serverURL'); // Get the server URL from the environment variable", + " const apiUrl = `${serverURL}/api/v1/apitoken`; // Construct the full API URL", + "", + "// If we are unable to get the JWT we need to generate a new one", + " if (!pm.environment.get('jwt')) {", + " const username = pm.environment.get(\"user\");", + " const password = pm.environment.get(\"password\");", + " const basicAuth = Buffer.from(`${username}:${password}`).toString('base64');", + "", + "", + " const requestOptions = {", + " url: apiUrl,", + " method: \"POST\",", + " header: {", + " \"accept\": \"*/*\",", + " \"content-type\": \"application/json\",", + " \"Authorization\": `Basic ${basicAuth}`", + " },", + " body: {", + " mode: \"raw\",", + " raw: JSON.stringify({", + " \"expirationSeconds\": 7200,", + " \"userId\": \"dotcms.org.1\",", + " \"network\": \"0.0.0.0/0\",", + " \"claims\": {\"label\": \"postman-tests\"}", + " })", + " }", + " };", + "", + "", + " pm.sendRequest(requestOptions, function (err, response) {", + " if (err) {", + " console.log(err);", + " } else {", + " const jwt = response.json().entity.jwt;", + " pm.environment.set('jwt', jwt);", + " console.log(jwt);", + " }", + " });", + " }" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "packages": {}, + "exec": [ + "" + ] + } + } + ], "variable": [ { "key": "bundleName",