From 7e1ea558ade4929b9cde190988beb1b2c1025174 Mon Sep 17 00:00:00 2001 From: jdotcms Date: Tue, 26 Nov 2024 15:49:43 -0600 Subject: [PATCH 1/8] #30411 first shot with some addition and name refactoring --- .../collectors/AsyncVanitiesCollector.java | 2 +- .../analytics/track/collectors/Collector.java | 48 ++++++++++++------- .../track/collectors/CollectorContextMap.java | 1 + .../collectors/CustomerEventCollector.java | 4 +- .../track/collectors/FilesCollector.java | 8 +++- .../track/collectors/PageDetailCollector.java | 6 ++- .../track/collectors/PagesCollector.java | 5 +- .../collectors/SyncVanitiesCollector.java | 8 ++-- 8 files changed, 51 insertions(+), 31 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollector.java index 0b35afaa977d..813f5ce78f11 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollector.java @@ -63,7 +63,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa if (UtilMethods.isSet(whoIAM)) { final CollectorContextMap innerCollectorContextMap = new WrapperCollectorContextMap(collectorContextMap, - Map.of("uri", cachedVanityUrl.forwardTo)); + Map.of(URL, cachedVanityUrl.forwardTo)); match.get(whoIAM).collect(innerCollectorContextMap, collectorPayloadBean); } diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/Collector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/Collector.java index 879d8752f5df..cf481099d078 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/Collector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/Collector.java @@ -18,37 +18,51 @@ */ public interface Collector { - String CLUSTER = "cluster"; - String COME_FROM_VANITY_URL = "comeFromVanityURL"; - String CONTENT_TYPE_ID = "content_type_id"; - String CONTENT_TYPE_NAME = "content_type_name"; - String CONTENT_TYPE_VAR_NAME = "content_type_var_name"; - String DETAIL_PAGE_URL = "detail_page_url"; + String ID = "identifier"; + String TITLE = "title"; + String INODE = "inode"; // NOT USED YET BUT MAY BE DESIRED + String BASE_TYPE = "baseType"; + String PATH = "path"; // NOT USED YET BUT MAY BE DESIRED + String LIVE = "live"; // NOT USED YET BUT MAY BE DESIRED + String WORKING = "working"; // NOT USED YET BUT MAY BE DESIRED + String CONTENT_TYPE_VAR_NAME = "contentType"; + String CONTENT_TYPE_NAME = "contentTypeName"; + String CONTENT_TYPE_ID = "contentTypeId"; + String SITE_ID = "conHost"; + String SITE_NAME = "conHostName"; + String LANGUAGE_ID = "languageId"; + String LANGUAGE = "language"; + String EVENT_SOURCE = "event_source"; String EVENT_TYPE = "event_type"; - String HOST = "host"; - String ID = "id"; - String IS_EXPERIMENT_PAGE = "isexperimentpage"; - String IS_TARGET_PAGE = "istargetpage"; - String LANGUAGE = "language"; - String LANGUAGE_ID = "language_id"; + String CLUSTER = "cluster"; String OBJECT = "object"; String PERSONA = "persona"; String REFERER = "referer"; - String RENDER_MODE = "renderMode"; String REQUEST_ID = "request_id"; - String RESPONSE = "response"; - String RESPONSE_CODE = "response_code"; String SERVER = "server"; String SESSION_ID = "sessionId"; String SESSION_NEW = "sessionNew"; - String SITE = "site"; - String TITLE = "title"; String URL = "url"; String USER_AGENT = "userAgent"; String UTC_TIME = "utc_time"; + + + String RENDER_MODE = "renderMode"; + String RESPONSE = "response"; + String RESPONSE_CODE = "response_code"; + + + String COME_FROM_VANITY_URL = "comeFromVanityURL"; + String DETAIL_PAGE_URL = "detail_page_url"; + String IS_EXPERIMENT_PAGE = "isexperimentpage"; + String IS_TARGET_PAGE = "istargetpage"; + + String VANITY_QUERY_STRING = "vanity_query_string"; + String VANITY_URL_KEY = "vanity_url"; + String FORWARD_TO = "forwardTo"; /** * Test if the collector should run * @param collectorContextMap diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CollectorContextMap.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CollectorContextMap.java index 57a932d0d927..6e0497e483e2 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CollectorContextMap.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CollectorContextMap.java @@ -5,6 +5,7 @@ public interface CollectorContextMap { String REQUEST_ID = "requestId"; + String REQUEST = "request"; String TIME = "time"; String CLUSTER = "cluster"; String SERVER = "server"; diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CustomerEventCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CustomerEventCollector.java index c4f503c9db3f..64628e4d464f 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CustomerEventCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CustomerEventCollector.java @@ -27,9 +27,9 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa final Host site = (Host) collectorContextMap.get(CollectorContextMap.CURRENT_HOST); final String language = (String)collectorContextMap.get(CollectorContextMap.LANG); collectorPayloadBean.put(URL, uri); - collectorPayloadBean.put(HOST, Objects.nonNull(site)?site.getHostname():host); + collectorPayloadBean.put(SITE_NAME, Objects.nonNull(site)?site.getHostname():host); collectorPayloadBean.put(LANGUAGE, language); - collectorPayloadBean.put(SITE, null != site?site.getIdentifier():StringPool.UNKNOWN); + collectorPayloadBean.put(SITE_ID, null != site?site.getIdentifier():StringPool.UNKNOWN); final String eventType = collectorContextMap.get(CollectorContextMap.EVENT_TYPE) == null? EventType.CUSTOM_USER_EVENT.getType():(String)collectorContextMap.get(CollectorContextMap.EVENT_TYPE); collectorPayloadBean.put(EVENT_TYPE, eventType); diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java index 5dd95ee8257d..49ecd2ff92f5 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java @@ -57,14 +57,18 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa fileObject.put(ID, fileAsset.getIdentifier()); fileObject.put(TITLE, fileAsset.getTitle()); fileObject.put(URL, uri); + fileObject.put(CONTENT_TYPE_ID, fileAsset.getContentType().id()); + fileObject.put(CONTENT_TYPE_NAME, fileAsset.getContentType().name()); + fileObject.put(CONTENT_TYPE_VAR_NAME, fileAsset.getContentType().variable()); + fileObject.put(BASE_TYPE, fileAsset.getContentType().baseType().name()); }); } collectorPayloadBean.put(OBJECT, fileObject); collectorPayloadBean.put(URL, uri); - collectorPayloadBean.put(HOST, Objects.nonNull(site)?site.getHostname():host); + collectorPayloadBean.put(SITE_NAME, Objects.nonNull(site)?site.getHostname():host); collectorPayloadBean.put(LANGUAGE, language); - collectorPayloadBean.put(SITE, null != site?site.getIdentifier():StringPool.UNKNOWN); + collectorPayloadBean.put(SITE_ID, null != site?site.getIdentifier():StringPool.UNKNOWN); collectorPayloadBean.put(EVENT_TYPE, EventType.FILE_REQUEST.getType()); return collectorPayloadBean; diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java index 2469f671d337..4acfede47cbd 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java @@ -78,6 +78,10 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa pageObject.put(ID, detailPageContent.getIdentifier()); pageObject.put(TITLE, detailPageContent.getTitle()); pageObject.put(URL, uri); + pageObject.put(CONTENT_TYPE_ID, urlMapContentlet.getContentType().id()); + pageObject.put(CONTENT_TYPE_NAME, urlMapContentlet.getContentType().name()); + pageObject.put(CONTENT_TYPE_VAR_NAME, urlMapContentlet.getContentType().variable()); + pageObject.put(BASE_TYPE, urlMapContentlet.getContentType().baseType().name()); pageObject.put(DETAIL_PAGE_URL, Try.of(detailPageContent::getURI).getOrElse(StringPool.BLANK)); collectorPayloadBean.put(OBJECT, pageObject); } @@ -87,7 +91,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa collectorPayloadBean.put(LANGUAGE, language); if (Objects.nonNull(site)) { - collectorPayloadBean.put(HOST, site.getHostname()); + collectorPayloadBean.put(SITE_NAME, site.getHostname()); } return collectorPayloadBean; } diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java index 90c4c6e55b01..6fef01620651 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java @@ -75,6 +75,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa pageObject.put(CONTENT_TYPE_ID, urlMapContentType.id()); pageObject.put(CONTENT_TYPE_NAME, urlMapContentType.name()); pageObject.put(CONTENT_TYPE_VAR_NAME, urlMapContentType.variable()); + pageObject.put(BASE_TYPE, urlMapContentType.baseType().name()); collectorPayloadBean.put(EVENT_TYPE, EventType.URL_MAP.getType()); } } else { @@ -83,8 +84,6 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa pageObject.put(ID, page.getIdentifier()); pageObject.put(TITLE, page.getTitle()); collectorPayloadBean.put(EVENT_TYPE, EventType.PAGE_REQUEST.getType()); - pageObject.put("id", page.getIdentifier()); - pageObject.put("title", page.getTitle()); } pageObject.put(URL, uri); } @@ -94,7 +93,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa collectorPayloadBean.put(LANGUAGE, language); if (Objects.nonNull(site)) { - collectorPayloadBean.put(HOST, site.getHostname()); + collectorPayloadBean.put(SITE_NAME, site.getHostname()); } return collectorPayloadBean; diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollector.java index 4f3e3dd1471a..42632afd3305 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollector.java @@ -17,8 +17,6 @@ */ public class SyncVanitiesCollector implements Collector { - public static final String VANITY_URL_KEY = "vanity_url"; - public static final String FORWARD_TO = "forward_to"; public SyncVanitiesCollector() { } @@ -32,9 +30,9 @@ public boolean test(CollectorContextMap collectorContextMap) { @Override public CollectorPayloadBean collect(final CollectorContextMap collectorContextMap, final CollectorPayloadBean collectorPayloadBean) { - if (null != collectorContextMap.get("request")) { + if (null != collectorContextMap.get(CollectorContextMap.REQUEST)) { - final HttpServletRequest request = (HttpServletRequest)collectorContextMap.get("request"); + final HttpServletRequest request = (HttpServletRequest)collectorContextMap.get(CollectorContextMap.REQUEST); final String vanityUrl = (String)request.getAttribute(Constants.CMS_FILTER_URI_OVERRIDE); final String vanityQueryString = (String)request.getAttribute(Constants.CMS_FILTER_QUERY_STRING_OVERRIDE); if (request instanceof VanityUrlRequestWrapper) { @@ -66,7 +64,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa collectorPayloadBean.put(URL, uri); collectorPayloadBean.put(LANGUAGE, language); collectorPayloadBean.put(LANGUAGE_ID, languageId); - collectorPayloadBean.put(SITE, site.getIdentifier()); + collectorPayloadBean.put(SITE_ID, site.getIdentifier()); collectorPayloadBean.put(EVENT_TYPE, EventType.VANITY_REQUEST.getType()); return collectorPayloadBean; From 6ba6527ec1a9a59e4ff6f683199e8c538fea98a0 Mon Sep 17 00:00:00 2001 From: jdotcms Date: Tue, 26 Nov 2024 16:13:00 -0600 Subject: [PATCH 2/8] #30411 first shot with some addition and name refactoring --- .../track/collectors/BasicProfileCollector.java | 17 +++++++++++++++++ .../analytics/track/collectors/Collector.java | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java index 84723f0c5bb8..e36bbf34d507 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java @@ -6,6 +6,7 @@ import com.dotmarketing.business.web.WebAPILocator; import com.dotmarketing.util.PageMode; import com.dotmarketing.util.UtilMethods; +import com.liferay.portal.model.User; import com.liferay.util.StringPool; import javax.servlet.http.HttpServletRequest; @@ -13,6 +14,8 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; /** @@ -78,9 +81,23 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa collectorPayloadBean.put(EVENT_SOURCE, EventSource.DOT_CMS.getName()); } + setUserInfo(request, collectorPayloadBean); + return collectorPayloadBean; } + private void setUserInfo(final HttpServletRequest request, final CollectorPayloadBean collectorPayloadBean) { + + final User user = WebAPILocator.getUserWebAPI().getUser(request); + if (Objects.nonNull(user)) { + + final HashMap userObject = new HashMap<>(); + userObject.put(ID, user.getUserId().toString()); + userObject.put(EMAIL, user.getEmailAddress()); + collectorPayloadBean.put(USER_OBJECT, userObject); + } + } + @Override public boolean isEventCreator(){ return false; diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/Collector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/Collector.java index cf481099d078..f6437c0dee41 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/Collector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/Collector.java @@ -57,12 +57,12 @@ public interface Collector { String DETAIL_PAGE_URL = "detail_page_url"; String IS_EXPERIMENT_PAGE = "isexperimentpage"; String IS_TARGET_PAGE = "istargetpage"; - - String VANITY_QUERY_STRING = "vanity_query_string"; - String VANITY_URL_KEY = "vanity_url"; String FORWARD_TO = "forwardTo"; + + String EMAIL = "email"; + String USER_OBJECT = "user"; /** * Test if the collector should run * @param collectorContextMap From 1ff54d8fda03bbc6e0bda7a1ab6157c2186827cc Mon Sep 17 00:00:00 2001 From: jdotcms Date: Wed, 27 Nov 2024 15:34:58 -0600 Subject: [PATCH 3/8] #30411 adding last renames --- .../analytics/track/collectors/BasicProfileCollector.java | 2 -- .../com/dotcms/analytics/track/collectors/FilesCollector.java | 3 +++ .../dotcms/analytics/track/collectors/PageDetailCollector.java | 2 ++ .../com/dotcms/analytics/track/collectors/PagesCollector.java | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java index e36bbf34d507..8d5d5c4e53a4 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java @@ -69,8 +69,6 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa collectorPayloadBean.put(PERSONA, WebAPILocator.getPersonalizationWebAPI().getContainerPersonalization(request)); - collectorPayloadBean.put(RENDER_MODE, PageMode.get(request).toString().replace("_MODE", StringPool.BLANK)); - // Include default value for other boolean fields in the Clickhouse table collectorPayloadBean.put(COME_FROM_VANITY_URL, false); collectorPayloadBean.put(IS_EXPERIMENT_PAGE, false); diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java index 49ecd2ff92f5..571be4f7d7ef 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java @@ -9,6 +9,7 @@ import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.fileassets.business.FileAssetAPI; import com.liferay.util.StringPool; +import io.vavr.control.Try; import java.util.HashMap; import java.util.Objects; @@ -61,6 +62,8 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa fileObject.put(CONTENT_TYPE_NAME, fileAsset.getContentType().name()); fileObject.put(CONTENT_TYPE_VAR_NAME, fileAsset.getContentType().variable()); fileObject.put(BASE_TYPE, fileAsset.getContentType().baseType().name()); + fileObject.put(LIVE, String.valueOf(Try.of(()->fileAsset.isLive()).getOrElse(false))); + fileObject.put(WORKING, String.valueOf(Try.of(()->fileAsset.isWorking()).getOrElse(false))); }); } diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java index 4acfede47cbd..370aa5182821 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java @@ -82,6 +82,8 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa pageObject.put(CONTENT_TYPE_NAME, urlMapContentlet.getContentType().name()); pageObject.put(CONTENT_TYPE_VAR_NAME, urlMapContentlet.getContentType().variable()); pageObject.put(BASE_TYPE, urlMapContentlet.getContentType().baseType().name()); + pageObject.put(LIVE, String.valueOf(Try.of(()->urlMapContentlet.isLive()).getOrElse(false))); + pageObject.put(WORKING, String.valueOf(Try.of(()->urlMapContentlet.isWorking()).getOrElse(false))); pageObject.put(DETAIL_PAGE_URL, Try.of(detailPageContent::getURI).getOrElse(StringPool.BLANK)); collectorPayloadBean.put(OBJECT, pageObject); } diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java index 6fef01620651..b550b86dc816 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java @@ -76,6 +76,8 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa pageObject.put(CONTENT_TYPE_NAME, urlMapContentType.name()); pageObject.put(CONTENT_TYPE_VAR_NAME, urlMapContentType.variable()); pageObject.put(BASE_TYPE, urlMapContentType.baseType().name()); + pageObject.put(LIVE, String.valueOf(Try.of(()->urlMapContentlet.isLive()).getOrElse(false))); + pageObject.put(WORKING, String.valueOf(Try.of(()->urlMapContentlet.isWorking()).getOrElse(false))); collectorPayloadBean.put(EVENT_TYPE, EventType.URL_MAP.getType()); } } else { From 783a7d82c65307c6709f6f7aa5e4e021698c0f44 Mon Sep 17 00:00:00 2001 From: jdotcms Date: Fri, 29 Nov 2024 14:00:01 -0600 Subject: [PATCH 4/8] #30411 adding fixes for it test --- .../collectors/PageDetailCollectorTest.java | 27 ++++--- .../track/collectors/PagesCollectorTest.java | 54 ++++++++----- .../collectors/SyncVanitiesCollectorTest.java | 22 +++--- .../WebEventsCollectorServiceImplTest.java | 76 +++++++++++-------- 4 files changed, 107 insertions(+), 72 deletions(-) diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java index a03992d5450b..e0dbd6fa32f2 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java @@ -11,6 +11,7 @@ import com.dotmarketing.beans.Host; import com.dotmarketing.business.APILocator; import com.dotmarketing.exception.DotDataException; +import com.dotmarketing.exception.DotSecurityException; import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.contentlet.model.IndexPolicy; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; @@ -70,7 +71,7 @@ public static void prepare() throws Exception { * */ @Test - public void testPageDetailCollector() throws DotDataException, UnknownHostException { + public void testPageDetailCollector() throws DotDataException, UnknownHostException, DotSecurityException { final HttpServletResponse response = mock(HttpServletResponse.class); final String requestId = UUIDUtil.uuid(); final HttpServletRequest request = Util.mockHttpRequestObj(response, @@ -100,15 +101,21 @@ public void testPageDetailCollector() throws DotDataException, UnknownHostExcept ContentletDataGen.publish(newsTestContent); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "language", language.getIsoCode(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "object", Map.of( - "id", testDetailPage.getIdentifier(), - "title", testDetailPage.getTitle(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "detail_page_url", testDetailPage.getURI()) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.LANGUAGE, language.getIsoCode(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testDetailPage.getIdentifier(), + Collector.TITLE, testDetailPage.getTitle(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.CONTENT_TYPE_ID, testDetailPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testDetailPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testDetailPage.getContentType().variable(), + Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), + Collector.LIVE, testDetailPage.isLive(), + Collector.WORKING, testDetailPage.isWorking(), + Collector.DETAIL_PAGE_URL, testDetailPage.getURI()) ); final Collector collector = new PageDetailCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java index 934269c23996..515880d80e2e 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java @@ -73,7 +73,7 @@ public static void prepare() throws Exception { * */ @Test - public void collectPageData() throws DotDataException, UnknownHostException { + public void collectPageData() throws Exception { final HttpServletResponse response = mock(HttpServletResponse.class); final String requestId = UUIDUtil.uuid(); final HttpServletRequest request = Util.mockHttpRequestObj(response, TEST_PAGE_URL, @@ -82,14 +82,21 @@ public void collectPageData() throws DotDataException, UnknownHostException { final HTMLPageAsset testPage = Util.createTestHTMLPage(testSite, TEST_PAGE_NAME); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), - "url", TEST_PAGE_URL, - "object", Map.of( - "id", testPage.getIdentifier(), - "title", testPage.getTitle(), - "url", testPage.getURI()) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.LANGUAGE, APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), + Collector.URL, TEST_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testPage.getIdentifier(), + Collector.TITLE, testPage.getTitle(), + Collector.URL, TEST_PAGE_URL, + Collector.CONTENT_TYPE_ID, testPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testPage.getContentType().variable(), + Collector.BASE_TYPE, testPage.getContentType().baseType().name(), + Collector.LIVE, testPage.isLive(), + Collector.WORKING, testPage.isWorking(), + Collector.DETAIL_PAGE_URL, testPage.getURI()) ); final Collector collector = new PagesCollector(); @@ -116,7 +123,7 @@ public void collectPageData() throws DotDataException, UnknownHostException { * */ @Test - public void collectUrlMapPageData() throws DotDataException, UnknownHostException { + public void collectUrlMapPageData() throws Exception { final HttpServletResponse response = mock(HttpServletResponse.class); final String requestId = UUIDUtil.uuid(); final HttpServletRequest request = Util.mockHttpRequestObj(response, @@ -148,17 +155,22 @@ public void collectUrlMapPageData() throws DotDataException, UnknownHostExceptio ContentletDataGen.publish(newsTestContent); final Map expectedDataMap = Map.of( - "event_type", EventType.URL_MAP.getType(), - "host", testSite.getHostname(), - "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "object", Map.of( - "content_type_var_name", urlMappedContentType.variable(), - "content_type_id", urlMappedContentType.id(), - "id", newsTestContent.getIdentifier(), - "content_type_name", urlMappedContentType.name(), - "title", urlTitle, - "url", TEST_URL_MAP_DETAIL_PAGE_URL) + Collector.EVENT_TYPE, EventType.URL_MAP.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.LANGUAGE, APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, newsTestContent.getIdentifier(), + Collector.TITLE, urlTitle, + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.CONTENT_TYPE_ID, urlMappedContentType.id(), + Collector.CONTENT_TYPE_NAME, urlMappedContentType.name(), + Collector.CONTENT_TYPE_VAR_NAME, urlMappedContentType.variable(), + Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), + Collector.LIVE, newsTestContent.isLive(), + Collector.WORKING, newsTestContent.isWorking(), + Collector.DETAIL_PAGE_URL, testDetailPage.getURI() + ) ); final Collector collector = new PagesCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java index 636e6cbfe1ab..c0bcb1f3c993 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java @@ -87,17 +87,17 @@ public void collectSyncVanityData() throws DotDataException, IOException, DotSec assertTrue("Resolved vanity url must be present", resolvedVanity.isPresent()); final Map expectedDataMap = Map.of( - "site", testSite.getIdentifier(), - "event_type", EventType.VANITY_REQUEST.getType(), - "language", defaultLanguage.getIsoCode(), - "vanity_url", TEST_PAGE_URL, - "language_id", defaultLanguage.getId(), - "url", URI, - "object", Map.of( - "forward_to", TEST_PAGE_URL, - "response", "200", - "id", resolvedVanity.get().vanityUrlId, - "url", URI) + Collector.SITE_ID, testSite.getIdentifier(), + Collector.EVENT_TYPE, EventType.VANITY_REQUEST.getType(), + Collector.LANGUAGE, defaultLanguage.getIsoCode(), + Collector.VANITY_URL_KEY, TEST_PAGE_URL, + Collector.LANGUAGE_ID, defaultLanguage.getId(), + Collector.URL, URI, + Collector.OBJECT, Map.of( + Collector.FORWARD_TO, TEST_PAGE_URL, + Collector.RESPONSE, "200", + Collector.ID, resolvedVanity.get().vanityUrlId, + Collector.URL, URI) ); final Collector collector = new SyncVanitiesCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java index e80bf21f71bb..a9192473dbb9 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java @@ -220,7 +220,7 @@ public void testPagesCollector() throws DotDataException, IOException { * */ @Test - public void testPageDetailCollector() throws DotDataException, IOException { + public void testPageDetailCollector() throws Exception { testDetailPage = null != testDetailPage ? testDetailPage : Util.createTestHTMLPage(testSite, TEST_URL_MAP_PAGE_NAME, PARENT_FOLDER_1_NAME); final String urlTitle = "mynews"; @@ -243,15 +243,24 @@ public void testPageDetailCollector() throws DotDataException, IOException { final Contentlet newsTestContent = contentletDataGen.nextPersisted(); ContentletDataGen.publish(newsTestContent); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "language", language.getIsoCode(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "object", Map.of( - "id", testDetailPage.getIdentifier(), - "title", testDetailPage.getTitle(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "detail_page_url", testDetailPage.getURI()) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.LANGUAGE, language.getIsoCode(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testDetailPage.getIdentifier(), + Collector.TITLE, testDetailPage.getTitle(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.CONTENT_TYPE_ID, testDetailPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testDetailPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testDetailPage.getContentType().variable(), + Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), + Collector.LIVE, testDetailPage.isLive(), + Collector.WORKING, testDetailPage.isWorking(), + Collector.DETAIL_PAGE_URL, testDetailPage.getURI() + + + ) ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter(); @@ -293,17 +302,17 @@ public void testSyncVanitiesCollector() throws DotDataException, IOException, Do assertTrue(resolvedVanity.isPresent(), "Test resolved vanity url must be present"); final Map expectedDataMap = Map.of( - "site", testSite.getIdentifier(), - "event_type", EventType.VANITY_REQUEST.getType(), - "language", defaultLanguage.getIsoCode(), - "vanity_url", TEST_PAGE_URL, - "language_id", (int) defaultLanguage.getId(), - "url", URI, - "object", Map.of( - "forward_to", TEST_PAGE_URL, - "response", "200", - "id", resolvedVanity.get().vanityUrlId, - "url", URI) + Collector.SITE_ID, testSite.getIdentifier(), + Collector.EVENT_TYPE, EventType.VANITY_REQUEST.getType(), + Collector.LANGUAGE, defaultLanguage.getIsoCode(), + Collector.VANITY_URL_KEY, TEST_PAGE_URL, + Collector.LANGUAGE_ID, (int) defaultLanguage.getId(), + Collector.URL, URI, + Collector.OBJECT, Map.of( + Collector.FORWARD_TO, TEST_PAGE_URL, + Collector.RESPONSE, "200", + Collector.ID, resolvedVanity.get().vanityUrlId, + Collector.URL, URI) ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter(); @@ -352,15 +361,22 @@ public void testAsyncVanitiesCollector() throws DotDataException, IOException, D assertTrue(resolvedVanity.isPresent(), "Test resolved vanity url must be present"); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "comeFromVanityURL", true, - "language", defaultLanguage.getIsoCode(), - "url", TEST_PAGE_URL, - "object", Map.of( - "id", testPage.getIdentifier(), - "title", TEST_PAGE_NAME, - "url", TEST_PAGE_URL) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.COME_FROM_VANITY_URL, true, + Collector.LANGUAGE, defaultLanguage.getIsoCode(), + Collector.URL, TEST_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testPage.getIdentifier(), + Collector.TITLE, TEST_PAGE_NAME, + Collector.URL, TEST_PAGE_URL, + Collector.CONTENT_TYPE_ID, testPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testPage.getContentType().variable(), + Collector.BASE_TYPE, testPage.getContentType().baseType().name(), + Collector.LIVE, testPage.isLive(), + Collector.WORKING, testPage.isWorking(), + Collector.DETAIL_PAGE_URL, testPage.getURI()) ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter(); From 58b029a2cfaafb23cbae8d69158bb95a55c3cb02 Mon Sep 17 00:00:00 2001 From: jdotcms Date: Mon, 2 Dec 2024 17:25:28 -0600 Subject: [PATCH 5/8] #30411 adding fixes --- .../collectors/AsyncVanitiesCollector.java | 2 +- .../AsyncVanitiesCollectorTest.java | 18 ++++++------- .../collectors/BasicProfileCollectorTest.java | 19 +++++++------- .../track/collectors/FilesCollectorTest.java | 26 ++++++++++++------- .../collectors/PageDetailCollectorTest.java | 12 ++++----- 5 files changed, 42 insertions(+), 35 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollector.java index 813f5ce78f11..822b95d4da6d 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollector.java @@ -63,7 +63,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa if (UtilMethods.isSet(whoIAM)) { final CollectorContextMap innerCollectorContextMap = new WrapperCollectorContextMap(collectorContextMap, - Map.of(URL, cachedVanityUrl.forwardTo)); + Map.of(CollectorContextMap.URI, cachedVanityUrl.forwardTo)); match.get(whoIAM).collect(innerCollectorContextMap, collectorPayloadBean); } diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java index 8635612928ef..2f097da543ad 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java @@ -84,15 +84,15 @@ public void collectAsyncVanityData() throws DotDataException, IOException, assertTrue("Resolved vanity url must be present", resolvedVanity.isPresent()); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "comeFromVanityURL", true, - "language", defaultLanguage.getIsoCode(), - "url", TEST_PAGE_URL, - "object", Map.of( - "id", testHTMLPage.getIdentifier(), - "title", TEST_PAGE_NAME, - "url", TEST_PAGE_URL) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.COME_FROM_VANITY_URL, true, + Collector.LANGUAGE, defaultLanguage.getIsoCode(), + Collector.URL, TEST_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testHTMLPage.getIdentifier(), + Collector.TITLE, TEST_PAGE_NAME, + Collector.URL, TEST_PAGE_URL) ); final Collector collector = new AsyncVanitiesCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/BasicProfileCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/BasicProfileCollectorTest.java index 50ba30bfebbf..16b72e4d2d4d 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/BasicProfileCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/BasicProfileCollectorTest.java @@ -55,15 +55,14 @@ public void collectBasicProfileData() throws DotDataException, UnknownHostExcept final HttpServletRequest request = Util.mockHttpRequestObj(response, "/", requestId, APILocator.getUserAPI().getAnonymousUser()); final Map expectedDataMap = Map.of( - "renderMode", "LIVE", - "cluster", CLUSTER_ID, - "server", SERVER_ID, - "persona", "dot:default", - "utc_time", "2024-10-09T00:00:00.000000Z", - "sessionNew", true, - "userAgent", Util.USER_AGENT, - "sessionId", "DAA3339CD687D9ABD4101CF9EDDD42DB", - "request_id", requestId + Collector.CLUSTER, CLUSTER_ID, + Collector.SERVER, SERVER_ID, + Collector.PERSONA, "dot:default", + Collector.UTC_TIME, "2024-10-09T00:00:00.000000Z", + Collector.SESSION_NEW, true, + Collector.USER_AGENT, Util.USER_AGENT, + Collector.SESSION_ID, "DAA3339CD687D9ABD4101CF9EDDD42DB", + Collector.REQUEST_ID, requestId ); final Collector collector = new BasicProfileCollector(); final CollectorPayloadBean collectedData = Util.getCollectorPayloadBean(request, collector, new PagesAndUrlMapsRequestMatcher(), null); @@ -75,7 +74,7 @@ public void collectBasicProfileData() throws DotDataException, UnknownHostExcept if (collectedData.toMap().containsKey(key)) { final Object expectedValue = expectedDataMap.get(key); final Object collectedValue = collectedData.toMap().get(key); - if (!"utc_time".equalsIgnoreCase(key)) { + if (!Collector.UTC_TIME.equalsIgnoreCase(key)) { assertEquals("Collected value must be equal to expected value for key: " + key, expectedValue, collectedValue); } counter++; diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java index e8d544f63dc8..d82cd92667e8 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java @@ -14,6 +14,7 @@ import com.dotmarketing.util.PageMode; import com.dotmarketing.util.UUIDUtil; import com.dotmarketing.util.UtilMethods; +import io.vavr.control.Try; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -70,15 +71,22 @@ public void collectFileData() throws DotDataException, IOException, DotSecurityE APILocator.getUserAPI().getAnonymousUser()); final Map expectedDataMap = Map.of( - "host", testSite.getHostname(), - "site", testSite.getIdentifier(), - "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), - "event_type", EventType.FILE_REQUEST.getType(), - "url", testFileAsset.getURI(), - "object", Map.of( - "id", testFileAsset.getIdentifier(), - "title", testFileAsset.getTitle(), - "url", testFileAsset.getURI()) + Collector.SITE_NAME, testSite.getHostname(), + Collector.SITE_ID, testSite.getIdentifier(), + Collector.LANGUAGE, APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), + Collector.EVENT_TYPE, EventType.FILE_REQUEST.getType(), + Collector.URL, testFileAsset.getURI(), + Collector.OBJECT, Map.of( + Collector.ID, testFileAsset.getIdentifier(), + Collector.TITLE, testFileAsset.getTitle(), + Collector.URL, testFileAsset.getURI(), + Collector.CONTENT_TYPE_ID, testFileAsset.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testFileAsset.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testFileAsset.getContentType().variable(), + Collector.BASE_TYPE, testFileAsset.getContentType().baseType().name(), + Collector.LIVE, String.valueOf(Try.of(()->testFileAsset.isLive()).getOrElse(false)), + Collector.WORKING, String.valueOf(Try.of(()->testFileAsset.isWorking()).getOrElse(false)) + ) ); final Collector collector = new FilesCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java index e0dbd6fa32f2..e532d5855c27 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java @@ -109,12 +109,12 @@ public void testPageDetailCollector() throws DotDataException, UnknownHostExcept Collector.ID, testDetailPage.getIdentifier(), Collector.TITLE, testDetailPage.getTitle(), Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, - Collector.CONTENT_TYPE_ID, testDetailPage.getContentType().id(), - Collector.CONTENT_TYPE_NAME, testDetailPage.getContentType().name(), - Collector.CONTENT_TYPE_VAR_NAME, testDetailPage.getContentType().variable(), - Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), - Collector.LIVE, testDetailPage.isLive(), - Collector.WORKING, testDetailPage.isWorking(), + Collector.CONTENT_TYPE_ID, newsTestContent.getContentType().id(), + Collector.CONTENT_TYPE_NAME, newsTestContent.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, newsTestContent.getContentType().variable(), + Collector.BASE_TYPE, newsTestContent.getContentType().baseType().name(), + Collector.LIVE, newsTestContent.isLive(), + Collector.WORKING, newsTestContent.isWorking(), Collector.DETAIL_PAGE_URL, testDetailPage.getURI()) ); From 5bd31821307f5ab37a545d0145a14f18779ef118 Mon Sep 17 00:00:00 2001 From: jdotcms Date: Mon, 2 Dec 2024 23:06:58 -0600 Subject: [PATCH 6/8] #30411 adding fixes --- .../track/collectors/PagesCollector.java | 7 +++ .../CustomerEventCollectorTest.java | 10 +-- .../analytics/track/collectors/Util.java | 10 +-- .../WebEventsCollectorServiceImplTest.java | 61 ++++++++++++------- 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java index b550b86dc816..1266da3e3805 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java @@ -85,6 +85,13 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa this.pageAPI.getPageByPath(uri, site, languageId, true)).get(); pageObject.put(ID, page.getIdentifier()); pageObject.put(TITLE, page.getTitle()); + final Contentlet pageContentlet = (Contentlet) page; + pageObject.put(CONTENT_TYPE_ID, pageContentlet.getContentType().id()); + pageObject.put(CONTENT_TYPE_NAME, pageContentlet.getContentType().name()); + pageObject.put(CONTENT_TYPE_VAR_NAME, pageContentlet.getContentType().variable()); + pageObject.put(BASE_TYPE, pageContentlet.getContentType().baseType().name()); + pageObject.put(LIVE, String.valueOf(Try.of(()->page.isLive()).getOrElse(false))); + pageObject.put(WORKING, String.valueOf(Try.of(()->page.isWorking()).getOrElse(false))); collectorPayloadBean.put(EVENT_TYPE, EventType.PAGE_REQUEST.getType()); } pageObject.put(URL, uri); diff --git a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java index c75f71350086..89a210d38ba4 100644 --- a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java +++ b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java @@ -53,10 +53,10 @@ public RequestMatcher getRequestMatcher() { final CollectorPayloadBean collectorPayloadBean = new ConcurrentCollectorPayloadBean(); customerEventCollector.collect(collectorContextMap, collectorPayloadBean); - Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); - Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); - Assert.assertEquals("en", collectorPayloadBean.get("language")); - Assert.assertEquals("1", collectorPayloadBean.get("site")); - Assert.assertEquals(EventType.CUSTOM_USER_EVENT.getType(), collectorPayloadBean.get("event_type")); + Assert.assertEquals("/test-path", collectorPayloadBean.get(Collector.URL)); + Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get(Collector.SITE_NAME)); + Assert.assertEquals("en", collectorPayloadBean.get(Collector.LANGUAGE)); + Assert.assertEquals("1", collectorPayloadBean.get(Collector.SITE_ID)); + Assert.assertEquals(EventType.CUSTOM_USER_EVENT.getType(), collectorPayloadBean.get(Collector.EVENT_TYPE)); } } diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/Util.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/Util.java index 82a73bc488bd..08b9325db20c 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/Util.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/Util.java @@ -51,6 +51,7 @@ import java.util.Optional; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -304,8 +305,7 @@ public static void validateExpectedEntries(final Map expectedDat */ public static void validateExpectedEntries(final Map expectedDataMap, final Map collectedData) { - assertEquals("Number of returned expected properties doesn't match", expectedDataMap.size(), - collectedData.size()); + assertTrue("Number of returned expected properties doesn't match", collectedData.size() >= expectedDataMap.size()); for (final String key : expectedDataMap.keySet()) { if (collectedData.containsKey(key)) { final Object expectedValue = expectedDataMap.get(key); @@ -313,13 +313,13 @@ public static void validateExpectedEntries(final Map expectedDat if (expectedValue instanceof Map) { final Map expectedMap = (Map) expectedValue; final Map collectedMap = (Map) collectedValue; - assertEquals("Number of returned expected properties in 'object' entry " + + assertTrue("Number of returned expected properties in 'object' entry " + "doesn't match", - expectedMap.size(), collectedMap.size()); + collectedMap.size() >= expectedMap.size()); for (final String mapKey : expectedMap.keySet()) { assertEquals("Collected value in 'object' entry must be equal to expected" + " value for key: " - + mapKey, expectedMap.get(mapKey), collectedMap.get(mapKey)); + + mapKey, expectedMap.get(mapKey).toString(), collectedMap.get(mapKey).toString()); } } assertEquals("Collected value must be equal to expected value for key: " + key, diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java index a9192473dbb9..322ac2c697f7 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java @@ -32,6 +32,7 @@ import com.dotmarketing.portlets.languagesmanager.model.Language; import com.dotmarketing.util.Config; import com.dotmarketing.util.UUIDUtil; +import io.vavr.control.Try; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -175,18 +176,26 @@ public void testBasicProfileCollector() throws DotDataException, IOException { * */ @Test - public void testPagesCollector() throws DotDataException, IOException { + public void testPagesCollector() throws DotDataException, IOException, DotSecurityException { testPage = null != testPage ? testPage : Util.createTestHTMLPage(testSite, TEST_PAGE_NAME); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "url", TEST_PAGE_URL, - "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), - "object", Map.of( - "id", testPage.getIdentifier(), - "title", testPage.getTitle(), - "url", testPage.getURI()) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.URL, TEST_PAGE_URL, + Collector.LANGUAGE, APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), + Collector.OBJECT, Map.of( + Collector.ID, testPage.getIdentifier(), + Collector.TITLE, testPage.getTitle(), + Collector.URL, testPage.getURI(), + Collector.CONTENT_TYPE_ID, testPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testPage.getContentType().variable(), + Collector.BASE_TYPE, testPage.getContentType().baseType().name(), + Collector.LIVE, testPage.isLive(), + Collector.WORKING, testPage.isWorking() + ) + ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter(); @@ -251,10 +260,10 @@ public void testPageDetailCollector() throws Exception { Collector.ID, testDetailPage.getIdentifier(), Collector.TITLE, testDetailPage.getTitle(), Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, - Collector.CONTENT_TYPE_ID, testDetailPage.getContentType().id(), - Collector.CONTENT_TYPE_NAME, testDetailPage.getContentType().name(), - Collector.CONTENT_TYPE_VAR_NAME, testDetailPage.getContentType().variable(), - Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), + Collector.CONTENT_TYPE_ID, urlMappedContentType.id(), + Collector.CONTENT_TYPE_NAME, urlMappedContentType.name(), + Collector.CONTENT_TYPE_VAR_NAME, urlMappedContentType.variable(), + Collector.BASE_TYPE, urlMappedContentType.baseType().name(), Collector.LIVE, testDetailPage.isLive(), Collector.WORKING, testDetailPage.isWorking(), Collector.DETAIL_PAGE_URL, testDetailPage.getURI() @@ -422,15 +431,23 @@ public void testFilesCollector() throws DotDataException, IOException, DotSecuri ".txt","Sample content for my test file", "parent-folder-for-file", testSite); final Map expectedDataMap = Map.of( - "host", testSite.getHostname(), - "site", testSite.getIdentifier(), - "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), - "event_type", EventType.FILE_REQUEST.getType(), - "url", testFileAsset.getURI(), - "object", Map.of( - "id", testFileAsset.getIdentifier(), - "title", testFileAsset.getTitle(), - "url", testFileAsset.getURI()) + Collector.SITE_NAME, testSite.getHostname(), + Collector.SITE_ID, testSite.getIdentifier(), + Collector.LANGUAGE, APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), + Collector.EVENT_TYPE, EventType.FILE_REQUEST.getType(), + Collector.URL, testFileAsset.getURI(), + Collector.OBJECT, Map.of( + Collector.ID, testFileAsset.getIdentifier(), + Collector.TITLE, testFileAsset.getTitle(), + Collector.URL, testFileAsset.getURI(), + Collector.CONTENT_TYPE_ID, testFileAsset.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testFileAsset.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testFileAsset.getContentType().variable(), + Collector.BASE_TYPE, testFileAsset.getContentType().baseType().name(), + Collector.LIVE, String.valueOf(Try.of(()->testFileAsset.isLive()).getOrElse(false)), + Collector.WORKING, String.valueOf(Try.of(()->testFileAsset.isWorking()).getOrElse(false)) + ) + ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter(); From e06b079387de5a56033dfc74fcd871a6015aa382 Mon Sep 17 00:00:00 2001 From: jdotcms Date: Tue, 3 Dec 2024 15:10:12 -0600 Subject: [PATCH 7/8] #30411 adding fixes --- .../track/collectors/AsyncVanitiesCollectorTest.java | 8 +++++++- .../analytics/track/collectors/PagesCollectorTest.java | 8 +++----- .../java/com/dotcms/analytics/track/collectors/Util.java | 5 +++-- .../collectors/WebEventsCollectorServiceImplTest.java | 3 +-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java index 2f097da543ad..807448c2d578 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java @@ -92,7 +92,13 @@ public void collectAsyncVanityData() throws DotDataException, IOException, Collector.OBJECT, Map.of( Collector.ID, testHTMLPage.getIdentifier(), Collector.TITLE, TEST_PAGE_NAME, - Collector.URL, TEST_PAGE_URL) + Collector.URL, TEST_PAGE_URL, + Collector.CONTENT_TYPE_ID, testHTMLPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testHTMLPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testHTMLPage.getContentType().variable(), + Collector.BASE_TYPE, testHTMLPage.getContentType().baseType().name(), + Collector.LIVE, testHTMLPage.isLive(), + Collector.WORKING, testHTMLPage.isWorking()) ); final Collector collector = new AsyncVanitiesCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java index 515880d80e2e..5b789e909ea8 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java @@ -95,8 +95,7 @@ public void collectPageData() throws Exception { Collector.CONTENT_TYPE_VAR_NAME, testPage.getContentType().variable(), Collector.BASE_TYPE, testPage.getContentType().baseType().name(), Collector.LIVE, testPage.isLive(), - Collector.WORKING, testPage.isWorking(), - Collector.DETAIL_PAGE_URL, testPage.getURI()) + Collector.WORKING, testPage.isWorking()) ); final Collector collector = new PagesCollector(); @@ -166,10 +165,9 @@ public void collectUrlMapPageData() throws Exception { Collector.CONTENT_TYPE_ID, urlMappedContentType.id(), Collector.CONTENT_TYPE_NAME, urlMappedContentType.name(), Collector.CONTENT_TYPE_VAR_NAME, urlMappedContentType.variable(), - Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), + Collector.BASE_TYPE, urlMappedContentType.baseType().name(), Collector.LIVE, newsTestContent.isLive(), - Collector.WORKING, newsTestContent.isWorking(), - Collector.DETAIL_PAGE_URL, testDetailPage.getURI() + Collector.WORKING, newsTestContent.isWorking() ) ); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/Util.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/Util.java index 08b9325db20c..ace3b4430674 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/Util.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/Util.java @@ -321,9 +321,10 @@ public static void validateExpectedEntries(final Map expectedDat " value for key: " + mapKey, expectedMap.get(mapKey).toString(), collectedMap.get(mapKey).toString()); } + } else { + assertEquals("Collected value must be equal to expected value for key: " + key, + expectedValue, collectedValue); } - assertEquals("Collected value must be equal to expected value for key: " + key, - expectedValue, collectedValue); } } } diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java index 322ac2c697f7..a1e344046cb8 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java @@ -384,8 +384,7 @@ public void testAsyncVanitiesCollector() throws DotDataException, IOException, D Collector.CONTENT_TYPE_VAR_NAME, testPage.getContentType().variable(), Collector.BASE_TYPE, testPage.getContentType().baseType().name(), Collector.LIVE, testPage.isLive(), - Collector.WORKING, testPage.isWorking(), - Collector.DETAIL_PAGE_URL, testPage.getURI()) + Collector.WORKING, testPage.isWorking()) ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter(); From 0d9f38eb85152b8a845d1bc2ea7db10fa68f4e95 Mon Sep 17 00:00:00 2001 From: jdotcms Date: Wed, 4 Dec 2024 16:17:29 -0600 Subject: [PATCH 8/8] #30411 fixing junits --- .../track/collectors/FilesCollectorTest.java | 32 ++++++++++++++----- .../track/collectors/PagesCollectorTest.java | 17 ++++------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java index fa60f7b429f1..3769843b952c 100644 --- a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java +++ b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java @@ -2,6 +2,8 @@ import com.dotcms.UnitTestBase; import com.dotcms.analytics.track.matchers.RequestMatcher; +import com.dotcms.contenttype.model.type.BaseContentType; +import com.dotcms.contenttype.model.type.ContentType; import com.dotmarketing.beans.Host; import com.dotmarketing.portlets.contentlet.model.Contentlet; import org.junit.Assert; @@ -30,9 +32,24 @@ public void test_collect_easy_path() throws IOException { final FilesCollector filesCollector = new FilesCollector() { @Override protected Optional getFileAsset(String uri, Host host, Long languageId) { + final Contentlet contentlet = Mockito.mock(Contentlet.class); Mockito.when(contentlet.getIdentifier()).thenReturn("1"); Mockito.when(contentlet.getTitle()).thenReturn("Test"); + try { + Mockito.when(contentlet.isLive()).thenReturn(true); + Mockito.when(contentlet.isWorking()).thenReturn(true); + } catch (Exception e) { + + } + final ContentType contentType = Mockito.mock(ContentType.class); + Mockito.when(contentlet.getContentType()).thenReturn(contentType); + Mockito.when(contentType.id()).thenReturn("1"); + Mockito.when(contentType.name()).thenReturn("file"); + Mockito.when(contentType.variable()).thenReturn("file"); + final BaseContentType baseType = Mockito.mock(BaseContentType.class); + Mockito.when(contentType.baseType()).thenReturn(baseType); + Mockito.when(baseType.name()).thenReturn("file"); return Optional.ofNullable(contentlet); } }; @@ -70,13 +87,12 @@ public RequestMatcher getRequestMatcher() { final Map fileObject = (Map) collectorPayloadBean.get("object"); Assert.assertNotNull(fileObject); - Assert.assertEquals("1", fileObject.get("id")); - Assert.assertEquals("Test", fileObject.get("title")); - Assert.assertEquals("/test-path", fileObject.get("url")); - Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); - Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); - Assert.assertEquals("en", collectorPayloadBean.get("language")); - Assert.assertEquals("1", collectorPayloadBean.get("site")); - Assert.assertEquals(EventType.FILE_REQUEST.getType(), collectorPayloadBean.get("event_type")); + Assert.assertEquals("1", fileObject.get(Collector.ID)); + Assert.assertEquals("Test", fileObject.get(Collector.TITLE)); + Assert.assertEquals("/test-path", fileObject.get(Collector.URL)); + Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get(Collector.SITE_NAME)); + Assert.assertEquals("en", collectorPayloadBean.get(Collector.LANGUAGE)); + Assert.assertEquals("1", collectorPayloadBean.get(Collector.SITE_ID)); + Assert.assertEquals(EventType.FILE_REQUEST.getType(), collectorPayloadBean.get(Collector.EVENT_TYPE)); } } diff --git a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java index 7668e4a8b832..a5915a358e0a 100644 --- a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java +++ b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java @@ -3,15 +3,12 @@ import com.dotcms.analytics.track.matchers.RequestMatcher; import com.dotmarketing.beans.Host; import com.dotmarketing.cms.urlmap.URLMapAPIImpl; -import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.htmlpageasset.business.HTMLPageAssetAPI; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.io.IOException; -import java.util.Map; -import java.util.Optional; /** * Test for the {@link PagesCollector} class @@ -29,9 +26,9 @@ public class PagesCollectorTest { public void test_collect_easy_path() throws IOException { final PagesCollector pagesCollector = new PagesCollector(Mockito.mock(HTMLPageAssetAPI.class), Mockito.mock(URLMapAPIImpl.class)); - final Host host = new Host(); - host.setIdentifier("1"); - host.setHostname("www.dotcms.com"); + final Host host = Mockito.mock(Host.class); + Mockito.when(host.getIdentifier()).thenReturn("1"); + Mockito.when(host.getHostname()).thenReturn("www.dotcms.com"); final CollectorContextMap collectorContextMap = new CollectorContextMap() { @Override public Object get(final String key) { @@ -62,9 +59,9 @@ public RequestMatcher getRequestMatcher() { final CollectorPayloadBean collectorPayloadBean = new ConcurrentCollectorPayloadBean(); pagesCollector.collect(collectorContextMap, collectorPayloadBean); - Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); - Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); - Assert.assertEquals("en", collectorPayloadBean.get("language")); - Assert.assertEquals(EventType.PAGE_REQUEST.getType(), collectorPayloadBean.get("event_type")); + Assert.assertEquals("/test-path", collectorPayloadBean.get(Collector.URL)); + Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get(Collector.SITE_NAME)); + Assert.assertEquals("en", collectorPayloadBean.get(Collector.LANGUAGE)); + Assert.assertEquals(EventType.PAGE_REQUEST.getType(), collectorPayloadBean.get(Collector.EVENT_TYPE)); } }