From 4c26326ef4c5cb3151c5337f34b70736d19ed563 Mon Sep 17 00:00:00 2001 From: soimugeo Date: Thu, 14 Nov 2024 14:51:54 +0200 Subject: [PATCH 1/2] interim commit --- .../gateway/config/ApplicationBeans.java | 5 ++++ .../protege/gateway/dto/EntityChange.java | 10 ++++++++ .../protege/gateway/dto/EntityHistory.java | 9 +++++++ .../gateway/history/EntityHistoryService.java | 19 ++++++++++++-- .../gateway/history/HistoryController.java | 18 +++++++++---- .../GetEntityHistorySummaryRequest.java | 25 +++++++++++++++++++ .../GetEntityHistorySummaryResponse.java | 14 +++++++++++ ...O collection local.postman_collection.json | 4 +-- 8 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 src/main/java/edu/stanford/protege/gateway/dto/EntityChange.java create mode 100644 src/main/java/edu/stanford/protege/gateway/dto/EntityHistory.java create mode 100644 src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryRequest.java create mode 100644 src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryResponse.java 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/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/EntityHistory.java b/src/main/java/edu/stanford/protege/gateway/dto/EntityHistory.java new file mode 100644 index 0000000..6c154e3 --- /dev/null +++ b/src/main/java/edu/stanford/protege/gateway/dto/EntityHistory.java @@ -0,0 +1,9 @@ +package edu.stanford.protege.gateway.dto; + +import java.util.List; + +public record EntityHistory(List changes) { + public static EntityHistory create(List changes) { + return new EntityHistory(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..efef68e 100644 --- a/src/main/java/edu/stanford/protege/gateway/history/EntityHistoryService.java +++ b/src/main/java/edu/stanford/protege/gateway/history/EntityHistoryService.java @@ -1,14 +1,16 @@ 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.change.ProjectChange; import edu.stanford.protege.webprotege.common.ProjectId; import edu.stanford.protege.webprotege.ipc.CommandExecutor; import org.slf4j.*; import org.springframework.stereotype.Service; import java.sql.Timestamp; +import java.util.List; import java.util.concurrent.ExecutionException; @Service @@ -17,9 +19,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) { @@ -34,4 +39,14 @@ public ChangedEntities getChangedEntities(String projectId, Timestamp timestamp) } } + + public EntityHistory getEntityHistory(String projectId, String entityIri) { + EntityHistory entityHistory = entityHistorySummaryExecutor.execute(GetEntityHistorySummaryRequest.create(projectId,entityIri), SecurityContextHelper.getExecutionContext()) + .thenApply(response -> mapToEntityHistory(response.projectChangesForEntity())) + .get(); + return null; + } + + private Object mapToEntityHistory(List projectChangesForEntity) { + } } diff --git a/src/main/java/edu/stanford/protege/gateway/history/HistoryController.java b/src/main/java/edu/stanford/protege/gateway/history/HistoryController.java index 1c8d528..6c7972c 100644 --- a/src/main/java/edu/stanford/protege/gateway/history/HistoryController.java +++ b/src/main/java/edu/stanford/protege/gateway/history/HistoryController.java @@ -1,7 +1,7 @@ package edu.stanford.protege.gateway.history; -import edu.stanford.protege.gateway.dto.ChangedEntities; +import edu.stanford.protege.gateway.dto.*; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -19,16 +19,24 @@ public HistoryController(EntityHistoryService entityHistoryService) { this.entityHistoryService = entityHistoryService; } - @GetMapping("/entityChanges") + @GetMapping("/changedEntities") public ResponseEntity getEntityChanges(@RequestParam("projectId") String projectId, - @RequestParam("changedAfter") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - LocalDateTime changedAfter) { + @RequestParam("changedAfter") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + LocalDateTime changedAfter) { var timestamp = Timestamp.valueOf(changedAfter); ChangedEntities changedEntities = entityHistoryService.getChangedEntities(projectId, timestamp); return ResponseEntity.ok() .body(changedEntities); + } + + @GetMapping("/entityHistory") + public ResponseEntity getEntityHistory(@RequestParam("projectId") String projectId, + @RequestParam("entityIri") String entityIri) { + EntityHistory entityHistory = entityHistoryService.getEntityHistory(projectId, entityIri); + return ResponseEntity.ok() + .body(entityHistory); } } 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..087dd9d --- /dev/null +++ b/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryResponse.java @@ -0,0 +1,14 @@ +package edu.stanford.protege.gateway.history.commands; + +import com.fasterxml.jackson.annotation.*; +import edu.stanford.protege.webprotege.change.ProjectChange; +import edu.stanford.protege.webprotege.common.Response; + +import java.util.List; + +import static edu.stanford.protege.gateway.history.commands.GetEntityHistorySummaryRequest.CHANNEL; +@JsonTypeName(CHANNEL) +public record GetEntityHistorySummaryResponse( + @JsonProperty("projectChangesForEntity") List projectChangesForEntity +) 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": [ { From 3d3caff97c02bf4d7351e4dd1439a278a1fd6870 Mon Sep 17 00:00:00 2001 From: soimugeo Date: Thu, 14 Nov 2024 17:53:46 +0200 Subject: [PATCH 2/2] Added endpoint for getEntityHistorySummary --- .../controllers/HistoryController.java | 21 ++++++++++--------- .../protege/gateway/dto/EntityHistory.java | 9 -------- .../gateway/dto/EntityHistorySummary.java | 9 ++++++++ .../gateway/history/EntityHistoryService.java | 21 +++++++++---------- .../GetEntityHistorySummaryResponse.java | 7 +++---- 5 files changed, 33 insertions(+), 34 deletions(-) delete mode 100644 src/main/java/edu/stanford/protege/gateway/dto/EntityHistory.java create mode 100644 src/main/java/edu/stanford/protege/gateway/dto/EntityHistorySummary.java 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 94522e1..ece8963 100644 --- a/src/main/java/edu/stanford/protege/gateway/controllers/HistoryController.java +++ b/src/main/java/edu/stanford/protege/gateway/controllers/HistoryController.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.*; import java.sql.Timestamp; -import java.time.LocalDateTime; +import java.time.*; @RestController @RequestMapping("/history") @@ -21,23 +21,24 @@ public HistoryController(EntityHistoryService entityHistoryService) { } @GetMapping("/changedEntities") - public ResponseEntity getEntityChanges(@RequestParam("projectId") String projectId, - @RequestParam("changedAfter") + public ResponseEntity getChangedEntities(@RequestParam("projectId") String projectId, + @RequestParam("changedAfter") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - LocalDateTime changedAfter) { - var timestamp = Timestamp.valueOf(changedAfter); + 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("/entityHistory") - public ResponseEntity getEntityHistory(@RequestParam("projectId") String projectId, - @RequestParam("entityIri") String entityIri) { - EntityHistory entityHistory = entityHistoryService.getEntityHistory(projectId, entityIri); + @GetMapping("/entityHistorySummary") + public ResponseEntity getEntityHistorySummary(@RequestParam("projectId") String projectId, + @RequestParam("entityIri") String entityIri) { + EntityHistorySummary entityHistorySummary = entityHistoryService.getEntityHistorySummary(projectId, entityIri); return ResponseEntity.ok() - .body(entityHistory); + .body(entityHistorySummary); } } diff --git a/src/main/java/edu/stanford/protege/gateway/dto/EntityHistory.java b/src/main/java/edu/stanford/protege/gateway/dto/EntityHistory.java deleted file mode 100644 index 6c154e3..0000000 --- a/src/main/java/edu/stanford/protege/gateway/dto/EntityHistory.java +++ /dev/null @@ -1,9 +0,0 @@ -package edu.stanford.protege.gateway.dto; - -import java.util.List; - -public record EntityHistory(List changes) { - public static EntityHistory create(List changes) { - return new EntityHistory(changes); - } -} 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 efef68e..4f18643 100644 --- a/src/main/java/edu/stanford/protege/gateway/history/EntityHistoryService.java +++ b/src/main/java/edu/stanford/protege/gateway/history/EntityHistoryService.java @@ -3,14 +3,12 @@ import edu.stanford.protege.gateway.SecurityContextHelper; import edu.stanford.protege.gateway.dto.*; import edu.stanford.protege.gateway.history.commands.*; -import edu.stanford.protege.webprotege.change.ProjectChange; import edu.stanford.protege.webprotege.common.ProjectId; import edu.stanford.protege.webprotege.ipc.CommandExecutor; import org.slf4j.*; import org.springframework.stereotype.Service; import java.sql.Timestamp; -import java.util.List; import java.util.concurrent.ExecutionException; @Service @@ -34,19 +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 EntityHistory getEntityHistory(String projectId, String entityIri) { - EntityHistory entityHistory = entityHistorySummaryExecutor.execute(GetEntityHistorySummaryRequest.create(projectId,entityIri), SecurityContextHelper.getExecutionContext()) - .thenApply(response -> mapToEntityHistory(response.projectChangesForEntity())) - .get(); - return null; - } - - private Object mapToEntityHistory(List projectChangesForEntity) { + 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/GetEntityHistorySummaryResponse.java b/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryResponse.java index 087dd9d..f18e56e 100644 --- a/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryResponse.java +++ b/src/main/java/edu/stanford/protege/gateway/history/commands/GetEntityHistorySummaryResponse.java @@ -1,14 +1,13 @@ package edu.stanford.protege.gateway.history.commands; import com.fasterxml.jackson.annotation.*; -import edu.stanford.protege.webprotege.change.ProjectChange; +import edu.stanford.protege.gateway.dto.EntityHistorySummary; import edu.stanford.protege.webprotege.common.Response; -import java.util.List; - import static edu.stanford.protege.gateway.history.commands.GetEntityHistorySummaryRequest.CHANNEL; + @JsonTypeName(CHANNEL) public record GetEntityHistorySummaryResponse( - @JsonProperty("projectChangesForEntity") List projectChangesForEntity + @JsonProperty("entityHistorySummary") EntityHistorySummary entityHistorySummary ) implements Response { }