diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/content/ContentAnalyticsResource.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/content/ContentAnalyticsResource.java index bc6395a5114..ee02c0e6d8a 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/content/ContentAnalyticsResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/content/ContentAnalyticsResource.java @@ -13,6 +13,7 @@ import com.dotcms.util.DotPreconditions; import com.dotmarketing.business.APILocator; import com.dotmarketing.util.Logger; +import com.dotmarketing.util.UUIDUtil; import com.google.common.annotations.VisibleForTesting; import com.liferay.portal.model.User; import io.swagger.v3.oas.annotations.Operation; @@ -31,6 +32,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import java.io.Serializable; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -49,7 +51,7 @@ description = "Endpoints that exposes information related to how dotCMS content is accessed and interacted with by users.") public class ContentAnalyticsResource { - private static final UserCustomDefinedRequestMatcher USER_CUSTOM_DEFINED_REQUEST_MATCHER = new UserCustomDefinedRequestMatcher() + private static final UserCustomDefinedRequestMatcher USER_CUSTOM_DEFINED_REQUEST_MATCHER = new UserCustomDefinedRequestMatcher(); private final WebResource webResource; private final ContentAnalyticsAPI contentAnalyticsAPI; @@ -207,7 +209,7 @@ public ReportResponseEntityView queryCubeJs(@Context final HttpServletRequest re @Operation( operationId = "fireUserCustomEvent", summary = "Fire an user custom event.", - description = "receives a custom event paylod and fires the event to the collectors", + description = "receives a custom event payload and fires the event to the collectors", tags = {"Content Analytics"}, responses = { @ApiResponse(responseCode = "200", description = "If the event was created successfully", @@ -240,7 +242,9 @@ public ResponseEntityStringView fireUserCustomEvent(@Context final HttpServletRe .init(); DotPreconditions.checkNotNull(userEventPayload, IllegalArgumentException.class, "The 'userEventPayload' JSON cannot be null"); + DotPreconditions.checkNotNull(userEventPayload.get("event_type"), IllegalArgumentException.class, "The 'event_type' field is required"); Logger.debug(this, ()->"Creating an user custom event with the payload: " + userEventPayload); + request.setAttribute("requestId", UUIDUtil.uuid()); WebEventsCollectorServiceFactory.getInstance().getWebEventsCollectorService().fireCollectorsAndEmitEvent(request, response, USER_CUSTOM_DEFINED_REQUEST_MATCHER, userEventPayload); return new ResponseEntityStringView("User event created successfully"); } diff --git a/dotcms-postman/src/main/resources/postman/Content_Analytics.postman_collection.json b/dotcms-postman/src/main/resources/postman/Content_Analytics.postman_collection.json index 8d505c8bf85..77197f1320e 100644 --- a/dotcms-postman/src/main/resources/postman/Content_Analytics.postman_collection.json +++ b/dotcms-postman/src/main/resources/postman/Content_Analytics.postman_collection.json @@ -1,11 +1,10 @@ { "info": { - "_postman_id": "e4fd950b-b8f4-4213-99a1-eb468e732dd6", + "_postman_id": "e003f644-856a-4639-ac55-dfbcd946bd4e", "name": "Content Analytics", "description": "Performs simple data validation for the Content Analytics REST Endpoint. It's very important to notice that, for the time being, the CICD instance does not start up any of the additional third-party tools required to actually run the Content Analytics feature.\n\nThis means that these test do not deal with retrieveing or saving data at all. It verifies that important/required information is present.", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "5403727", - "_collection_link": "https://cloudy-robot-285072.postman.co/workspace/JCastro-Workspace~5bfa586e-54db-429b-b7d5-c4ff997e3a0d/collection/5403727-e4fd950b-b8f4-4213-99a1-eb468e732dd6?action=share&source=collection_link&creator=5403727" + "_exporter_id": "781456" }, "item": [ { @@ -93,6 +92,121 @@ "response": [] } ] + }, + { + "name": "Events", + "item": [ + { + "name": "No Query Form on Event", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"HTTP Status code must be 400\", function () {", + " pm.response.to.have.status(400);", + "});", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/v1/analytics/content/event", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "analytics", + "content", + "event" + ] + } + }, + "response": [] + }, + { + "name": "EventType is must", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"HTTP Status code must be 400\", function () {", + " pm.response.to.have.status(400);", + "});", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"test\":\"test\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{serverURL}}/api/v1/analytics/content/event", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "analytics", + "content", + "event" + ] + } + }, + "response": [] + } + ] } ], "auth": {