Skip to content

Commit

Permalink
#30369 adding the custom user event
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms committed Oct 17, 2024
1 parent ccbf5ae commit 61158d2
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 61158d2

Please sign in to comment.