Skip to content

Commit

Permalink
SAK-50590 SiteStats exception when persisting an eventRef longer than…
Browse files Browse the repository at this point in the history
  • Loading branch information
ern committed Oct 9, 2024
1 parent b0d7bea commit 5cf7fb5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
4 changes: 4 additions & 0 deletions search/elasticsearch/util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<groupId>org.sakaiproject.search</groupId>
<artifactId>search-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1063,10 +1066,11 @@ public SearchResponse search(String searchTerms, List<String> references, List<S
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
log.debug("Search request from index builder [{}] took: {}", getName(), response.getTook().getMillis());
String minified = getMinifiedJson(searchRequest.source().query().toString());
eventTrackingService.post(
eventTrackingService.newEvent(
SearchService.EVENT_SEARCH,
SearchService.EVENT_SEARCH_REF + searchRequest.source().query().toString(),
SearchService.EVENT_SEARCH_REF + minified,
true,
NotificationService.PREF_IMMEDIATE));
return response;
Expand All @@ -1076,6 +1080,17 @@ public SearchResponse search(String searchTerms, List<String> references, List<S
return null;
}

private static String getMinifiedJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(json);
return mapper.writeValueAsString(jsonNode);
} catch (JsonProcessingException e) {
log.warn("Could not minify json [{}], {}", json, e.toString());
}
return json;
}

@Override
public SearchResponse search(String searchTerms, List<String> references, List<String> siteIds, List<String> toolIds, int start, int end, Map<String,String> additionalSearchInformation) {
// additional information will be used in specific indexes,
Expand Down
4 changes: 4 additions & 0 deletions sitestats/sitestats-impl-hib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 5cf7fb5

Please sign in to comment.