From 5cf7fb5b3d4aa011e12b118ab9ba190013bcd203 Mon Sep 17 00:00:00 2001 From: Earle Nietzel Date: Tue, 8 Oct 2024 23:26:54 -0400 Subject: [PATCH] SAK-50590 SiteStats exception when persisting an eventRef longer than 512 chars https://sakaiproject.atlassian.net/browse/SAK-50590 --- search/elasticsearch/util/pom.xml | 4 +++ .../BaseElasticSearchIndexBuilder.java | 17 ++++++++- sitestats/sitestats-impl-hib/pom.xml | 4 +++ .../sitestats/impl/DetailedEventImpl.java | 35 +++++++++++-------- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/search/elasticsearch/util/pom.xml b/search/elasticsearch/util/pom.xml index 1f68b3840642..a08e51135edd 100644 --- a/search/elasticsearch/util/pom.xml +++ b/search/elasticsearch/util/pom.xml @@ -68,6 +68,10 @@ org.sakaiproject.search search-api + + com.fasterxml.jackson.core + jackson-databind + diff --git a/search/elasticsearch/util/src/java/org/sakaiproject/search/elasticsearch/BaseElasticSearchIndexBuilder.java b/search/elasticsearch/util/src/java/org/sakaiproject/search/elasticsearch/BaseElasticSearchIndexBuilder.java index e885a7b8651d..5c567b9b43db 100644 --- a/search/elasticsearch/util/src/java/org/sakaiproject/search/elasticsearch/BaseElasticSearchIndexBuilder.java +++ b/search/elasticsearch/util/src/java/org/sakaiproject/search/elasticsearch/BaseElasticSearchIndexBuilder.java @@ -43,6 +43,9 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -1063,10 +1066,11 @@ public SearchResponse search(String searchTerms, List references, List references, List references, List siteIds, List toolIds, int start, int end, Map additionalSearchInformation) { // additional information will be used in specific indexes, diff --git a/sitestats/sitestats-impl-hib/pom.xml b/sitestats/sitestats-impl-hib/pom.xml index 4132b9701d19..767c0590923d 100644 --- a/sitestats/sitestats-impl-hib/pom.xml +++ b/sitestats/sitestats-impl-hib/pom.xml @@ -29,6 +29,10 @@ org.springframework spring-core + + org.apache.commons + commons-lang3 + org.hamcrest hamcrest diff --git a/sitestats/sitestats-impl-hib/src/java/org/sakaiproject/sitestats/impl/DetailedEventImpl.java b/sitestats/sitestats-impl-hib/src/java/org/sakaiproject/sitestats/impl/DetailedEventImpl.java index 16d61c229ab1..4a0cdd62b3bb 100644 --- a/sitestats/sitestats-impl-hib/src/java/org/sakaiproject/sitestats/impl/DetailedEventImpl.java +++ b/sitestats/sitestats-impl-hib/src/java/org/sakaiproject/sitestats/impl/DetailedEventImpl.java @@ -18,35 +18,40 @@ import java.io.Serializable; import java.util.Date; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.apache.commons.lang3.StringUtils; import org.sakaiproject.sitestats.api.event.detailed.DetailedEvent; /** * @author plukasew */ -public class DetailedEventImpl implements DetailedEvent, Serializable -{ - @Getter @Setter private long id; - @Getter @Setter private String siteId; - @Getter @Setter private String userId; - @Getter @Setter private String eventId; - @Getter @Setter private String eventRef; - @Getter @Setter private Date eventDate; +@Data +@EqualsAndHashCode(onlyExplicitlyIncluded = true) +public class DetailedEventImpl implements DetailedEvent, Serializable { + @EqualsAndHashCode.Include + private long id; + private String siteId; + private String userId; + private String eventId; + private String eventRef; + private Date eventDate; - public DetailedEventImpl() - { + public DetailedEventImpl() { this(0, "", "", "", "", new Date()); } - public DetailedEventImpl(long id, String siteId, String userId, String eventId, String eventRef, Date date) - { + public DetailedEventImpl(long id, String siteId, String userId, String eventId, String eventRef, Date date) { this.id = id; this.siteId = siteId; this.userId = userId; this.eventId = eventId; - this.eventRef = eventRef; this.eventDate = date; + setEventRef(eventRef); + } + + public void setEventRef(String eventRef) { + this.eventRef = StringUtils.abbreviate(eventRef, 512); } }