[CST-6751] Renamed GoogleAnalyticsClientRequestBuilder method

This commit is contained in:
Luca Giamminonni
2022-09-14 15:30:17 +02:00
parent 53fd235841
commit 5130642415
6 changed files with 35 additions and 35 deletions

View File

@@ -56,18 +56,18 @@ public class GoogleAnalytics4ClientRequestBuilder implements GoogleAnalyticsClie
}
@Override
public List<String> composeRequestBodies(String analyticsKey, List<GoogleAnalyticsEvent> events) {
public List<String> composeRequestsBody(String analyticsKey, List<GoogleAnalyticsEvent> events) {
Map<String, List<GoogleAnalyticsEvent>> eventsGroupedByClientId = groupByClientId(events);
List<String> requestBodies = new ArrayList<String>();
List<String> requestsBody = new ArrayList<String>();
for (String clientId : eventsGroupedByClientId.keySet()) {
String requestBody = composeRequestBody(analyticsKey, clientId, eventsGroupedByClientId.get(clientId));
requestBodies.add(requestBody);
requestsBody.add(requestBody);
}
return requestBodies;
return requestsBody;
}

View File

@@ -55,7 +55,7 @@ public class GoogleAnalyticsClientImpl implements GoogleAnalyticsClient {
String endpointUrl = requestBuilder.getEndpointUrl(analyticsKey);
requestBuilder.composeRequestBodies(analyticsKey, events)
requestBuilder.composeRequestsBody(analyticsKey, events)
.forEach(requestBody -> sendRequest(endpointUrl, requestBody));
}

View File

@@ -13,7 +13,7 @@ import org.dspace.google.GoogleAnalyticsEvent;
/**
* Interface for classes used by {@link GoogleAnalyticsClient} to define the url
* and the body of the request to be sent to Google Analytics.
* and the body of the requests to be sent to Google Analytics.
*
* @author Luca Giamminonni (luca.giamminonni at 4science.it)
*
@@ -29,12 +29,12 @@ public interface GoogleAnalyticsClientRequestBuilder {
String getEndpointUrl(String analyticsKey);
/**
* Returns the bodies of the requests to be sent to Google Analytics as string,
* Returns the body of the requests to be sent to Google Analytics as string,
* based on the given analytics key and events.
*
* @param analyticsKey the Google Analytics key
* @param events the events to be sent
* @return the request body as string
* @return the requests body as string
*/
List<String> composeRequestBodies(String analyticsKey, List<GoogleAnalyticsEvent> events);
List<String> composeRequestsBody(String analyticsKey, List<GoogleAnalyticsEvent> events);
}

View File

