From 85e2f4b772d9f9f7b39e2e5c24314b9b6f75dde3 Mon Sep 17 00:00:00 2001 From: soimugeo Date: Thu, 14 Nov 2024 17:54:38 +0200 Subject: [PATCH] added handler for GetEntityHistorySummaryRequest --- .../uiHistoryConcern/dto/EntityChange.java | 16 ++++++++ .../dto/EntityHistorySummary.java | 9 +++++ ...GetEntityHistorySummaryCommandHandler.java | 38 +++++++++++++++++++ .../GetEntityHistorySummaryRequest.java | 23 +++++++++++ .../GetEntityHistorySummaryResponse.java | 16 ++++++++ .../RevisionsEventRepository.java | 4 ++ .../services/NewRevisionsEventService.java | 4 +- .../NewRevisionsEventServiceImpl.java | 17 +++++++++ 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/EntityChange.java create mode 100644 src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/EntityHistorySummary.java create mode 100644 src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryCommandHandler.java create mode 100644 src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryRequest.java create mode 100644 src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryResponse.java diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/EntityChange.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/EntityChange.java new file mode 100644 index 0000000..c781977 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/EntityChange.java @@ -0,0 +1,16 @@ +package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto; + +import edu.stanford.protege.webprotege.common.UserId; + +import java.time.LocalDateTime; + +public record EntityChange(String changeSummary, + UserId userId, + LocalDateTime dateTime) { + + public static EntityChange create(String changeSummary, + UserId userId, + LocalDateTime dateTime){ + return new EntityChange(changeSummary,userId,dateTime); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/EntityHistorySummary.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/EntityHistorySummary.java new file mode 100644 index 0000000..2ef4abf --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/EntityHistorySummary.java @@ -0,0 +1,9 @@ +package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto; + +import java.util.List; + +public record EntityHistorySummary(List changes) { + public static EntityHistorySummary create(List changes) { + return new EntityHistorySummary(changes); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryCommandHandler.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryCommandHandler.java new file mode 100644 index 0000000..3a50cc1 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryCommandHandler.java @@ -0,0 +1,38 @@ +package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers; + +import edu.stanford.protege.webprotege.common.ProjectId; +import edu.stanford.protege.webprotege.ipc.*; +import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.EntityHistorySummary; +import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.services.NewRevisionsEventService; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +import javax.annotation.Nonnull; + +@Component +public class GetEntityHistorySummaryCommandHandler implements CommandHandler { + + private final NewRevisionsEventService service; + + public GetEntityHistorySummaryCommandHandler(NewRevisionsEventService service) { + this.service = service; + } + + + @Nonnull + @Override + public String getChannelName() { + return GetEntityHistorySummaryRequest.CHANNEL; + } + + @Override + public Class getRequestClass() { + return GetEntityHistorySummaryRequest.class; + } + + @Override + public Mono handleRequest(GetEntityHistorySummaryRequest request, ExecutionContext executionContext) { + EntityHistorySummary entityHistorySummary = service.getEntityHistorySummary(ProjectId.valueOf(request.projectId()), request.entityIri()); + return Mono.just(GetEntityHistorySummaryResponse.create(entityHistorySummary)); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryRequest.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryRequest.java new file mode 100644 index 0000000..4af8373 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryRequest.java @@ -0,0 +1,23 @@ +package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers; + +import com.fasterxml.jackson.annotation.*; +import edu.stanford.protege.webprotege.common.Request; + +@JsonTypeName(GetEntityHistorySummaryRequest.CHANNEL) +public record GetEntityHistorySummaryRequest( + @JsonProperty("projectId") String projectId, + @JsonProperty("entityIri") String entityIri +) implements Request { + + public static final String CHANNEL = "webprotege.history.GetEntityHistorySummary"; + + public static GetEntityHistorySummaryRequest create(String projectId, + String entityIri) { + return new GetEntityHistorySummaryRequest(projectId, entityIri); + } + + @Override + public String getChannel() { + return CHANNEL; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryResponse.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryResponse.java new file mode 100644 index 0000000..f81c1d7 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetEntityHistorySummaryResponse.java @@ -0,0 +1,16 @@ +package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers; + +import com.fasterxml.jackson.annotation.*; +import edu.stanford.protege.webprotege.common.Response; +import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.EntityHistorySummary; + +import static edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers.GetEntityHistorySummaryRequest.CHANNEL; + +@JsonTypeName(CHANNEL) +public record GetEntityHistorySummaryResponse( + @JsonProperty("entityHistorySummary") EntityHistorySummary entityHistorySummary +) implements Response { + public static GetEntityHistorySummaryResponse create(EntityHistorySummary entityHistorySummary) { + return new GetEntityHistorySummaryResponse(entityHistorySummary); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.java index ffdaae2..a2b6203 100644 --- a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.java +++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.java @@ -1,5 +1,6 @@ package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.repositories; +import edu.stanford.protege.webprotege.common.ProjectId; import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.events.RevisionsEvent; import org.springframework.data.mongodb.repository.*; @@ -8,4 +9,7 @@ public interface RevisionsEventRepository extends MongoRepository { @Query("{ 'projectId.id': ?0, 'timestamp': { $gt: ?1 } }") List findByProjectIdAndTimestampAfter(String projectId, long timestamp); + + List findByProjectIdAndWhoficEntityIriOrderByTimestampDesc(ProjectId projectId, String whoficEntityIri); + } diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventService.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventService.java index e68ad28..0a52714 100644 --- a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventService.java +++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventService.java @@ -2,7 +2,7 @@ import edu.stanford.protege.webprotege.change.ProjectChange; import edu.stanford.protege.webprotege.common.*; -import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.ChangedEntities; +import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.*; import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.events.NewRevisionsEvent; import org.semanticweb.owlapi.model.OWLEntity; @@ -16,4 +16,6 @@ public interface NewRevisionsEventService { Page fetchPaginatedProjectChanges(ProjectId projectId, Optional subject, int pageNumber, int pageSize); ChangedEntities getChangedEntitiesAfterTimestamp(ProjectId projectId, Timestamp timestamp); + + EntityHistorySummary getEntityHistorySummary(ProjectId projectId, String entityIri); } diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventServiceImpl.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventServiceImpl.java index aedb8f3..f3413f9 100644 --- a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventServiceImpl.java +++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventServiceImpl.java @@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional; import java.sql.Timestamp; +import java.time.*; import java.util.*; import java.util.stream.Collectors; @@ -99,4 +100,20 @@ private static List groupByChangeType(List revisionsEven .distinct() .collect(Collectors.toList()); } + + @Override + public EntityHistorySummary getEntityHistorySummary(ProjectId projectId, String entityIri) { + List revisionsForEntity = repository.findByProjectIdAndWhoficEntityIriOrderByTimestampDesc(projectId, entityIri); + List entityChanges = revisionsForEntity.stream() + .map(revisionEvent -> { + ProjectChange projectChange = projectChangeMapper.mapProjectChangeDocumentToProjectChange(revisionEvent.projectChange()); + Instant instant = Instant.ofEpochMilli(projectChange.getTimestamp()); + LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("UTC")); + return EntityChange.create(projectChange.getSummary(), projectChange.getAuthor(), localDateTime); + } + ).toList(); + + + return EntityHistorySummary.create(entityChanges); + } }