Skip to content

Commit

Permalink
changed response of getEntityChildren and getEntityHistorySummary to …
Browse files Browse the repository at this point in the history
…return projectId first and then entityIr in the response.
  • Loading branch information
soimugeoWB committed Jan 13, 2025
1 parent 0409bd0 commit 1a1c9c1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package edu.stanford.protege.gateway.controllers;


import edu.stanford.protege.gateway.dto.*;
import edu.stanford.protege.gateway.dto.ChangedEntities;
import edu.stanford.protege.gateway.dto.EntityHistorySummary;
import edu.stanford.protege.gateway.dto.EntityHistorySummaryDto;
import edu.stanford.protege.gateway.history.EntityHistoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.time.*;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

@RestController
@RequestMapping("/history")
Expand All @@ -27,8 +34,8 @@ public HistoryController(EntityHistoryService entityHistoryService) {
@Operation(summary = "Entities that have been updated since a certain time", operationId = "7_getChangedEntities")
public ResponseEntity<ChangedEntities> getChangedEntities(@RequestParam("projectId") String projectId,
@RequestParam("changedAfter")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
ZonedDateTime 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);
Expand All @@ -39,11 +46,16 @@ public ResponseEntity<ChangedEntities> getChangedEntities(@RequestParam("project

@GetMapping("/entity-summary")
@Operation(summary = "Change history for a single entity", operationId = "8_getEntityHistory")
public ResponseEntity<EntityHistorySummary> getEntityHistorySummary(@RequestParam("projectId") String projectId,
@RequestParam("entityIRI") String entityIRI) {
public ResponseEntity<EntityHistorySummaryDto> getEntityHistorySummary(@RequestParam("projectId") String projectId,
@RequestParam("entityIRI") String entityIRI) {
EntityHistorySummary entityHistorySummary = entityHistoryService.getEntityHistorySummary(projectId, entityIRI);
return ResponseEntity.ok()
.body(entityHistorySummary);
.body(EntityHistorySummaryDto.create(
entityHistorySummary.projectId(),
entityHistorySummary.entityUri(),
entityHistorySummary.changes()
)
);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ResponseEntity<EntityChildren> getEntityChildren(@PathVariable String pro
List<String> children = owlEntityService.getEntityChildren(entityIRI, projectId);

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.List;

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

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

public record EntityHistorySummaryDto(
@JsonProperty("projectId") String projectId,
@JsonProperty("entityUri") String entityUri,
@JsonProperty("changes") List<EntityChange> changes
) {
public static EntityHistorySummaryDto create(String entityUri,
String projectId,
List<EntityChange> changes) {
return new EntityHistorySummaryDto(entityUri, projectId, changes);
}
}

0 comments on commit 1a1c9c1

Please sign in to comment.