Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 change history for a single entity #7

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ CommandExecutor<GetEntityChildrenRequest, GetEntityChildrenResponse> entityChild
return new CommandExecutorImpl<>(GetEntityChildrenResponse.class);
}

@Bean
CommandExecutor<GetEntityHistorySummaryRequest, GetEntityHistorySummaryResponse> getEntityHistorySummaryExecutor() {
return new CommandExecutorImpl<>(GetEntityHistorySummaryResponse.class);
}

}
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -20,16 +20,25 @@ public HistoryController(EntityHistoryService entityHistoryService) {
this.entityHistoryService = entityHistoryService;
}

@GetMapping("/entityChanges")
public ResponseEntity<ChangedEntities> getEntityChanges(@RequestParam("projectId") String projectId,
@RequestParam("changedAfter")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime changedAfter) {
var timestamp = Timestamp.valueOf(changedAfter);
@GetMapping("/changedEntities")
public ResponseEntity<ChangedEntities> 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<EntityHistorySummary> getEntityHistorySummary(@RequestParam("projectId") String projectId,
@RequestParam("entityIri") String entityIri) {
EntityHistorySummary entityHistorySummary = entityHistoryService.getEntityHistorySummary(projectId, entityIri);
return ResponseEntity.ok()
.body(entityHistorySummary);

}
}
10 changes: 10 additions & 0 deletions src/main/java/edu/stanford/protege/gateway/dto/EntityChange.java
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.stanford.protege.gateway.dto;

import java.util.List;

public record EntityHistorySummary(List<EntityChange> changes) {
public static EntityHistorySummary create(List<EntityChange> changes) {
return new EntityHistorySummary(changes);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,9 +17,12 @@ public class EntityHistoryService {
private final static Logger LOGGER = LoggerFactory.getLogger(EntityHistoryService.class);

private final CommandExecutor<GetChangedEntitiesRequest, GetChangedEntitiesResponse> changedEntitiesExecutor;
private final CommandExecutor<GetEntityHistorySummaryRequest, GetEntityHistorySummaryResponse> entityHistorySummaryExecutor;

public EntityHistoryService(CommandExecutor<GetChangedEntitiesRequest, GetChangedEntitiesResponse> changedEntitiesExecutor) {
public EntityHistoryService(CommandExecutor<GetChangedEntitiesRequest, GetChangedEntitiesResponse> changedEntitiesExecutor,
CommandExecutor<GetEntityHistorySummaryRequest, GetEntityHistorySummaryResponse> entityHistorySummaryExecutor) {
this.changedEntitiesExecutor = changedEntitiesExecutor;
this.entityHistorySummaryExecutor = entityHistorySummaryExecutor;
}

public ChangedEntities getChangedEntities(String projectId, Timestamp timestamp) {
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<GetEntityHistorySummaryResponse> {

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;
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -212,7 +212,7 @@
"path": [
"icat",
"history",
"entityChanges"
"changedEntities"
],
"query": [
{
Expand Down