diff --git a/src/main/java/edu/stanford/protege/gateway/config/ApplicationBeans.java b/src/main/java/edu/stanford/protege/gateway/config/ApplicationBeans.java index d0dd8cb..db6f9c1 100644 --- a/src/main/java/edu/stanford/protege/gateway/config/ApplicationBeans.java +++ b/src/main/java/edu/stanford/protege/gateway/config/ApplicationBeans.java @@ -88,4 +88,9 @@ CommandExecutor entityChild return new CommandExecutorImpl<>(GetEntityChildrenResponse.class); } + @Bean + CommandExecutor getEntityHistorySummaryExecutor() { + return new CommandExecutorImpl<>(GetEntityHistorySummaryResponse.class); + } + } diff --git a/src/main/java/edu/stanford/protege/gateway/controllers/HistoryController.java b/src/main/java/edu/stanford/protege/gateway/controllers/HistoryController.java index 0b09a16..ece8963 100644 --- a/src/main/java/edu/stanford/protege/gateway/controllers/HistoryController.java +++ b/src/main/java/edu/stanford/protege/gateway/controllers/HistoryController.java @@ -1,14 +1,14 @@ package edu.stanford.protege.gateway.controllers; -import edu.stanford.protege.gateway.dto.ChangedEntities; +import edu.stanford.protege.gateway.dto.*; import edu.stanford.protege.gateway.history.EntityHistoryService; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.sql.Timestamp; -import java.time.LocalDateTime; +import java.time.*; @RestController @RequestMapping("/history") @@ -20,16 +20,25 @@ public HistoryController(EntityHistoryService entityHistoryService) { this.entityHistoryService = entityHistoryService; } - @GetMapping("/entityChanges") - public ResponseEntity getEntityChanges(@RequestParam("projectId") String projectId, - @RequestParam("changedAfter") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - LocalDateTime changedAfter) { - var timestamp = Timestamp.valueOf(changedAfter); + @GetMapping("/changedEntities") + public ResponseEntity getChangedEntities(@RequestParam("projectId") String projectId, + @RequestParam("changedAfter") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + ZonedDateTime changedAfter) { + LocalDateTime utcDateTime = changedAfter.withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime(); + Timestamp timestamp = Timestamp.valueOf(utcDateTime); ChangedEntities changedEntities = entityHistoryService.getChangedEntities(projectId, timestamp); return ResponseEntity.ok() .body(changedEntities); + } + + @GetMapping("/entityHistorySummary") + public ResponseEntity getEntityHistorySummary(@RequestParam("projectId") String projectId, + @RequestParam("entityIri") String entityIri) { + EntityHistorySummary entityHistorySummary = entityHistoryService.getEntityHistorySummary(projectId, entityIri); + return ResponseEntity.ok() + .body(entityHistorySummary); } } diff --git a/src/main/java/edu/stanford/protege/gateway/dto/EntityChange.java b/src/main/java/edu/stanford/protege/gateway/dto/EntityChange.java new file mode 100644 index 0000000..0d4d218 --- /dev/null +++ b/src/main/java/edu/stanford/protege/gateway/dto/EntityChange.java @@ -0,0 +1,10 @@ +package edu.stanford.protege.gateway.dto; + +import edu.stanford.protege.webprotege.common.UserId; + +import java.time.LocalDateTime; + +public record EntityChange(String changeSummary, + UserId userId, + LocalDateTime dateTime) { +} diff --git a/src/main/java/edu/stanford/protege/gateway/dto/EntityHistorySummary.java b/src/main/java/edu/stanford/protege/gateway/dto/EntityHistorySummary.java new file mode 100644 index 0000000..843996f --- /dev/null +++ b/src/main/java/edu/stanford/protege/gateway/dto/EntityHistorySummary.java @@ -0,0 +1,9 @@ +package edu.stanford.protege.gateway.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/gateway/history/EntityHistoryService.java b/src/main/java/edu/stanford/protege/gateway/history/EntityHistoryService.java index 53c49b6..4f18643 100644 --- a/src/main/java/edu/stanford/protege/gateway/history/EntityHistoryService.java +++ b/src/main/java/edu/stanford/protege/gateway/history/EntityHistoryService.java @@ -1,7 +1,7 @@ package edu.stanford.protege.gateway.history; import edu.stanford.protege.gateway.SecurityContextHelper; -import edu.stanford.protege.gateway.dto.ChangedEntities; +import edu.stanford.protege.gateway.dto.*; import edu.stanford.protege.gateway.history.commands.*; import edu.stanford.protege.webprotege.common.ProjectId; import edu.stanford.protege.webprotege.ipc.CommandExecutor; @@ -17,9 +17,12 @@ public class EntityHistoryService { private final static Logger LOGGER = LoggerFactory.getLogger(EntityHistoryService.class); private final CommandExecutor changedEntitiesExecutor; + private final CommandExecutor entityHistorySummaryExecutor; - public EntityHistoryService(CommandExecutor changedEntitiesExecutor) { + public EntityHistoryService(CommandExecutor changedEntitiesExecutor, + CommandExecutor entityHistorySummaryExecutor) { this.changedEntitiesExecutor = changedEntitiesExecutor; + this.entityHistorySummaryExecutor = entityHistorySummaryExecutor; } public ChangedEntities getChangedEntities(String projectId, Timestamp timestamp) { @@ -29,9 +32,20 @@ public ChangedEntities getChangedEntities(String projectId, Timestamp timestamp) .thenApply(GetChangedEntitiesResponse::changedEntities) .get(); } catch (InterruptedException | ExecutionException e) { - LOGGER.error("Error while requestion changed entities"); + LOGGER.error("Error while requestion changed entities." + e.getMessage()); throw new RuntimeException(e); } } + + public EntityHistorySummary getEntityHistorySummary(String projectId, String entityIri) { + try { + return entityHistorySummaryExecutor.execute(GetEntityHistorySummaryRequest.create(projectId, entityIri), SecurityContextHelper.getExecutionContext()) + .thenApply(GetEntityHistorySummaryResponse::entityHistorySummary) + .get(); + } catch (InterruptedException | ExecutionException e) { + LOGGER.error("Error while requestion entity history summary. " + e.getMessage()); + throw new RuntimeException(e); + } + } } diff --git a/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryRequest.java b/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryRequest.java new file mode 100644 index 0000000..c11bfd7 --- /dev/null +++ b/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryRequest.java @@ -0,0 +1,25 @@ +package edu.stanford.protege.gateway.history.commands; + +import com.fasterxml.jackson.annotation.*; +import edu.stanford.protege.webprotege.common.Request; + +import static edu.stanford.protege.gateway.history.commands.GetEntityHistorySummaryRequest.CHANNEL; + +@JsonTypeName(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/gateway/history/commands/GetEntityHistorySummaryResponse.java b/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryResponse.java new file mode 100644 index 0000000..f18e56e --- /dev/null +++ b/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryResponse.java @@ -0,0 +1,13 @@ +package edu.stanford.protege.gateway.history.commands; + +import com.fasterxml.jackson.annotation.*; +import edu.stanford.protege.gateway.dto.EntityHistorySummary; +import edu.stanford.protege.webprotege.common.Response; + +import static edu.stanford.protege.gateway.history.commands.GetEntityHistorySummaryRequest.CHANNEL; + +@JsonTypeName(CHANNEL) +public record GetEntityHistorySummaryResponse( + @JsonProperty("entityHistorySummary") EntityHistorySummary entityHistorySummary +) implements Response { +} diff --git a/src/main/resources/WHO collection local.postman_collection.json b/src/main/resources/WHO collection local.postman_collection.json index fc21eab..c06b09f 100644 --- a/src/main/resources/WHO collection local.postman_collection.json +++ b/src/main/resources/WHO collection local.postman_collection.json @@ -203,7 +203,7 @@ } ], "url": { - "raw": "http://localhost:7779/icat/history/entityChanges?projectId=03a3f282-8671-45bf-901e-362e0e1ac3e2&changedAfter=2024-11-12T19:00:50Z", + "raw": "http://localhost:7779/icat/history/changedEntities?projectId=03a3f282-8671-45bf-901e-362e0e1ac3e2&changedAfter=2024-11-12T19:00:50Z", "protocol": "http", "host": [ "localhost" @@ -212,7 +212,7 @@ "path": [ "icat", "history", - "entityChanges" + "changedEntities" ], "query": [ {