Skip to content

Commit

Permalink
fixed #19
Browse files Browse the repository at this point in the history
  • Loading branch information
soimugeoWB committed Jan 3, 2025
1 parent 6b9adf7 commit 0409bd0
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.http.*;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -40,26 +41,26 @@ public ResponseEntity<List<ProjectSummaryDto>> getProjects() {

@GetMapping(value = "/{projectId}")
@Operation(summary = "Reading an entity", operationId = "2_getEntity")
public ResponseEntity<OWLEntityDto> getEntity(@PathVariable @javax.annotation.Nonnull String projectId, @RequestParam String entityIRI){
public ResponseEntity<OWLEntityDto> getEntity(@PathVariable @javax.annotation.Nonnull String projectId, @RequestParam String entityIRI) {
OWLEntityDto dto = owlEntityService.getEntityInfo(entityIRI, projectId);
return getOwlEntityDtoResponseEntity(dto);
}

@PutMapping(value = "/{projectId}/entities")
@Operation(summary = "Updating an entity", operationId = "3_updateEntity")
public ResponseEntity<OWLEntityDto> updateEntity( @RequestHeader(value = "If-Match", required = false) String ifMatch,
@PathVariable @Nonnull String projectId,
@RequestBody OWLEntityDto owlEntityDto){
OWLEntityDto response = owlEntityService.updateEntity(owlEntityDto, projectId,ifMatch);
public ResponseEntity<OWLEntityDto> updateEntity(@RequestHeader(value = "If-Match", required = false) String ifMatch,
@PathVariable @Nonnull String projectId,
@RequestBody OWLEntityDto owlEntityDto) {
OWLEntityDto response = owlEntityService.updateEntity(owlEntityDto, projectId, ifMatch);
return getOwlEntityDtoResponseEntity(response);
}

@PostMapping(value = "/{projectId}/entities")
@Operation(summary = "Adding a new entity", operationId = "4_createEntity")
public ResponseEntity<OWLEntityDto> createEntity(@PathVariable("projectId")
@NotNull(message = "Project ID cannot be null")
String projectId,
@RequestBody CreateEntityDto createEntityDto) {
@NotNull(message = "Project ID cannot be null")
String projectId,
@RequestBody CreateEntityDto createEntityDto) {
var newCreatedIri = owlEntityService.createClassEntity(projectId, createEntityDto);
OWLEntityDto result = owlEntityService.getEntityInfo(newCreatedIri, projectId);
return getOwlEntityDtoResponseEntity(result);
Expand All @@ -72,7 +73,7 @@ public ResponseEntity<EntityChildren> getEntityChildren(@PathVariable String pro
List<String> children = owlEntityService.getEntityChildren(entityIRI, projectId);

return ResponseEntity.ok()
.body(EntityChildren.create(children));
.body(EntityChildren.create(entityIRI, projectId, children));
}


Expand Down
13 changes: 10 additions & 3 deletions src/main/java/edu/stanford/protege/gateway/dto/EntityChildren.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

import java.util.List;

public record EntityChildren(@JsonProperty("children") List<String> children) {
public static EntityChildren create(List<String> children) {
return new EntityChildren(children);
public record EntityChildren(
@JsonProperty("entityUri") String entityUri,
@JsonProperty("projectId") String projectId,
@JsonProperty("children") List<String> children
) {
public static EntityChildren create(
String entityUri,
String projectId,
List<String> children) {
return new EntityChildren(entityUri, projectId, children);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package edu.stanford.protege.gateway.dto;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

public record EntityHistorySummary(List<EntityChange> changes) {
public static EntityHistorySummary create(List<EntityChange> changes) {
return new EntityHistorySummary(changes);
public record EntityHistorySummary(
@JsonProperty("entityUri") String entityUri,
@JsonProperty("projectId") String projectId,
@JsonProperty("changes") List<EntityChange> changes
) {
public static EntityHistorySummary create(String entityUri,
String projectId,
List<EntityChange> changes) {
return new EntityHistorySummary(entityUri, projectId, changes);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package edu.stanford.protege.gateway.history;

import edu.stanford.protege.gateway.SecurityContextHelper;
import edu.stanford.protege.gateway.dto.*;
import edu.stanford.protege.gateway.history.commands.*;
import edu.stanford.protege.gateway.dto.ChangedEntities;
import edu.stanford.protege.gateway.dto.EntityChange;
import edu.stanford.protege.gateway.dto.EntityHistorySummary;
import edu.stanford.protege.gateway.history.commands.GetChangedEntitiesRequest;
import edu.stanford.protege.gateway.history.commands.GetChangedEntitiesResponse;
import edu.stanford.protege.gateway.history.commands.GetEntityHistorySummaryRequest;
import edu.stanford.protege.gateway.history.commands.GetEntityHistorySummaryResponse;
import edu.stanford.protege.gateway.validators.ValidatorService;
import edu.stanford.protege.webprotege.common.ProjectId;
import edu.stanford.protege.webprotege.ipc.CommandExecutor;
import edu.stanford.protege.webprotege.ipc.ExecutionContext;
import org.slf4j.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

Expand All @@ -21,16 +28,20 @@ public class EntityHistoryService {

private final static Logger LOGGER = LoggerFactory.getLogger(EntityHistoryService.class);

private final ValidatorService validatorService;

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

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

public ChangedEntities getChangedEntities(String projectId, Timestamp timestamp) {
validatorService.validateProjectId(projectId);

try {
return changedEntitiesExecutor.execute(GetChangedEntitiesRequest.create(ProjectId.valueOf(projectId), timestamp), SecurityContextHelper.getExecutionContext())
Expand All @@ -44,6 +55,8 @@ public ChangedEntities getChangedEntities(String projectId, Timestamp timestamp)
}

public EntityHistorySummary getEntityHistorySummary(String projectId, String entityIri) {
validatorService.validateProjectId(projectId);
validatorService.validateEntityExists(projectId, entityIri);
try {
return entityHistorySummaryExecutor.execute(GetEntityHistorySummaryRequest.create(projectId, entityIri), SecurityContextHelper.getExecutionContext())
.thenApply(GetEntityHistorySummaryResponse::entityHistorySummary)
Expand All @@ -53,13 +66,16 @@ public EntityHistorySummary getEntityHistorySummary(String projectId, String ent
throw new RuntimeException(e);
}
}
public CompletableFuture<LocalDateTime> getEntityLatestChangeTime(String projectId, String entityIri){

public CompletableFuture<LocalDateTime> getEntityLatestChangeTime(String projectId, String entityIri) {
return getEntityLatestChangeTime(projectId, entityIri, SecurityContextHelper.getExecutionContext());
}


@Async
public CompletableFuture<LocalDateTime> getEntityLatestChangeTime(String projectId, String entityIri, ExecutionContext executionContext) {
validatorService.validateProjectId(projectId);
validatorService.validateEntityExists(projectId, entityIri);
return entityHistorySummaryExecutor.execute(new GetEntityHistorySummaryRequest(projectId, entityIri), executionContext)
.thenApply(response -> {
if (response.entityHistorySummary() != null && response.entityHistorySummary().changes() != null && response.entityHistorySummary().changes().size() > 0) {
Expand Down
Loading

0 comments on commit 0409bd0

Please sign in to comment.