@@ -37,7 +37,7 @@ public class UniversalAnalyticsClientRequestBuilder implements GoogleAnalyticsCl
}
@Override
public List<String> composeRequestBodies(String analyticsKey, List<GoogleAnalyticsEvent> events) {
public List<String> composeRequestsBody(String analyticsKey, List<GoogleAnalyticsEvent> events) {
String requestBody = events.stream()
.map(event -> formatEvent(analyticsKey, event))

View File

@@ -65,8 +65,8 @@ public class GoogleAnalytics4ClientRequestBuilderTest {
@Test
public void testComposeRequestBodiesWithoutEvents() {
List<String> requestBodies = requestBuilder.composeRequestBodies("G-12345", List.of());
assertThat(requestBodies, empty());
List<String> requestsBody = requestBuilder.composeRequestsBody("G-12345", List.of());
assertThat(requestsBody, empty());
}
@@ -76,10 +76,10 @@ public class GoogleAnalytics4ClientRequestBuilderTest {
GoogleAnalyticsEvent event = buildEvent("123", "192.168.1.25", "Chrome", "REF",
"/api/documents/123", "Test publication");
List<String> requestBodies = requestBuilder.composeRequestBodies("G-12345", List.of(event));
assertThat(requestBodies, hasSize(1));
List<String> requestsBody = requestBuilder.composeRequestsBody("G-12345", List.of(event));
assertThat(requestsBody, hasSize(1));
JSONObject requestBody = new JSONObject(requestBodies.get(0));
JSONObject requestBody = new JSONObject(requestsBody.get(0));
assertThat(requestBody.get("client_id"), is("123"));
JSONArray eventsArray = requestBody.getJSONArray("events");
@@ -99,10 +99,10 @@ public class GoogleAnalytics4ClientRequestBuilderTest {
GoogleAnalyticsEvent event2 = buildEvent("123", "192.168.1.25", "Mozilla Firefox", "REF-2",
"/api/documents/12345", "Test publication 2");
List<String> requestBodies = requestBuilder.composeRequestBodies("G-12345", List.of(event1, event2));
assertThat(requestBodies, hasSize(1));
List<String> requestsBody = requestBuilder.composeRequestsBody("G-12345", List.of(event1, event2));
assertThat(requestsBody, hasSize(1));
JSONObject requestBody = new JSONObject(requestBodies.get(0));
JSONObject requestBody = new JSONObject(requestsBody.get(0));
assertThat(requestBody.get("client_id"), is("123"));
JSONArray eventsArray = requestBody.getJSONArray("events");
@@ -134,10 +134,10 @@ public class GoogleAnalytics4ClientRequestBuilderTest {
GoogleAnalyticsEvent event3 = buildEvent("987", "192.168.1.13", "Postman", null,
"/api/documents/654", "Test publication 3");
List<String> requestBodies = requestBuilder.composeRequestBodies("G-12345", of(event1, event2, event3));
assertThat(requestBodies, hasSize(2));
List<String> requestsBody = requestBuilder.composeRequestsBody("G-12345", of(event1, event2, event3));
assertThat(requestsBody, hasSize(2));
JSONObject firstRequestBody = findRequestBodyByClientId(requestBodies, "123");
JSONObject firstRequestBody = findRequestBodyByClientId(requestsBody, "123");
assertThat(firstRequestBody.get("client_id"), is("123"));
JSONArray firstEventsArray = firstRequestBody.getJSONArray("events");
@@ -155,7 +155,7 @@ public class GoogleAnalytics4ClientRequestBuilderTest {
assertEventJsonHasAttributes(eventJson2, "item", "download", "bitstream", "192.168.1.25",
"Mozilla Firefox", "REF-2", "/api/documents/12345", "Test publication 2");
JSONObject secondRequestBody = findRequestBodyByClientId(requestBodies, "987");
JSONObject secondRequestBody = findRequestBodyByClientId(requestsBody, "987");
assertThat(secondRequestBody.get("client_id"), is("987"));
JSONArray secondEventsArray = secondRequestBody.getJSONArray("events");
@@ -182,8 +182,8 @@ public class GoogleAnalytics4ClientRequestBuilderTest {
}
private JSONObject findRequestBodyByClientId(List<String> requestBodies, String clientId) {
for (String requestBody : requestBodies) {
private JSONObject findRequestBodyByClientId(List<String> requestsBody, String clientId) {
for (String requestBody : requestsBody) {
JSONObject requestBodyJson = new JSONObject(requestBody);
if (requestBodyJson.get("client_id").equals(clientId)) {
return requestBodyJson;

View File

@@ -46,8 +46,8 @@ public class UniversalAnalyticsClientRequestBuilderTest {
@Test
public void testComposeRequestBodiesWithoutEvents() {
List<String> requestBodies = requestBuilder.composeRequestBodies("G-12345", List.of());
assertThat(requestBodies, empty());
List<String> requestsBody = requestBuilder.composeRequestsBody("G-12345", List.of());
assertThat(requestsBody, empty());
}
@@ -57,10 +57,10 @@ public class UniversalAnalyticsClientRequestBuilderTest {
GoogleAnalyticsEvent event = buildEvent("123", "192.168.1.25", "Chrome", "REF",
"/api/documents/123", "Test publication");
List<String> requestBodies = requestBuilder.composeRequestBodies("G-12345", List.of(event));
assertThat(requestBodies, hasSize(1));
List<String> requestsBody = requestBuilder.composeRequestsBody("G-12345", List.of(event));
assertThat(requestsBody, hasSize(1));
String requestBody = requestBodies.get(0);
String requestBody = requestsBody.get(0);
assertThat(countMatches(requestBody, "&qt="), is(1));
String requestBodyWithoutTime = removeAllTimeSections(requestBody);
@@ -81,9 +81,9 @@ public class UniversalAnalyticsClientRequestBuilderTest {
GoogleAnalyticsEvent event2 = buildEvent("123", "192.168.1.25", "Mozilla Firefox", "REF-2",
"/api/documents/12345", "Test publication 2");
List<String> requestBodies = requestBuilder.composeRequestBodies("G-12345", List.of(event1, event2));
assertThat(requestBodies, hasSize(1));
String requestBody = requestBodies.get(0);
List<String> requestsBody = requestBuilder.composeRequestsBody("G-12345", List.of(event1, event2));
assertThat(requestsBody, hasSize(1));
String requestBody = requestsBody.get(0);
assertThat(countMatches(requestBody, "&qt="), is(2));
@@ -110,9 +110,9 @@ public class UniversalAnalyticsClientRequestBuilderTest {
GoogleAnalyticsEvent event3 = buildEvent("987", "192.168.1.13", "Postman", null,
"/api/documents/654", "Test publication 3");
List<String> requestBodies = requestBuilder.composeRequestBodies("G-12345", of(event1, event2, event3));
assertThat(requestBodies, hasSize(1));
String requestBody = requestBodies.get(0);
List<String> requestsBody = requestBuilder.composeRequestsBody("G-12345", of(event1, event2, event3));
assertThat(requestsBody, hasSize(1));
String requestBody = requestsBody.get(0);
assertThat(countMatches(requestBody, "&qt="), is(3));