From 605e200eb0b9e8685ab888d2507f011738ea59f3 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Tue, 17 Sep 2024 10:31:12 +0300 Subject: [PATCH 1/6] partial commit --- .../dto/GetEntityPostCoordinationRequest.java | 21 +++++++++++++ .../GetEntityPostCoordinationResponse.java | 17 +++++++++++ .../PostCoordinationSpecificationRequest.java | 1 - .../events/PostCoordinationEvent.java | 2 -- ...tEntityPostCoordinationCommandHandler.java | 30 +++++++++++++++++++ .../model/PostCoordinationRevision.java | 30 ++----------------- ...tCoordinationSpecificationsRepository.java | 22 +++++++++++++- .../PostCoordinationEventProcessor.java | 9 ++++++ .../services/PostCoordinationService.java | 18 +++++++++-- .../services/PostCoordinationServiceTest.java | 5 ++-- 10 files changed, 118 insertions(+), 37 deletions(-) create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationRequest.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationResponse.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationRequest.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationRequest.java new file mode 100644 index 0000000..388911e --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationRequest.java @@ -0,0 +1,21 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import edu.stanford.protege.webprotege.common.ProjectId; +import edu.stanford.protege.webprotege.common.Request; + +import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationRequest.CHANNEL; + +@JsonTypeName(CHANNEL) +public record GetEntityPostCoordinationRequest(@JsonProperty("entityIRI") String entityIRI, + @JsonProperty("projectId") ProjectId projectId) implements Request { + + public static final String CHANNEL = "webprotege.postcoordination.GetEntityPostCoordinations"; + + @Override + public String getChannel() { + return CHANNEL; + } + +} \ No newline at end of file diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationResponse.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationResponse.java new file mode 100644 index 0000000..5c398d2 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationResponse.java @@ -0,0 +1,17 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import edu.stanford.protege.webprotege.common.Response; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; + +import java.util.List; + +import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationRequest.CHANNEL; + +@JsonTypeName(CHANNEL) +public record GetEntityPostCoordinationResponse(@JsonProperty("entityIri") + String entityIri, + @JsonProperty("postcoordinationSpecifications") + List postCoordinationSpecifications) implements Response { +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecificationRequest.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecificationRequest.java index 50ca8ef..17e2f91 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecificationRequest.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecificationRequest.java @@ -11,7 +11,6 @@ public class PostCoordinationSpecificationRequest extends EventProcessableParame private final String linearizationView; - private final List allowedAxes; private final List defaultAxes; diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java index 981b882..c9bbaa3 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java @@ -20,8 +20,6 @@ }) public abstract class PostCoordinationEvent { - - @Field("postCoordinationAxis") private final String postCoordinationAxis; diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java new file mode 100644 index 0000000..ef32ccc --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java @@ -0,0 +1,30 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.handlers; + + +import edu.stanford.protege.webprotege.ipc.CommandHandler; +import edu.stanford.protege.webprotege.ipc.ExecutionContext; +import edu.stanford.protege.webprotege.ipc.WebProtegeHandler; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationResponse; +import org.jetbrains.annotations.NotNull; +import reactor.core.publisher.Mono; + +@WebProtegeHandler +public class GetEntityPostCoordinationCommandHandler implements CommandHandler { + + @NotNull + @Override + public String getChannelName() { + return GetEntityPostCoordinationRequest.CHANNEL; + } + + @Override + public Class getRequestClass() { + return null; + } + + @Override + public Mono handleRequest(GetEntityPostCoordinationRequest request, ExecutionContext executionContext) { + return null; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationRevision.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationRevision.java index 077d19e..2d053eb 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationRevision.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationRevision.java @@ -2,34 +2,10 @@ import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; -import java.util.List; import java.util.Set; -public class PostCoordinationRevision { - public static final String LINEARIZATION_HISTORY_COLLECTION = "EntityPostCoordinationHistory"; +public record PostCoordinationRevision(String userId, + Long timestamp, + Set postCoordinationEventList) { - private final String userId; - - private final Long timestamp; - - private final Set postCoordinationEventList; - - - public PostCoordinationRevision(String userId, Long timestamp, Set postCoordinationEventList) { - this.userId = userId; - this.timestamp = timestamp; - this.postCoordinationEventList = postCoordinationEventList; - } - - public String getUserId() { - return userId; - } - - public Long getTimestamp() { - return timestamp; - } - - public Set getPostCoordinationEventList() { - return postCoordinationEventList; - } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java index fd5b1b7..5f26a03 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java @@ -2,16 +2,27 @@ import com.mongodb.client.model.InsertOneModel; +import edu.stanford.protege.webprotege.common.ProjectId; import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; import edu.stanford.protege.webprotege.postcoordinationservice.services.ReadWriteLockService; import org.bson.Document; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; + +import static edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory.POSTCOORDINATION_HISTORY_COLLECTION; @Repository public class PostCoordinationSpecificationsRepository { + + public static final String WHOFIC_ENTITY_IRI = "whoficEntityIri"; + public static final String PROJECT_ID = "projectId"; + + private final MongoTemplate mongoTemplate; private final ReadWriteLockService readWriteLock; @@ -23,10 +34,19 @@ public PostCoordinationSpecificationsRepository(MongoTemplate mongoTemplate, Rea public void bulkWriteDocuments(List> listOfInsertOneModelDocument) { readWriteLock.executeWriteLock(() -> { - var collection = mongoTemplate.getCollection(EntityPostCoordinationHistory.POSTCOORDINATION_HISTORY_COLLECTION); + var collection = mongoTemplate.getCollection(POSTCOORDINATION_HISTORY_COLLECTION); collection.bulkWrite(listOfInsertOneModelDocument); }); } + public Optional findHistoryByEntityIriAndProjectId(String entityIri, ProjectId projectId) { + + Query query = new Query(); + query.addCriteria( + Criteria.where(WHOFIC_ENTITY_IRI).is(entityIri) + .and(PROJECT_ID).is(projectId.value()) + ); + return readWriteLock.executeReadLock(() -> Optional.ofNullable(mongoTemplate.findOne(query, EntityPostCoordinationHistory.class, POSTCOORDINATION_HISTORY_COLLECTION))); + } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java new file mode 100644 index 0000000..36586ef --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java @@ -0,0 +1,9 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.services; + +import org.springframework.stereotype.Service; + +@Service +public class PostCoordinationEventProcessor { + + +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java index 3336c41..c8f68c7 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java @@ -17,6 +17,7 @@ import edu.stanford.protege.webprotege.postcoordinationservice.repositories.PostCoordinationSpecificationsRepository; import edu.stanford.protege.webprotege.postcoordinationservice.repositories.PostCoordinationTableConfigRepository; import org.bson.Document; +import org.semanticweb.owlapi.model.IRI; import org.springframework.stereotype.Service; import java.util.*; @@ -62,9 +63,20 @@ public void createFirstImport(String documentLocation, ProjectId projectId, User stream.collect(StreamUtils.batchCollector(500, createBatchProcessorForSavingPaginatedHistories(projectId, userId, definitionList, configurations))); }); } + Optional getExistingHistoryOrderedByRevision(IRI entityIri, ProjectId projectId) { + return specRepository.findHistoryByEntityIriAndProjectId(entityIri.toString(), projectId) + .map(history -> { + Set sortedRevisions = history.getPostCoordinationRevisions() + .stream() + .sorted(Comparator.comparingLong(PostCoordinationRevision::timestamp)) + .collect(Collectors.toCollection(TreeSet::new)); + // Return a new EntityLinearizationHistory object with the sorted revisions + return new EntityPostCoordinationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions); + }); + } - public Consumer> createBatchProcessorForSavingPaginatedHistories(ProjectId projectId, UserId userId , List definitionList, List configurations) { + private Consumer> createBatchProcessorForSavingPaginatedHistories(ProjectId projectId, UserId userId , List definitionList, List configurations) { return page -> { if (isNotEmpty(page)) { Set histories = new HashSet<>(); @@ -83,7 +95,7 @@ public Consumer> createBatchProc }; } - public void saveMultipleEntityPostCoordinationHistories(Set historiesToBeSaved) { + private void saveMultipleEntityPostCoordinationHistories(Set historiesToBeSaved) { var documents = historiesToBeSaved.stream() .map(history -> new InsertOneModel<>(objectMapper.convertValue(history, Document.class))) .toList(); @@ -92,7 +104,7 @@ public void saveMultipleEntityPostCoordinationHistories(Set definitionList, List configurations) { + PostCoordinationSpecificationRequest enrichWithMissingAxis(String entityType, PostCoordinationSpecificationRequest specification, List definitionList, List configurations) { LinearizationDefinition definition = definitionList.stream() .filter(linearizationDefinition -> linearizationDefinition.getWhoficEntityIri().equalsIgnoreCase(specification.getLinearizationView())) .findFirst() diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java index 6f96616..bfddfc5 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java @@ -12,7 +12,6 @@ import edu.stanford.protege.webprotege.postcoordinationservice.model.TableConfiguration; import edu.stanford.protege.webprotege.postcoordinationservice.repositories.MinioPostCoordinationDocumentLoader; import org.bson.Document; -import org.junit.Before; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -134,8 +133,8 @@ public void GIVEN_existingFile_WHEN_firstImport_THEN_allEventsAreGenerated() { .findFirst().orElse(null); assertNotNull(history); assertEquals(1, history.getPostCoordinationRevisions().size()); - assertEquals("alexsilaghi", history.getPostCoordinationRevisions().iterator().next().getUserId()); - assertNotNull(history.getPostCoordinationRevisions().iterator().next().getPostCoordinationEventList()); + assertEquals("alexsilaghi", history.getPostCoordinationRevisions().iterator().next().userId()); + assertNotNull(history.getPostCoordinationRevisions().iterator().next().postCoordinationEventList()); } } \ No newline at end of file From 4ac80307c91f3d07bc27f837ca64f16a5f85ac06 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Thu, 19 Sep 2024 09:03:24 +0300 Subject: [PATCH 2/6] partial commit --- .../GetEntityPostCoordinationResponse.java | 6 +- ...ava => PostCoordinationSpecification.java} | 12 +- .../events/AddToAllowedAxisEvent.java | 7 +- .../events/AddToDefaultAxisEvent.java | 7 +- .../events/AddToNotAllowedAxisEvent.java | 7 +- .../events/AddToRequiredAxisEvent.java | 7 +- .../events/PostCoordinationEvent.java | 6 +- ...tEntityPostCoordinationCommandHandler.java | 24 +- .../mappers/SpecificationToEventsMapper.java | 4 +- .../model/EntityPostCoordinationHistory.java | 7 +- .../model/PostCoordinationRevision.java | 3 +- .../model/PostCoordinationViewEvent.java | 13 + ...icEntityPostCoordinationSpecification.java | 27 +- ...tCoordinationSpecificationsRepository.java | 7 + .../PostCoordinationEventProcessor.java | 33 ++ .../services/PostCoordinationService.java | 46 ++- .../SpecificationToEventsMapperTest.java | 4 +- ...ostCoordinationDocumentRepositoryTest.java | 6 +- .../PostCoordinationEventProcessorTest.java | 86 +++++ .../services/PostCoordinationServiceTest.java | 12 +- .../processedPostCoordinationHistory.json | 354 ++++++++++++++++++ 21 files changed, 590 insertions(+), 88 deletions(-) rename src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/{PostCoordinationSpecificationRequest.java => PostCoordinationSpecification.java} (69%) create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationViewEvent.java create mode 100644 src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessorTest.java create mode 100644 src/test/resources/processedPostCoordinationHistory.json diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationResponse.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationResponse.java index 5c398d2..0146c61 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationResponse.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityPostCoordinationResponse.java @@ -5,13 +5,11 @@ import edu.stanford.protege.webprotege.common.Response; import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; -import java.util.List; - import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationRequest.CHANNEL; @JsonTypeName(CHANNEL) public record GetEntityPostCoordinationResponse(@JsonProperty("entityIri") String entityIri, - @JsonProperty("postcoordinationSpecifications") - List postCoordinationSpecifications) implements Response { + @JsonProperty("postCoordinationSpecification") + WhoficEntityPostCoordinationSpecification postCoordinationSpecification) implements Response { } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecificationRequest.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecification.java similarity index 69% rename from src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecificationRequest.java rename to src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecification.java index 17e2f91..4d86810 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecificationRequest.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationSpecification.java @@ -7,7 +7,7 @@ import java.util.ArrayList; import java.util.List; -public class PostCoordinationSpecificationRequest extends EventProcessableParameter { +public class PostCoordinationSpecification extends EventProcessableParameter { private final String linearizationView; @@ -20,11 +20,11 @@ public class PostCoordinationSpecificationRequest extends EventProcessableParame private final List requiredAxes; @JsonCreator - public PostCoordinationSpecificationRequest(@JsonProperty("linearizationView") String linearizationView, - @JsonProperty("allowedAxes") List allowedAxes, - @JsonProperty("defaultAxes") List defaultAxes, - @JsonProperty("notAllowedAxes") List notAllowedAxes, - @JsonProperty("requiredAxes") List requiredAxes) { + public PostCoordinationSpecification(@JsonProperty("linearizationView") String linearizationView, + @JsonProperty("allowedAxes") List allowedAxes, + @JsonProperty("defaultAxes") List defaultAxes, + @JsonProperty("notAllowedAxes") List notAllowedAxes, + @JsonProperty("requiredAxes") List requiredAxes) { this.linearizationView = linearizationView; this.allowedAxes = allowedAxes == null ? new ArrayList<>() : allowedAxes; this.defaultAxes = defaultAxes == null ? new ArrayList<>() : defaultAxes; diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToAllowedAxisEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToAllowedAxisEvent.java index adedfa6..f7942c0 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToAllowedAxisEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToAllowedAxisEvent.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; public class AddToAllowedAxisEvent extends PostCoordinationEvent { @@ -21,8 +21,9 @@ String getType() { } @Override - PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input) { - return null; + PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input) { + input.getAllowedAxes().add(this.getPostCoordinationAxis()); + return input; } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToDefaultAxisEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToDefaultAxisEvent.java index 580264b..d69d783 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToDefaultAxisEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToDefaultAxisEvent.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; public class AddToDefaultAxisEvent extends PostCoordinationEvent { @@ -20,7 +20,8 @@ String getType() { } @Override - PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input) { - return null; + PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input) { + input.getDefaultAxes().add(this.getPostCoordinationAxis()); + return input; } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToNotAllowedAxisEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToNotAllowedAxisEvent.java index 45b0d1d..c1471bd 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToNotAllowedAxisEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToNotAllowedAxisEvent.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; public class AddToNotAllowedAxisEvent extends PostCoordinationEvent { @@ -20,8 +20,9 @@ String getType() { } @Override - PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input) { - return null; + PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input) { + input.getNotAllowedAxes().add(this.getPostCoordinationAxis()); + return input; } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToRequiredAxisEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToRequiredAxisEvent.java index e9e6ca3..2251351 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToRequiredAxisEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToRequiredAxisEvent.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; public class AddToRequiredAxisEvent extends PostCoordinationEvent { @@ -20,7 +20,8 @@ String getType() { } @Override - PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input) { - return null; + PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input) { + input.getRequiredAxes().add(this.getPostCoordinationAxis()); + return input; } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java index c9bbaa3..a082be2 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.*; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; import org.bson.codecs.pojo.annotations.BsonDiscriminator; import org.springframework.data.mongodb.core.mapping.Field; @@ -34,7 +34,7 @@ protected PostCoordinationEvent(String postCoordinationAxis, String linearizatio @JsonProperty("@type") abstract String getType(); - public PostCoordinationSpecificationRequest applyEvent(PostCoordinationSpecificationRequest input) { + public PostCoordinationSpecification applyEvent(PostCoordinationSpecification input) { input.getAllowedAxes().remove(this.postCoordinationAxis); input.getDefaultAxes().remove(this.postCoordinationAxis); input.getNotAllowedAxes().remove(this.postCoordinationAxis); @@ -42,7 +42,7 @@ public PostCoordinationSpecificationRequest applyEvent(PostCoordinationSpecifica return applySpecificEvent(input); } - abstract PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input); + abstract PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input); @Field("postCoordinationAxis") diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java index ef32ccc..a3c7fbe 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java @@ -6,12 +6,26 @@ import edu.stanford.protege.webprotege.ipc.WebProtegeHandler; import edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationRequest; import edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationResponse; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.services.PostCoordinationEventProcessor; +import edu.stanford.protege.webprotege.postcoordinationservice.services.PostCoordinationService; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Mono; +import java.util.Collections; + @WebProtegeHandler public class GetEntityPostCoordinationCommandHandler implements CommandHandler { + private final PostCoordinationService postCoordinationService; + + private final PostCoordinationEventProcessor postCoordinationEventProcessor; + + public GetEntityPostCoordinationCommandHandler(PostCoordinationService postCoordinationService, PostCoordinationEventProcessor postCoordinationEventProcessor) { + this.postCoordinationService = postCoordinationService; + this.postCoordinationEventProcessor = postCoordinationEventProcessor; + } + @NotNull @Override public String getChannelName() { @@ -20,11 +34,17 @@ public String getChannelName() { @Override public Class getRequestClass() { - return null; + return GetEntityPostCoordinationRequest.class; } @Override public Mono handleRequest(GetEntityPostCoordinationRequest request, ExecutionContext executionContext) { - return null; + + WhoficEntityPostCoordinationSpecification processedSpec = + this.postCoordinationService.getExistingHistoryOrderedByRevision(request.entityIRI(), request.projectId()) + .map(postCoordinationEventProcessor::processHistory) + .orElseGet(() -> new WhoficEntityPostCoordinationSpecification(request.entityIRI(), null, Collections.emptyList())); + + return Mono.just(new GetEntityPostCoordinationResponse(request.entityIRI(), processedSpec)); } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapper.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapper.java index 7bb5da0..f84e178 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapper.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapper.java @@ -1,7 +1,7 @@ package edu.stanford.protege.webprotege.postcoordinationservice.mappers; import edu.stanford.protege.webprotege.postcoordinationservice.events.*; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; import java.util.ArrayList; import java.util.List; @@ -10,7 +10,7 @@ public class SpecificationToEventsMapper { - public static List convertFromSpecification(PostCoordinationSpecificationRequest specification) { + public static List convertFromSpecification(PostCoordinationSpecification specification) { List response = new ArrayList<>(); response.addAll(specification.getAllowedAxes().stream().map(axis -> new AddToAllowedAxisEvent(axis, specification.getLinearizationView())).toList()); diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityPostCoordinationHistory.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityPostCoordinationHistory.java index 9a6b8e8..9537a4f 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityPostCoordinationHistory.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityPostCoordinationHistory.java @@ -6,6 +6,7 @@ import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Field; +import java.util.List; import java.util.Objects; import java.util.Set; @@ -24,13 +25,13 @@ public class EntityPostCoordinationHistory { private final String projectId; @Field("postCoordinationRevisions") - private final Set postCoordinationRevisions; + private final List postCoordinationRevisions; @JsonCreator public EntityPostCoordinationHistory(@JsonProperty("whoficEntityIri") String whoficEntityIri, @JsonProperty("projectId") String projectId, - @JsonProperty("postCoordinationRevisions") Set postCoordinationRevisions) { + @JsonProperty("postCoordinationRevisions") List postCoordinationRevisions) { this.whoficEntityIri = whoficEntityIri; this.projectId = projectId; this.postCoordinationRevisions = postCoordinationRevisions; @@ -44,7 +45,7 @@ public String getProjectId() { return projectId; } - public Set getPostCoordinationRevisions() { + public List getPostCoordinationRevisions() { return postCoordinationRevisions; } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationRevision.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationRevision.java index 2d053eb..0cf9aac 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationRevision.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationRevision.java @@ -1,11 +1,10 @@ package edu.stanford.protege.webprotege.postcoordinationservice.model; -import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; import java.util.Set; public record PostCoordinationRevision(String userId, Long timestamp, - Set postCoordinationEventList) { + Set postCoordinationEventList) { } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationViewEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationViewEvent.java new file mode 100644 index 0000000..f88acfb --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationViewEvent.java @@ -0,0 +1,13 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.model; + +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; +import org.springframework.data.mongodb.core.mapping.Field; + +import java.util.List; + +public record PostCoordinationViewEvent(@Field("linearizationView") + String linearizationView, + + @Field("axisEvents") + List axisEvents) { +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficEntityPostCoordinationSpecification.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficEntityPostCoordinationSpecification.java index 68f73aa..e791835 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficEntityPostCoordinationSpecification.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficEntityPostCoordinationSpecification.java @@ -2,36 +2,19 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; import java.util.List; -public class WhoficEntityPostCoordinationSpecification { - - private final String whoficEntityIri; - - private final String entityType; - private final List postcoordinationSpecifications; - +public record WhoficEntityPostCoordinationSpecification(String whoficEntityIri, String entityType, + List postCoordinationSpecifications) { @JsonCreator public WhoficEntityPostCoordinationSpecification(@JsonProperty("whoficEntityIri") String whoficEntityIri, @JsonProperty("entityType") String entityType, - @JsonProperty("postcoordinationSpecifications") List postcoordinationSpecifications) { + @JsonProperty("postCoordinationSpecifications") List postCoordinationSpecifications) { this.whoficEntityIri = whoficEntityIri; this.entityType = entityType; - this.postcoordinationSpecifications = postcoordinationSpecifications; - } - - public String getWhoficEntityIri() { - return whoficEntityIri; - } - - public List getPostCoordinationSpecifications() { - return postcoordinationSpecifications; - } - - public String getEntityType() { - return entityType; + this.postCoordinationSpecifications = postCoordinationSpecifications; } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java index 5f26a03..853abe2 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java @@ -38,6 +38,13 @@ public void bulkWriteDocuments(List> listOfInsertOneMod collection.bulkWrite(listOfInsertOneModelDocument); }); } + + public void writeDocument(Document document) { + readWriteLock.executeWriteLock(() -> { + var collection = mongoTemplate.getCollection(POSTCOORDINATION_HISTORY_COLLECTION); + collection.insertOne(document); + }); + } public Optional findHistoryByEntityIriAndProjectId(String entityIri, ProjectId projectId) { Query query = new Query(); diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java index 36586ef..a4d0be8 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java @@ -1,9 +1,42 @@ package edu.stanford.protege.webprotege.postcoordinationservice.services; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; +import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; +import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationRevision; +import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationViewEvent; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; import org.springframework.stereotype.Service; +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.HashSet; + @Service public class PostCoordinationEventProcessor { + public WhoficEntityPostCoordinationSpecification processHistory(@Nonnull EntityPostCoordinationHistory postCoordinationHistory) { + + var postCoordinationSpecification = new HashSet(); + for(PostCoordinationRevision revision: postCoordinationHistory.getPostCoordinationRevisions()) { + for(PostCoordinationViewEvent viewEvent: revision.postCoordinationEventList()) { + PostCoordinationSpecification specification = findSpecificationWithLinearizationView(viewEvent.linearizationView(), postCoordinationSpecification); + for(PostCoordinationEvent event : viewEvent.axisEvents()) { + event.applyEvent(specification); + } + postCoordinationSpecification.add(specification); + } + } + + return new WhoficEntityPostCoordinationSpecification(postCoordinationHistory.getWhoficEntityIri(), "ICD", postCoordinationSpecification.stream().toList()); + } + + private PostCoordinationSpecification findSpecificationWithLinearizationView(String linearizationView, HashSet postCoordinationSpecification) { + return postCoordinationSpecification.stream().filter(spec -> spec.getLinearizationView().equalsIgnoreCase(linearizationView)) + .findFirst() + .orElse(new PostCoordinationSpecification(linearizationView, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>())); + + } + } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java index c8f68c7..73fabba 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java @@ -6,18 +6,13 @@ import edu.stanford.protege.webprotege.common.UserId; import edu.stanford.protege.webprotege.postcoordinationservice.StreamUtils; import edu.stanford.protege.webprotege.postcoordinationservice.dto.LinearizationDefinition; -import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; import edu.stanford.protege.webprotege.postcoordinationservice.mappers.SpecificationToEventsMapper; -import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; -import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationRevision; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; -import edu.stanford.protege.webprotege.postcoordinationservice.model.TableConfiguration; -import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.model.*; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; import edu.stanford.protege.webprotege.postcoordinationservice.repositories.PostCoordinationDocumentRepository; import edu.stanford.protege.webprotege.postcoordinationservice.repositories.PostCoordinationSpecificationsRepository; import edu.stanford.protege.webprotege.postcoordinationservice.repositories.PostCoordinationTableConfigRepository; import org.bson.Document; -import org.semanticweb.owlapi.model.IRI; import org.springframework.stereotype.Service; import java.util.*; @@ -63,30 +58,33 @@ public void createFirstImport(String documentLocation, ProjectId projectId, User stream.collect(StreamUtils.batchCollector(500, createBatchProcessorForSavingPaginatedHistories(projectId, userId, definitionList, configurations))); }); } - Optional getExistingHistoryOrderedByRevision(IRI entityIri, ProjectId projectId) { - return specRepository.findHistoryByEntityIriAndProjectId(entityIri.toString(), projectId) + + public Optional getExistingHistoryOrderedByRevision(String entityIri, ProjectId projectId) { + return specRepository.findHistoryByEntityIriAndProjectId(entityIri, projectId) .map(history -> { - Set sortedRevisions = history.getPostCoordinationRevisions() + List sortedRevisions = history.getPostCoordinationRevisions() .stream() .sorted(Comparator.comparingLong(PostCoordinationRevision::timestamp)) - .collect(Collectors.toCollection(TreeSet::new)); + .collect(Collectors.toList()); // Return a new EntityLinearizationHistory object with the sorted revisions return new EntityPostCoordinationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions); }); } - private Consumer> createBatchProcessorForSavingPaginatedHistories(ProjectId projectId, UserId userId , List definitionList, List configurations) { + private Consumer> createBatchProcessorForSavingPaginatedHistories(ProjectId projectId, UserId userId, List definitionList, List configurations) { return page -> { if (isNotEmpty(page)) { Set histories = new HashSet<>(); - for(WhoficEntityPostCoordinationSpecification specification: page) { - Set events = specification.getPostCoordinationSpecifications().stream() - .map(spec -> enrichWithMissingAxis(specification.getEntityType(), spec, definitionList, configurations)) - .flatMap(spec -> SpecificationToEventsMapper.convertFromSpecification(spec).stream()) + for (WhoficEntityPostCoordinationSpecification specification : page) { + Set events = specification.postCoordinationSpecifications().stream() + .map(spec -> enrichWithMissingAxis(specification.entityType(), spec, definitionList, configurations)) + .map(spec -> + new PostCoordinationViewEvent(spec.getLinearizationView(), SpecificationToEventsMapper.convertFromSpecification(spec)) + ) .collect(Collectors.toSet()); PostCoordinationRevision revision = new PostCoordinationRevision(userId.id(), new Date().getTime(), events); - EntityPostCoordinationHistory history = new EntityPostCoordinationHistory(specification.getWhoficEntityIri(), projectId.id(), new HashSet<>(List.of(revision))); + EntityPostCoordinationHistory history = new EntityPostCoordinationHistory(specification.whoficEntityIri(), projectId.id(), List.of(revision)); histories.add(history); } @@ -104,7 +102,7 @@ private void saveMultipleEntityPostCoordinationHistories(Set definitionList, List configurations) { + PostCoordinationSpecification enrichWithMissingAxis(String entityType, PostCoordinationSpecification specification, List definitionList, List configurations) { LinearizationDefinition definition = definitionList.stream() .filter(linearizationDefinition -> linearizationDefinition.getWhoficEntityIri().equalsIgnoreCase(specification.getLinearizationView())) .findFirst() @@ -115,13 +113,13 @@ PostCoordinationSpecificationRequest enrichWithMissingAxis(String entityType, Po .findFirst() .orElseThrow(() -> new RuntimeException("Couldn't find the equivalent entity type " + entityType)); - for(String availableAxis : tableConfiguration.getPostCoordinationAxes()) { + for (String availableAxis : tableConfiguration.getPostCoordinationAxes()) { boolean isAlreadySet = specification.getRequiredAxes().contains(availableAxis) || - specification.getAllowedAxes().contains(availableAxis) || - specification.getNotAllowedAxes().contains(availableAxis) || - specification.getDefaultAxes().contains(availableAxis); - if(!isAlreadySet) { - if(definition.getCoreLinId() != null && !definition.getCoreLinId().isEmpty()) { + specification.getAllowedAxes().contains(availableAxis) || + specification.getNotAllowedAxes().contains(availableAxis) || + specification.getDefaultAxes().contains(availableAxis); + if (!isAlreadySet) { + if (definition.getCoreLinId() != null && !definition.getCoreLinId().isEmpty()) { specification.getDefaultAxes().add(availableAxis); } else { specification.getNotAllowedAxes().add(availableAxis); diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapperTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapperTest.java index 49d4abd..15939c6 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapperTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapperTest.java @@ -1,6 +1,6 @@ package edu.stanford.protege.webprotege.postcoordinationservice.mappers; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; import edu.stanford.protege.webprotege.postcoordinationservice.events.*; import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -17,7 +17,7 @@ public class SpecificationToEventsMapperTest { @Test public void GIVEN_PostCoordinationSpecificationRequest_WHEN_map_THEN_fieldsAreTurnedIntoEvents() { - PostCoordinationSpecificationRequest request = new PostCoordinationSpecificationRequest("view", + PostCoordinationSpecification request = new PostCoordinationSpecification("view", Collections.singletonList("allowedAxes"), Collections.singletonList("defaultAxes"), Collections.singletonList("notAllowedAxes"), diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepositoryTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepositoryTest.java index 1eed73a..98efde5 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepositoryTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepositoryTest.java @@ -59,12 +59,12 @@ public void GIVEN_existingFile_WHEN_fetchTheSpecifications_THEN_specificationsAr assertEquals(3, postCoordinationSpecifications.size()); WhoficEntityPostCoordinationSpecification specification = postCoordinationSpecifications.stream() - .filter(specification1 -> specification1.getWhoficEntityIri().equalsIgnoreCase("http://id.who.int/icd/entity/257068234")) + .filter(specification1 -> specification1.whoficEntityIri().equalsIgnoreCase("http://id.who.int/icd/entity/257068234")) .findFirst() .orElseThrow(() -> new RuntimeException("missing specification")); - assertEquals("ICD", specification.getEntityType()); - assertEquals(11, specification.getPostCoordinationSpecifications().size()); + assertEquals("ICD", specification.entityType()); + assertEquals(11, specification.postCoordinationSpecifications().size()); } } diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessorTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessorTest.java new file mode 100644 index 0000000..ba20544 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessorTest.java @@ -0,0 +1,86 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.services; + +import com.fasterxml.jackson.databind.ObjectMapper; +import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; +import edu.stanford.protege.webprotege.postcoordinationservice.IntegrationTest; +import edu.stanford.protege.webprotege.postcoordinationservice.WebprotegePostcoordinationServiceServiceApplication; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; +import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationRevision; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + +import java.io.*; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.eq; + +@SpringBootTest +@Import({WebprotegePostcoordinationServiceServiceApplication.class}) +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) +@ExtendWith({SpringExtension.class, IntegrationTest.class}) +@ActiveProfiles("test") +public class PostCoordinationEventProcessorTest { + + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private PostCoordinationEventProcessor postCoordinationEventProcessor; + + private EntityPostCoordinationHistory entityPostCoordinationHistory; + + @BeforeEach + public void setUp() throws IOException { + File initialFile = new File("src/test/resources/processedPostCoordinationHistory.json"); + InputStream targetStream = new FileInputStream(initialFile); + objectMapper = new WebProtegeJacksonApplication().objectMapper(new OWLDataFactoryImpl()); + entityPostCoordinationHistory = objectMapper.readValue(targetStream, EntityPostCoordinationHistory.class); + List sortedRevisions = entityPostCoordinationHistory.getPostCoordinationRevisions() + .stream() + .toList() + .stream() + .sorted(Comparator.comparingLong(PostCoordinationRevision::timestamp)) + .toList(); + + entityPostCoordinationHistory = new EntityPostCoordinationHistory(entityPostCoordinationHistory.getWhoficEntityIri(), entityPostCoordinationHistory.getProjectId(), sortedRevisions); + } + + @Test + public void GIVEN_savedDocument_WHEN_processingEvents_THEN_correctResponseIsGiven(){ + WhoficEntityPostCoordinationSpecification specification = postCoordinationEventProcessor.processHistory(entityPostCoordinationHistory); + + Optional envSpec = specification.postCoordinationSpecifications().stream() + .filter(spec -> spec.getLinearizationView().equalsIgnoreCase("http://id.who.int/icd/release/11/env")) + .findFirst(); + Optional mmsSpec = specification.postCoordinationSpecifications().stream() + .filter(spec -> spec.getLinearizationView().equalsIgnoreCase("http://id.who.int/icd/release/11/mms")) + .findFirst(); + + assertTrue(envSpec.isPresent()); + assertTrue(mmsSpec.isPresent()); + + assertEquals(31, envSpec.get().getDefaultAxes().size()); + assertEquals(0, envSpec.get().getAllowedAxes().size()); + assertEquals(0, envSpec.get().getNotAllowedAxes().size()); + assertEquals(0, envSpec.get().getRequiredAxes().size()); + + + assertEquals(0, mmsSpec.get().getDefaultAxes().size()); + assertEquals(2, mmsSpec.get().getAllowedAxes().size()); + assertEquals(29, mmsSpec.get().getNotAllowedAxes().size()); + assertEquals(0, mmsSpec.get().getRequiredAxes().size()); + } +} diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java index bfddfc5..4fbd7ce 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java @@ -7,8 +7,9 @@ import edu.stanford.protege.webprotege.postcoordinationservice.IntegrationTest; import edu.stanford.protege.webprotege.postcoordinationservice.WebprotegePostcoordinationServiceServiceApplication; import edu.stanford.protege.webprotege.postcoordinationservice.dto.LinearizationDefinition; -import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; +import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationViewEvent; import edu.stanford.protege.webprotege.postcoordinationservice.model.TableConfiguration; import edu.stanford.protege.webprotege.postcoordinationservice.repositories.MinioPostCoordinationDocumentLoader; import org.bson.Document; @@ -30,6 +31,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -86,7 +88,7 @@ public void GIVEN_mainLinearization_WHEN_enriching_THEN_missingAxisAreSetToNotAl List tableConfigs = objectMapper.readValue(tableConfig, new TypeReference<>() { }); - PostCoordinationSpecificationRequest specification = new PostCoordinationSpecificationRequest( + PostCoordinationSpecification specification = new PostCoordinationSpecification( "http://id.who.int/icd/release/11/mms", Arrays.asList("http://id.who.int/icd/schema/hasSeverity", "http://id.who.int/icd/schema/medication"), new ArrayList<>(), @@ -109,7 +111,7 @@ public void GIVEN_telescopicLinearization_WHEN_enriching_THEN_missingAxisAreSetT List tableConfigs = objectMapper.readValue(tableConfig, new TypeReference<>() { }); - PostCoordinationSpecificationRequest specification = new PostCoordinationSpecificationRequest( + PostCoordinationSpecification specification = new PostCoordinationSpecification( "http://id.who.int/icd/release/11/ocu", Arrays.asList("http://id.who.int/icd/schema/hasSeverity", "http://id.who.int/icd/schema/medication"), new ArrayList<>(), @@ -135,6 +137,10 @@ public void GIVEN_existingFile_WHEN_firstImport_THEN_allEventsAreGenerated() { assertEquals(1, history.getPostCoordinationRevisions().size()); assertEquals("alexsilaghi", history.getPostCoordinationRevisions().iterator().next().userId()); assertNotNull(history.getPostCoordinationRevisions().iterator().next().postCoordinationEventList()); + Set viewEventSet = history.getPostCoordinationRevisions().iterator().next().postCoordinationEventList(); + assertEquals(11, viewEventSet.size()); + assertEquals(31, viewEventSet.iterator().next().axisEvents().size()); + assertNotNull(viewEventSet.iterator().next().linearizationView()); } } \ No newline at end of file diff --git a/src/test/resources/processedPostCoordinationHistory.json b/src/test/resources/processedPostCoordinationHistory.json new file mode 100644 index 0000000..55f3261 --- /dev/null +++ b/src/test/resources/processedPostCoordinationHistory.json @@ -0,0 +1,354 @@ +{ + "whoficEntityIri": "http://id.who.int/icd/entity/2042704797", + "projectId": "b717d9a3-f265-46f5-bd15-9f1cf4b132c8", + "postCoordinationRevisions": [ + { + "userId": "alexsilaghi", + "timestamp": 1726558923593, + "postCoordinationEventList": [ + { + "linearizationView": "http://id.who.int/icd/release/11/env", + "axisEvents": [ + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasSeverity", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasAlternativeSeverity1", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasAlternativeSeverity2", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/course", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/temporalPatternAndOnset", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/timeInLife", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/causality", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/chemicalAgent", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/medication", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasCausingCondition", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/histopathology", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/laterality", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/relational", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/distribution", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/regional", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/specificAnatomy", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/serotype", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/genomicAndChomosomalAnomaly", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/fractureSubtype", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/fractureOpenOrClosed", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/jointInvolvementInFracture", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/typeOfInjury", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/extentOfBurnByBodySurface", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/extentOfFullThicknessBurnByBodySurface", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/outcomeOfFullThicknessBurn", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/durationOfComa", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/levelOfConsciousness", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/diagnosisConfirmedBy", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasManifestation", + "linearizationView": "http://id.who.int/icd/release/11/env" + }, + { + "@type": "AddToDefaultAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/associatedWith", + "linearizationView": "http://id.who.int/icd/release/11/env" + } + ] + }, + { + "linearizationView": "http://id.who.int/icd/release/11/mms", + "axisEvents": [ + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasSeverity", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasAlternativeSeverity1", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasAlternativeSeverity2", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/course", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/temporalPatternAndOnset", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/timeInLife", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/causality", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/chemicalAgent", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/medication", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasCausingCondition", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/histopathology", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/laterality", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/relational", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/distribution", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/regional", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/specificAnatomy", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/serotype", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/genomicAndChomosomalAnomaly", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/fractureSubtype", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/fractureOpenOrClosed", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/jointInvolvementInFracture", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/typeOfInjury", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/extentOfBurnByBodySurface", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/extentOfFullThicknessBurnByBodySurface", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/outcomeOfFullThicknessBurn", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/durationOfComa", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/levelOfConsciousness", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/diagnosisConfirmedBy", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasManifestation", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + { + "@type": "AddToNotAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/associatedWith", + "linearizationView": "http://id.who.int/icd/release/11/mms" + } + ] + } + ] + }, + { + "userId": "alexsilaghi", + "timestamp": 1726958923593, + "postCoordinationEventList": [ + { + "linearizationView": "http://id.who.int/icd/release/11/mms", + "axisEvents": [ + { + "@type": "AddToAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasSeverity", + "linearizationView": "http://id.who.int/icd/release/11/mms" + }, + + { + "@type": "AddToAllowedAxis", + "postCoordinationAxis": "http://id.who.int/icd/schema/hasAlternativeSeverity1", + "linearizationView": "http://id.who.int/icd/release/11/mms" + } + ] + } + ] + } + ] +} \ No newline at end of file From 85df3cdad18f686fe77ad5e859cf5cbbdc19a9ed Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Thu, 19 Sep 2024 09:22:28 +0300 Subject: [PATCH 3/6] partial commit --- .../PostCoordinationCustomScalesRequest.java | 29 +++++++++++++++++++ .../UploadPostCoordinationCommandHandler.java | 2 +- .../model/WhoficCustomScalesValues.java | 21 ++++++++++++++ .../PostCoordinationDocumentRepository.java | 27 ++++++++++------- .../services/PostCoordinationService.java | 4 +-- ...ostCoordinationDocumentRepositoryTest.java | 2 +- .../services/PostCoordinationServiceTest.java | 2 +- 7 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationCustomScalesRequest.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficCustomScalesValues.java diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationCustomScalesRequest.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationCustomScalesRequest.java new file mode 100644 index 0000000..c6472e3 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/PostCoordinationCustomScalesRequest.java @@ -0,0 +1,29 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.dto; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import edu.stanford.protege.webprotege.postcoordinationservice.events.EventProcessableParameter; + +import java.util.List; + +public class PostCoordinationCustomScalesRequest extends EventProcessableParameter { + + private final List postCoordinationScalesValues; + private final String postCoordinationAxis; + + + @JsonCreator + public PostCoordinationCustomScalesRequest(@JsonProperty("postcoordinationScaleValues") List postCoordinationScalesValues, + @JsonProperty("postcoordinationAxis") String postCoordinationAxis) { + this.postCoordinationScalesValues = postCoordinationScalesValues; + this.postCoordinationAxis = postCoordinationAxis; + } + + public List getPostCoordinationScalesValues() { + return postCoordinationScalesValues; + } + + public String getPostCoordinationAxis() { + return postCoordinationAxis; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadPostCoordinationCommandHandler.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadPostCoordinationCommandHandler.java index 3d51461..b1adb00 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadPostCoordinationCommandHandler.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadPostCoordinationCommandHandler.java @@ -35,7 +35,7 @@ public Class getRequestClass() { @Override public Mono handleRequest(UploadPostCoordinationRequest request, ExecutionContext executionContext) { try { - postCoordinationService.createFirstImport(request.getDocumentId().id(), request.getProjectId(), executionContext.userId()); + postCoordinationService.createFirstSpecificationImport(request.getDocumentId().id(), request.getProjectId(), executionContext.userId()); return Mono.just(new UploadPostCoordinationResponse()); } catch (Exception e) { LOGGER.error("Error uploading postcoordinations", e); diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficCustomScalesValues.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficCustomScalesValues.java new file mode 100644 index 0000000..2d7f543 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficCustomScalesValues.java @@ -0,0 +1,21 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationCustomScalesRequest; + +import java.util.List; + +public class WhoficCustomScalesValues { + + private final String whoficEntityIri; + + private final List scaleCustomizations; + + @JsonCreator + public WhoficCustomScalesValues(@JsonProperty("whoficEntityIri") String whoficEntityIri, + @JsonProperty("scaleCustomizations") List scaleCustomizations) { + this.whoficEntityIri = whoficEntityIri; + this.scaleCustomizations = scaleCustomizations; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepository.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepository.java index 637da7b..f661086 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepository.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepository.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; import org.springframework.stereotype.Service; @@ -29,8 +30,15 @@ public PostCoordinationDocumentRepository(MinioPostCoordinationDocumentLoader do this.objectMapper = objectMapper; } - public Stream fetchFromDocument(String location) { + public Stream fetchPostCoordinationSpecifications(String location) { + return fetchDataStream(location, "whoficEntityPostcoordinationSpecification", WhoficEntityPostCoordinationSpecification.class); + } + + public Stream fetchCustomScalesValues(String location) { + return fetchDataStream(location, "postcoordinationScaleCustomization", WhoficCustomScalesValues.class); + } + private Stream fetchDataStream(String location, String expectedArrayName, Class targetType) { try { JsonFactory jsonFactory = new JsonFactory(); JsonParser jsonParser = jsonFactory.createParser(documentLoader.fetchPostCoordinationDocument(location)); @@ -41,25 +49,23 @@ public Stream fetchFromDocument(Strin jsonParser.nextToken(); - if (!jsonParser.getCurrentName().equals("whoficEntityPostcoordinationSpecification") && jsonParser.nextToken() != JsonToken.START_ARRAY) { - throw new IllegalStateException("Expected the array of postCoordination specifications"); + if (!jsonParser.getCurrentName().equals(expectedArrayName) && jsonParser.nextToken() != JsonToken.START_ARRAY) { + throw new IllegalStateException("Expected the array of " + expectedArrayName); } jsonParser.nextToken(); return StreamSupport.stream( - new Spliterators.AbstractSpliterator<>(Long.MAX_VALUE, Spliterator.ORDERED) { + new Spliterators.AbstractSpliterator(Long.MAX_VALUE, Spliterator.ORDERED) { @Override - public boolean tryAdvance(Consumer action) { + public boolean tryAdvance(Consumer action) { try { - if (jsonParser.nextToken() == JsonToken.END_ARRAY) { return false; } - JsonNode node = objectMapper.readTree(jsonParser); - WhoficEntityPostCoordinationSpecification person = objectMapper.treeToValue(node, WhoficEntityPostCoordinationSpecification.class); - action.accept(person); + T element = objectMapper.treeToValue(node, targetType); + action.accept(element); return true; } catch (IOException e) { throw new UncheckedIOException(e); @@ -67,10 +73,9 @@ public boolean tryAdvance(Consumer definitionList = linearizationService.getLinearizationDefinitions(); List configurations = configRepository.getALlTableConfiguration(); readWriteLock.executeWriteLock(() -> { diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepositoryTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepositoryTest.java index 98efde5..a366e41 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepositoryTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationDocumentRepositoryTest.java @@ -53,7 +53,7 @@ public void setUp() throws FileNotFoundException { @Test public void GIVEN_existingFile_WHEN_fetchTheSpecifications_THEN_specificationsAreCorrectlyMapped(){ - List postCoordinationSpecifications = documentRepository.fetchFromDocument("dummy").toList(); + List postCoordinationSpecifications = documentRepository.fetchPostCoordinationSpecifications("dummy").toList(); assertNotNull(postCoordinationSpecifications); assertEquals(3, postCoordinationSpecifications.size()); diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java index 4fbd7ce..4f337ba 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java @@ -126,7 +126,7 @@ public void GIVEN_telescopicLinearization_WHEN_enriching_THEN_missingAxisAreSetT @Test public void GIVEN_existingFile_WHEN_firstImport_THEN_allEventsAreGenerated() { - postCoordinationService.createFirstImport("postCoordinationImportFile.json", ProjectId.generate(), new UserId("alexsilaghi")); + postCoordinationService.createFirstSpecificationImport("postCoordinationImportFile.json", ProjectId.generate(), new UserId("alexsilaghi")); List histories = mongoTemplate.findAll(EntityPostCoordinationHistory.class); assertNotNull(histories); assertEquals(3, histories.size()); From c0be659eb1de0a28caa759453ff1b54ce1abe2b7 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Thu, 19 Sep 2024 16:32:09 +0300 Subject: [PATCH 4/6] added process for custom scale customization --- .../config/ApplicationBeans.java | 4 +- ...rdinationCustomScalesReadingConverter.java | 23 ++ ...rdinationCustomScalesWritingConverter.java | 24 ++ ...PostcoordinationEventReadingConverter.java | 8 +- ...PostcoordinationEventWritingConverter.java | 6 +- .../events/AddCustomScaleValueEvent.java | 24 ++ .../events/AddToAllowedAxisEvent.java | 2 +- .../events/AddToDefaultAxisEvent.java | 2 +- .../events/AddToNotAllowedAxisEvent.java | 2 +- .../events/AddToRequiredAxisEvent.java | 2 +- ...ostCoordinationCustomScalesValueEvent.java | 48 +++ ...> PostCoordinationSpecificationEvent.java} | 4 +- .../events/RemoveCustomScaleValueEvent.java | 25 ++ .../UploadFirstCustomScalesValuesHandler.java | 38 +++ .../UploadFirstCustomScalesValuesRequest.java | 23 ++ ...UploadFirstCustomScalesValuesResponse.java | 11 + .../UploadPostCoordinationRequest.java | 3 +- .../mappers/SpecificationToEventsMapper.java | 20 +- .../EntityCustomScalesValuesHistory.java | 51 +++ .../model/EntityPostCoordinationHistory.java | 1 - .../PostCoordinationCustomScalesRevision.java | 10 + .../model/PostCoordinationViewEvent.java | 4 +- .../model/WhoficCustomScalesValues.java | 9 +- ...tCoordinationSpecificationsRepository.java | 5 +- .../PostCoordinationEventProcessor.java | 4 +- .../services/PostCoordinationService.java | 35 +- .../SpecificationToEventsMapperTest.java | 2 +- ...ostCoordinationCustomValueServiceTest.java | 78 +++++ ...CoordinationSpecificationServiceTest.java} | 2 +- .../resources/postCoordinationImportFile.json | 6 +- .../postCoordinationScalesImportFile.json | 317 ++++++++++++++++++ 31 files changed, 758 insertions(+), 35 deletions(-) create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostCoordinationCustomScalesReadingConverter.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostCoordinationCustomScalesWritingConverter.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddCustomScaleValueEvent.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationCustomScalesValueEvent.java rename src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/{PostCoordinationEvent.java => PostCoordinationSpecificationEvent.java} (92%) create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/RemoveCustomScaleValueEvent.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesHandler.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesRequest.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesResponse.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityCustomScalesValuesHistory.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationCustomScalesRevision.java create mode 100644 src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationCustomValueServiceTest.java rename src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/{PostCoordinationServiceTest.java => PostCoordinationSpecificationServiceTest.java} (99%) create mode 100644 src/test/resources/postCoordinationScalesImportFile.json diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/ApplicationBeans.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/ApplicationBeans.java index 58d9d28..d57036e 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/ApplicationBeans.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/ApplicationBeans.java @@ -41,7 +41,9 @@ public MongoCustomConversions customConversions(ObjectMapper objectMapper) { return new MongoCustomConversions( List.of( new PostcoordinationEventReadingConverter(objectMapper), - new PostcoordinationEventWritingConverter(objectMapper) + new PostcoordinationEventWritingConverter(objectMapper), + new PostCoordinationCustomScalesReadingConverter(objectMapper), + new PostCoordinationCustomScalesWritingConverter(objectMapper) ) ); } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostCoordinationCustomScalesReadingConverter.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostCoordinationCustomScalesReadingConverter.java new file mode 100644 index 0000000..952840a --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostCoordinationCustomScalesReadingConverter.java @@ -0,0 +1,23 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationCustomScalesValueEvent; +import org.bson.Document; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; + +@ReadingConverter +public class PostCoordinationCustomScalesReadingConverter implements Converter { + + + private final ObjectMapper objectMapper; + + public PostCoordinationCustomScalesReadingConverter(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public PostCoordinationCustomScalesValueEvent convert(Document source) { + return objectMapper.convertValue(source, PostCoordinationCustomScalesValueEvent.class); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostCoordinationCustomScalesWritingConverter.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostCoordinationCustomScalesWritingConverter.java new file mode 100644 index 0000000..85c114b --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostCoordinationCustomScalesWritingConverter.java @@ -0,0 +1,24 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationCustomScalesValueEvent; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent; +import org.bson.Document; +import org.jetbrains.annotations.NotNull; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.WritingConverter; + +@WritingConverter +public class PostCoordinationCustomScalesWritingConverter implements Converter { + private final ObjectMapper objectMapper; + + public PostCoordinationCustomScalesWritingConverter(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + + @Override + public Document convert(@NotNull PostCoordinationCustomScalesValueEvent source) { + return objectMapper.convertValue(source, Document.class); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostcoordinationEventReadingConverter.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostcoordinationEventReadingConverter.java index e6746c6..5bf209d 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostcoordinationEventReadingConverter.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostcoordinationEventReadingConverter.java @@ -1,13 +1,13 @@ package edu.stanford.protege.webprotege.postcoordinationservice.config; import com.fasterxml.jackson.databind.ObjectMapper; -import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent; import org.bson.Document; import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; @ReadingConverter -public class PostcoordinationEventReadingConverter implements Converter { +public class PostcoordinationEventReadingConverter implements Converter { private final ObjectMapper objectMapper; @@ -17,7 +17,7 @@ public PostcoordinationEventReadingConverter(ObjectMapper objectMapper) { } @Override - public PostCoordinationEvent convert(Document source) { - return objectMapper.convertValue(source, PostCoordinationEvent.class); + public PostCoordinationSpecificationEvent convert(Document source) { + return objectMapper.convertValue(source, PostCoordinationSpecificationEvent.class); } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostcoordinationEventWritingConverter.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostcoordinationEventWritingConverter.java index d2ae799..632db83 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostcoordinationEventWritingConverter.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/config/PostcoordinationEventWritingConverter.java @@ -1,14 +1,14 @@ package edu.stanford.protege.webprotege.postcoordinationservice.config; import com.fasterxml.jackson.databind.ObjectMapper; -import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent; import org.bson.Document; import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.WritingConverter; @WritingConverter -public class PostcoordinationEventWritingConverter implements Converter { +public class PostcoordinationEventWritingConverter implements Converter { private final ObjectMapper objectMapper; public PostcoordinationEventWritingConverter(ObjectMapper objectMapper) { @@ -17,7 +17,7 @@ public PostcoordinationEventWritingConverter(ObjectMapper objectMapper) { @Override - public Document convert(PostCoordinationEvent source) { + public Document convert(PostCoordinationSpecificationEvent source) { return objectMapper.convertValue(source, Document.class); } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddCustomScaleValueEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddCustomScaleValueEvent.java new file mode 100644 index 0000000..1dee6af --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddCustomScaleValueEvent.java @@ -0,0 +1,24 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.events; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; + +public class AddCustomScaleValueEvent extends PostCoordinationCustomScalesValueEvent { + public final static String TYPE = "AddCustomScaleValue"; + + @JsonCreator + public AddCustomScaleValueEvent(@JsonProperty("postCoordinationAxis") String postCoordinationAxis,@JsonProperty("postCoordinationScaleValue") String postCoordinationScaleValue) { + super(postCoordinationAxis, postCoordinationScaleValue); + } + + @Override + String getType() { + return TYPE; + } + + @Override + public void applyEvent(WhoficCustomScalesValues whoficCustomScalesValues) { + + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToAllowedAxisEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToAllowedAxisEvent.java index f7942c0..8d28a9d 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToAllowedAxisEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToAllowedAxisEvent.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; -public class AddToAllowedAxisEvent extends PostCoordinationEvent { +public class AddToAllowedAxisEvent extends PostCoordinationSpecificationEvent { public final static String TYPE = "AddToAllowedAxis"; diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToDefaultAxisEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToDefaultAxisEvent.java index d69d783..96ad55f 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToDefaultAxisEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToDefaultAxisEvent.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; -public class AddToDefaultAxisEvent extends PostCoordinationEvent { +public class AddToDefaultAxisEvent extends PostCoordinationSpecificationEvent { public final static String TYPE = "AddToDefaultAxis"; diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToNotAllowedAxisEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToNotAllowedAxisEvent.java index c1471bd..51f321b 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToNotAllowedAxisEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToNotAllowedAxisEvent.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; -public class AddToNotAllowedAxisEvent extends PostCoordinationEvent { +public class AddToNotAllowedAxisEvent extends PostCoordinationSpecificationEvent { public final static String TYPE = "AddToNotAllowedAxis"; diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToRequiredAxisEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToRequiredAxisEvent.java index 2251351..7c821b5 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToRequiredAxisEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddToRequiredAxisEvent.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; -public class AddToRequiredAxisEvent extends PostCoordinationEvent { +public class AddToRequiredAxisEvent extends PostCoordinationSpecificationEvent { public final static String TYPE = "AddToRequiredAxis"; diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationCustomScalesValueEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationCustomScalesValueEvent.java new file mode 100644 index 0000000..c2f0133 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationCustomScalesValueEvent.java @@ -0,0 +1,48 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.events; + + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; +import org.bson.codecs.pojo.annotations.BsonDiscriminator; +import org.springframework.data.mongodb.core.mapping.Field; + +@BsonDiscriminator(key = "type") +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME +) +@JsonSubTypes(value = { + @JsonSubTypes.Type(value = AddCustomScaleValueEvent.class, name = AddCustomScaleValueEvent.TYPE), + @JsonSubTypes.Type(value = RemoveCustomScaleValueEvent.class, name = RemoveCustomScaleValueEvent.TYPE), +}) +public abstract class PostCoordinationCustomScalesValueEvent { + + @Field("postCoordinationAxis") + private final String postCoordinationAxis; + + @Field("postCoordinationScaleValue") + private final String postCoordinationScaleValue; + + protected PostCoordinationCustomScalesValueEvent(String postCoordinationAxis, String postCoordinationScaleValue) { + this.postCoordinationAxis = postCoordinationAxis; + this.postCoordinationScaleValue = postCoordinationScaleValue; + } + + @JsonProperty("@type") + abstract String getType(); + + public abstract void applyEvent(WhoficCustomScalesValues whoficCustomScalesValues); + + @Field("postCoordinationAxis") + @JsonProperty("postCoordinationAxis") + public String getPostCoordinationAxis() { + return postCoordinationAxis; + }; + + @Field("postCoordinationScaleValue") + @JsonProperty("postCoordinationScaleValue") + public String getPostCoordinationScaleValue() { + return postCoordinationScaleValue; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationSpecificationEvent.java similarity index 92% rename from src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java rename to src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationSpecificationEvent.java index a082be2..8f25693 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/PostCoordinationSpecificationEvent.java @@ -18,7 +18,7 @@ @JsonSubTypes.Type(value = AddToNotAllowedAxisEvent.class, name = AddToNotAllowedAxisEvent.TYPE), @JsonSubTypes.Type(value = AddToAllowedAxisEvent.class, name = AddToAllowedAxisEvent.TYPE) }) -public abstract class PostCoordinationEvent { +public abstract class PostCoordinationSpecificationEvent { @Field("postCoordinationAxis") private final String postCoordinationAxis; @@ -26,7 +26,7 @@ public abstract class PostCoordinationEvent { @Field("linearizationView") private final String linearizationView; - protected PostCoordinationEvent(String postCoordinationAxis, String linearizationView) { + protected PostCoordinationSpecificationEvent(String postCoordinationAxis, String linearizationView) { this.postCoordinationAxis = postCoordinationAxis; this.linearizationView = linearizationView; } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/RemoveCustomScaleValueEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/RemoveCustomScaleValueEvent.java new file mode 100644 index 0000000..0cb56fe --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/RemoveCustomScaleValueEvent.java @@ -0,0 +1,25 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.events; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; + +public class RemoveCustomScaleValueEvent extends PostCoordinationCustomScalesValueEvent { + + public final static String TYPE = "RemoveCustomScaleValue"; + + @JsonCreator + public RemoveCustomScaleValueEvent(@JsonProperty("postCoordinationAxis") String postCoordinationAxis, @JsonProperty("postCoordinationScaleValue") String postCoordinationScaleValue) { + super(postCoordinationAxis, postCoordinationScaleValue); + } + + @Override + String getType() { + return TYPE; + } + + @Override + public void applyEvent(WhoficCustomScalesValues whoficCustomScalesValues) { + + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesHandler.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesHandler.java new file mode 100644 index 0000000..78aeb40 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesHandler.java @@ -0,0 +1,38 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.handlers; + +import edu.stanford.protege.webprotege.ipc.CommandHandler; +import edu.stanford.protege.webprotege.ipc.ExecutionContext; +import edu.stanford.protege.webprotege.ipc.WebProtegeHandler; +import edu.stanford.protege.webprotege.postcoordinationservice.services.PostCoordinationService; +import org.jetbrains.annotations.NotNull; +import reactor.core.publisher.Mono; + +import static edu.stanford.protege.webprotege.postcoordinationservice.handlers.UploadFirstCustomScalesValuesRequest.CHANNEL; + +@WebProtegeHandler +public class UploadFirstCustomScalesValuesHandler implements CommandHandler { + + + private final PostCoordinationService postCoordinationService; + + public UploadFirstCustomScalesValuesHandler(PostCoordinationService postCoordinationService) { + this.postCoordinationService = postCoordinationService; + } + + @NotNull + @Override + public String getChannelName() { + return CHANNEL; + } + + @Override + public Class getRequestClass() { + return UploadFirstCustomScalesValuesRequest.class; + } + + @Override + public Mono handleRequest(UploadFirstCustomScalesValuesRequest request, ExecutionContext executionContext) { + postCoordinationService.crateFirstCustomScalesValuesImport(request.documentId().id(), request.projectId(), executionContext.userId()); + return Mono.just(new UploadFirstCustomScalesValuesResponse()); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesRequest.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesRequest.java new file mode 100644 index 0000000..a900664 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesRequest.java @@ -0,0 +1,23 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.handlers; + + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import edu.stanford.protege.webprotege.change.OntologyDocumentId; +import edu.stanford.protege.webprotege.common.ProjectId; +import edu.stanford.protege.webprotege.common.Request; + +import static edu.stanford.protege.webprotege.postcoordinationservice.handlers.UploadFirstCustomScalesValuesRequest.CHANNEL; + +@JsonTypeName(CHANNEL) +public record UploadFirstCustomScalesValuesRequest(@JsonProperty("documentId") OntologyDocumentId documentId, + @JsonProperty("projectId") ProjectId projectId) implements Request { + + public static final String CHANNEL = "webprotege.postcoordination.ProcessFirstPostCoordinationScaleValues"; + + + @Override + public String getChannel() { + return null; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesResponse.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesResponse.java new file mode 100644 index 0000000..cfb3382 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadFirstCustomScalesValuesResponse.java @@ -0,0 +1,11 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.handlers; + + +import com.fasterxml.jackson.annotation.JsonTypeName; +import edu.stanford.protege.webprotege.common.Response; + +import static edu.stanford.protege.webprotege.postcoordinationservice.handlers.UploadFirstCustomScalesValuesRequest.CHANNEL; + +@JsonTypeName(CHANNEL) +public record UploadFirstCustomScalesValuesResponse() implements Response { +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadPostCoordinationRequest.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadPostCoordinationRequest.java index 8634766..6aa9d85 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadPostCoordinationRequest.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/UploadPostCoordinationRequest.java @@ -6,7 +6,8 @@ import edu.stanford.protege.webprotege.common.ProjectId; import edu.stanford.protege.webprotege.common.Request; -public record UploadPostCoordinationRequest( @JsonProperty("documentId") OntologyDocumentId documentId,@JsonProperty("projectId") ProjectId projectId) implements Request { +public record UploadPostCoordinationRequest( @JsonProperty("documentId") OntologyDocumentId documentId, + @JsonProperty("projectId") ProjectId projectId) implements Request { public static final String CHANNEL = "webprotege.postcoordination.ProcessUploadedPostCoordination"; @JsonCreator diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapper.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapper.java index f84e178..76b026e 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapper.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapper.java @@ -1,17 +1,21 @@ package edu.stanford.protege.webprotege.postcoordinationservice.mappers; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationCustomScalesRequest; import edu.stanford.protege.webprotege.postcoordinationservice.events.*; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class SpecificationToEventsMapper { - public static List convertFromSpecification(PostCoordinationSpecification specification) { - List response = new ArrayList<>(); + public static List convertFromSpecification(PostCoordinationSpecification specification) { + List response = new ArrayList<>(); response.addAll(specification.getAllowedAxes().stream().map(axis -> new AddToAllowedAxisEvent(axis, specification.getLinearizationView())).toList()); response.addAll(specification.getDefaultAxes().stream().map(axis -> new AddToDefaultAxisEvent(axis, specification.getLinearizationView())).toList()); @@ -21,4 +25,16 @@ public static List convertFromSpecification(PostCoordinat return response; } + public static Set convertToFirstImportEvents(WhoficCustomScalesValues whoficCustomScalesValues) { + Set response = new HashSet<>(); + + for(PostCoordinationCustomScalesRequest request : whoficCustomScalesValues.scaleCustomizations()) { + response.addAll(request.getPostCoordinationScalesValues() + .stream() + .map(scaleValue -> new AddCustomScaleValueEvent(request.getPostCoordinationAxis(), scaleValue)).toList()); + } + + return response; + } + } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityCustomScalesValuesHistory.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityCustomScalesValuesHistory.java new file mode 100644 index 0000000..f630da0 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityCustomScalesValuesHistory.java @@ -0,0 +1,51 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.model; + + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.Field; + +import java.util.List; + +import static edu.stanford.protege.webprotege.postcoordinationservice.model.EntityCustomScalesValuesHistory.POSTCOORDINATION_CUSTOM_SCALES_COLLECTION; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Document(collection = POSTCOORDINATION_CUSTOM_SCALES_COLLECTION) +public class EntityCustomScalesValuesHistory { + + public static final String POSTCOORDINATION_CUSTOM_SCALES_COLLECTION = "EntityPostCoordinationCustomScales"; + @Field("whoficEntityIri") + private final String whoficEntityIri; + + @Field("projectId") + private final String projectId; + + @Field("postCoordinationCustomScalesRevisions") + private final List postCoordinationCustomScalesRevisions; + + @JsonCreator + public EntityCustomScalesValuesHistory(@JsonProperty("whoficEntityIri") String whoficEntityIri, + @JsonProperty("projectId") String projectId, + @JsonProperty("postCoordinationCustomScalesRevisions") List postCoordinationCustomScalesRevisions) { + this.whoficEntityIri = whoficEntityIri; + this.projectId = projectId; + this.postCoordinationCustomScalesRevisions = postCoordinationCustomScalesRevisions; + } + + @JsonProperty("whoficEntityIri") + public String getWhoficEntityIri() { + return whoficEntityIri; + } + + @JsonProperty("projectId") + public String getProjectId() { + return projectId; + } + + @JsonProperty("postCoordinationCustomScalesRevisions") + public List getPostCoordinationCustomScalesRevisions() { + return postCoordinationCustomScalesRevisions; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityPostCoordinationHistory.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityPostCoordinationHistory.java index 9537a4f..b301de4 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityPostCoordinationHistory.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/EntityPostCoordinationHistory.java @@ -17,7 +17,6 @@ public class EntityPostCoordinationHistory { public static final String POSTCOORDINATION_HISTORY_COLLECTION = "EntityPostCoordinationHistory"; - @Field("whoficEntityIri") private final String whoficEntityIri; diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationCustomScalesRevision.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationCustomScalesRevision.java new file mode 100644 index 0000000..10255fc --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationCustomScalesRevision.java @@ -0,0 +1,10 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.model; + +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationCustomScalesValueEvent; + +import java.util.Set; + +public record PostCoordinationCustomScalesRevision(String userId, + Long timestamp, + Set postCoordinationEventList) { +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationViewEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationViewEvent.java index f88acfb..fcadf49 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationViewEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/PostCoordinationViewEvent.java @@ -1,6 +1,6 @@ package edu.stanford.protege.webprotege.postcoordinationservice.model; -import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent; import org.springframework.data.mongodb.core.mapping.Field; import java.util.List; @@ -9,5 +9,5 @@ public record PostCoordinationViewEvent(@Field("linearizationView") String linearizationView, @Field("axisEvents") - List axisEvents) { + List axisEvents) { } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficCustomScalesValues.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficCustomScalesValues.java index 2d7f543..fcce57a 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficCustomScalesValues.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/model/WhoficCustomScalesValues.java @@ -6,11 +6,8 @@ import java.util.List; -public class WhoficCustomScalesValues { - - private final String whoficEntityIri; - - private final List scaleCustomizations; +public record WhoficCustomScalesValues(String whoficEntityIri, + List scaleCustomizations) { @JsonCreator public WhoficCustomScalesValues(@JsonProperty("whoficEntityIri") String whoficEntityIri, @@ -18,4 +15,6 @@ public WhoficCustomScalesValues(@JsonProperty("whoficEntityIri") String whoficEn this.whoficEntityIri = whoficEntityIri; this.scaleCustomizations = scaleCustomizations; } + + } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java index 853abe2..e26cb01 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java @@ -32,13 +32,14 @@ public PostCoordinationSpecificationsRepository(MongoTemplate mongoTemplate, Rea this.readWriteLock = readWriteLock; } - public void bulkWriteDocuments(List> listOfInsertOneModelDocument) { + public void bulkWriteDocuments(List> listOfInsertOneModelDocument, String collectionName) { readWriteLock.executeWriteLock(() -> { - var collection = mongoTemplate.getCollection(POSTCOORDINATION_HISTORY_COLLECTION); + var collection = mongoTemplate.getCollection(collectionName); collection.bulkWrite(listOfInsertOneModelDocument); }); } + public void writeDocument(Document document) { readWriteLock.executeWriteLock(() -> { var collection = mongoTemplate.getCollection(POSTCOORDINATION_HISTORY_COLLECTION); diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java index a4d0be8..68cb708 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java @@ -1,7 +1,7 @@ package edu.stanford.protege.webprotege.postcoordinationservice.services; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; -import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent; import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationRevision; import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationViewEvent; @@ -21,7 +21,7 @@ public WhoficEntityPostCoordinationSpecification processHistory(@Nonnull EntityP for(PostCoordinationRevision revision: postCoordinationHistory.getPostCoordinationRevisions()) { for(PostCoordinationViewEvent viewEvent: revision.postCoordinationEventList()) { PostCoordinationSpecification specification = findSpecificationWithLinearizationView(viewEvent.linearizationView(), postCoordinationSpecification); - for(PostCoordinationEvent event : viewEvent.axisEvents()) { + for(PostCoordinationSpecificationEvent event : viewEvent.axisEvents()) { event.applyEvent(specification); } postCoordinationSpecification.add(specification); diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java index 2b59322..5471e4c 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java @@ -6,6 +6,7 @@ import edu.stanford.protege.webprotege.common.UserId; import edu.stanford.protege.webprotege.postcoordinationservice.StreamUtils; import edu.stanford.protege.webprotege.postcoordinationservice.dto.LinearizationDefinition; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationCustomScalesValueEvent; import edu.stanford.protege.webprotege.postcoordinationservice.mappers.SpecificationToEventsMapper; import edu.stanford.protege.webprotege.postcoordinationservice.model.*; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; @@ -19,6 +20,8 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import static edu.stanford.protege.webprotege.postcoordinationservice.model.EntityCustomScalesValuesHistory.POSTCOORDINATION_CUSTOM_SCALES_COLLECTION; +import static edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory.POSTCOORDINATION_HISTORY_COLLECTION; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; @Service @@ -59,6 +62,14 @@ public void createFirstSpecificationImport(String documentLocation, ProjectId pr }); } + + public void crateFirstCustomScalesValuesImport(String documentLocation, ProjectId projectId, UserId userId) { + var stream = documentRepository.fetchCustomScalesValues(documentLocation); + readWriteLock.executeWriteLock(() -> { + stream.collect(StreamUtils.batchCollector(500, createBatchProcessorForSavingPaginatedCustomScales(projectId, userId))); + }); + } + public Optional getExistingHistoryOrderedByRevision(String entityIri, ProjectId projectId) { return specRepository.findHistoryByEntityIriAndProjectId(entityIri, projectId) .map(history -> { @@ -72,6 +83,28 @@ public Optional getExistingHistoryOrderedByRevisi } + private Consumer> createBatchProcessorForSavingPaginatedCustomScales(ProjectId projectId, + UserId userId) { + return page -> { + if (isNotEmpty(page)) { + Set histories = new HashSet<>(); + for (WhoficCustomScalesValues specification : page) { + Set events = SpecificationToEventsMapper.convertToFirstImportEvents(specification); + PostCoordinationCustomScalesRevision revision = new PostCoordinationCustomScalesRevision(userId.id(), new Date().getTime(), events); + EntityCustomScalesValuesHistory history = new EntityCustomScalesValuesHistory(specification.whoficEntityIri(), projectId.id(), List.of(revision)); + histories.add(history); + } + var documents = histories.stream() + .map(history -> new InsertOneModel<>(objectMapper.convertValue(history, Document.class))) + .toList(); + + specRepository.bulkWriteDocuments(documents, POSTCOORDINATION_CUSTOM_SCALES_COLLECTION); + + } + }; + } + + private Consumer> createBatchProcessorForSavingPaginatedHistories(ProjectId projectId, UserId userId, List definitionList, List configurations) { return page -> { if (isNotEmpty(page)) { @@ -98,7 +131,7 @@ private void saveMultipleEntityPostCoordinationHistories(Set new InsertOneModel<>(objectMapper.convertValue(history, Document.class))) .toList(); - specRepository.bulkWriteDocuments(documents); + specRepository.bulkWriteDocuments(documents, POSTCOORDINATION_HISTORY_COLLECTION); } diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapperTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapperTest.java index 15939c6..57aafeb 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapperTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/mappers/SpecificationToEventsMapperTest.java @@ -24,7 +24,7 @@ public void GIVEN_PostCoordinationSpecificationRequest_WHEN_map_THEN_fieldsAreTu Collections.singletonList("requiredAxes") ); - List eventList = SpecificationToEventsMapper.convertFromSpecification(request); + List eventList = SpecificationToEventsMapper.convertFromSpecification(request); assertNotNull(eventList); assertEquals(4, eventList.size()); diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationCustomValueServiceTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationCustomValueServiceTest.java new file mode 100644 index 0000000..61fcc59 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationCustomValueServiceTest.java @@ -0,0 +1,78 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.services; + + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import edu.stanford.protege.webprotege.common.ProjectId; +import edu.stanford.protege.webprotege.common.UserId; +import edu.stanford.protege.webprotege.postcoordinationservice.IntegrationTest; +import edu.stanford.protege.webprotege.postcoordinationservice.WebprotegePostcoordinationServiceServiceApplication; +import edu.stanford.protege.webprotege.postcoordinationservice.model.*; +import edu.stanford.protege.webprotege.postcoordinationservice.repositories.MinioPostCoordinationDocumentLoader; +import org.bson.Document; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +@SpringBootTest +@Import({WebprotegePostcoordinationServiceServiceApplication.class}) +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) +@ExtendWith({SpringExtension.class, IntegrationTest.class}) +@ActiveProfiles("test") +public class PostCoordinationCustomValueServiceTest { + + @Autowired + private ObjectMapper objectMapper; + @MockBean + private MinioPostCoordinationDocumentLoader documentLoader; + + @Autowired + private MongoTemplate mongoTemplate; + + @Autowired + private PostCoordinationService postCoordinationService; + @BeforeEach + public void setUp() throws IOException { + when(documentLoader.fetchPostCoordinationDocument(eq("postCoordinationScalesImportFile.json"))) + .thenReturn(new FileInputStream("src/test/resources/postCoordinationScalesImportFile.json")); + + } + + + @Test + public void GIVEN_firstImportFile_WHEN_importing_THEN_eventsAreCorrectlyMapped(){ + + postCoordinationService.crateFirstCustomScalesValuesImport("postCoordinationScalesImportFile.json", ProjectId.generate(), new UserId("alexsilaghi")); + + List histories = mongoTemplate.findAll(EntityCustomScalesValuesHistory.class); + assertNotNull(histories); + assertEquals(19, histories.size()); + Optional historyOptional = histories.stream() + .filter(history -> history.getWhoficEntityIri().equalsIgnoreCase("http://id.who.int/icd/entity/515117475")) + .findFirst(); + assertTrue(historyOptional.isPresent()); + assertNotNull(historyOptional.get().getPostCoordinationCustomScalesRevisions()); + assertEquals(1, historyOptional.get().getPostCoordinationCustomScalesRevisions().size()); + PostCoordinationCustomScalesRevision revision = historyOptional.get().getPostCoordinationCustomScalesRevisions().get(0); + assertEquals("alexsilaghi", revision.userId()); + assertEquals(7, revision.postCoordinationEventList().size()); + } +} diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationSpecificationServiceTest.java similarity index 99% rename from src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java rename to src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationSpecificationServiceTest.java index 4f337ba..e49e851 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationServiceTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationSpecificationServiceTest.java @@ -44,7 +44,7 @@ @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) @ExtendWith({SpringExtension.class, IntegrationTest.class}) @ActiveProfiles("test") -public class PostCoordinationServiceTest { +public class PostCoordinationSpecificationServiceTest { @Autowired diff --git a/src/test/resources/postCoordinationImportFile.json b/src/test/resources/postCoordinationImportFile.json index 03e50da..2ca3fcd 100644 --- a/src/test/resources/postCoordinationImportFile.json +++ b/src/test/resources/postCoordinationImportFile.json @@ -3,7 +3,7 @@ { "whoficEntityIri": "http://id.who.int/icd/entity/257068234", "entityType": "ICD", - "postcoordinationSpecifications": [ + "postCoordinationSpecifications": [ { "linearizationView": "http://id.who.int/icd/release/11/mnh" }, @@ -46,7 +46,7 @@ { "whoficEntityIri": "http://id.who.int/icd/entity/741162165", "entityType": "ICD", - "postcoordinationSpecifications": [ + "postCoordinationSpecifications": [ { "linearizationView": "http://id.who.int/icd/release/11/mnh" }, @@ -85,7 +85,7 @@ { "whoficEntityIri": "http://id.who.int/icd/entity/2042704797", "entityType": "ICD", - "postcoordinationSpecifications": [ + "postCoordinationSpecifications": [ { "linearizationView": "http://id.who.int/icd/release/11/mnh" }, diff --git a/src/test/resources/postCoordinationScalesImportFile.json b/src/test/resources/postCoordinationScalesImportFile.json new file mode 100644 index 0000000..19849a2 --- /dev/null +++ b/src/test/resources/postCoordinationScalesImportFile.json @@ -0,0 +1,317 @@ +{ + "postcoordinationScaleCustomization": [ + { + "whoficEntityIri": "http://id.who.int/icd/entity/135352227", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1882742628" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1434326374" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/hasManifestation" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/83217129" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/250688797", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1122666181", + "http://id.who.int/icd/entity/1721353160" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/temporalPatternAndOnset" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1158914813", + "http://id.who.int/icd/entity/1323892810" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1434326374" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/hasManifestation" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/1851734799", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/578694909" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/specificAnatomy" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/1561949126", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1837021781" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/1780040028", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1837021781" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1472717853", + "http://id.who.int/icd/entity/1763821141", + "http://id.who.int/icd/entity/1370972705" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/hasManifestation" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/77655243", + "http://id.who.int/icd/entity/1423652218", + "http://id.who.int/icd/entity/833038527" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/515117475", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1837021781" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/216184590", + "http://id.who.int/icd/entity/684930313", + "http://id.who.int/icd/entity/2058491071", + "http://id.who.int/icd/entity/1210263011", + "http://id.who.int/icd/entity/1323682030", + "http://id.who.int/icd/entity/293771399" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/hasManifestation" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/1520312138", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1837021781" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/1528414070", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1837021781" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1763821141", + "http://id.who.int/icd/entity/1472717853", + "http://id.who.int/icd/entity/554373034", + "http://id.who.int/icd/entity/2058491071", + "http://id.who.int/icd/entity/512128824", + "http://id.who.int/icd/entity/1323682030", + "http://id.who.int/icd/entity/1370972705", + "http://id.who.int/icd/entity/654702340" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/hasManifestation" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/364534567", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1837021781" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/794462570", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1929872537" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/1000894786", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/578694909", + "http://id.who.int/icd/entity/1928625572" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/specificAnatomy" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/554373034" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/hasManifestation" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/257068234", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1882742628" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/194483911", + "http://id.who.int/icd/entity/802386629", + "http://id.who.int/icd/entity/21927667" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/2080365623", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1385347061" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1683090852", + "http://id.who.int/icd/entity/622600769" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/hasManifestation" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1095665982", + "http://id.who.int/icd/entity/1527363560", + "http://id.who.int/icd/entity/512546847", + "http://id.who.int/icd/entity/80471749" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/344162786", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/916407020" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + }, + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1292092042" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/1828273122", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/916407020" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/162723448", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/916407020" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/2099226249", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/916407020" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/408185629", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/916407020" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/associatedWith" + } + ] + }, + { + "whoficEntityIri": "http://id.who.int/icd/entity/416025325", + "scaleCustomizations": [ + { + "postcoordinationScaleValues": [ + "http://id.who.int/icd/entity/1860930306", + "http://id.who.int/icd/entity/1808959816" + ], + "postcoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent" + } + ] + } + ] +} \ No newline at end of file From 4f1df516ef7ac715a4855d86645b5585c8485528 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Fri, 20 Sep 2024 12:34:08 +0300 Subject: [PATCH 5/6] added processing custom scale events --- .../GetEntityCustomScaleValueResponse.java | 16 +++++ .../GetEntityCustomScaleValuesRequest.java | 21 +++++++ .../events/AddCustomScaleValueEvent.java | 18 +++++- .../events/RemoveCustomScaleValueEvent.java | 15 ++++- ...EntityCustomScaleValuesCommandHandler.java | 52 ++++++++++++++++ ...tEntityPostCoordinationCommandHandler.java | 11 ++-- ...tCoordinationSpecificationsRepository.java | 34 +++++++++++ .../PostCoordinationEventProcessor.java | 15 +++-- .../services/PostCoordinationService.java | 13 ---- .../PostCoordinationEventProcessorTest.java | 51 ++++++++++++---- .../processedCustomValuesEvents.json | 59 +++++++++++++++++++ 11 files changed, 268 insertions(+), 37 deletions(-) create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityCustomScaleValueResponse.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityCustomScaleValuesRequest.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityCustomScaleValuesCommandHandler.java create mode 100644 src/test/resources/processedCustomValuesEvents.json diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityCustomScaleValueResponse.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityCustomScaleValueResponse.java new file mode 100644 index 0000000..54b2639 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityCustomScaleValueResponse.java @@ -0,0 +1,16 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import edu.stanford.protege.webprotege.common.Response; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; + +import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityCustomScaleValuesRequest.CHANNEL; + + +@JsonTypeName(CHANNEL) +public record GetEntityCustomScaleValueResponse (@JsonProperty("entityIri") + String entityIri, + @JsonProperty("postCoordinationScaleValues") + WhoficCustomScalesValues postCoordinationScaleValues) implements Response { +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityCustomScaleValuesRequest.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityCustomScaleValuesRequest.java new file mode 100644 index 0000000..e815a9a --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/dto/GetEntityCustomScaleValuesRequest.java @@ -0,0 +1,21 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import edu.stanford.protege.webprotege.common.ProjectId; +import edu.stanford.protege.webprotege.common.Request; + +import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityCustomScaleValuesRequest.CHANNEL; + + +@JsonTypeName(CHANNEL) +public record GetEntityCustomScaleValuesRequest(@JsonProperty("entityIRI") String entityIRI, + @JsonProperty("projectId") ProjectId projectId) implements Request { + + public static final String CHANNEL = "webprotege.postcoordination.GetEntityScaleValues"; + + @Override + public String getChannel() { + return CHANNEL; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddCustomScaleValueEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddCustomScaleValueEvent.java index 1dee6af..c1d9a39 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddCustomScaleValueEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/AddCustomScaleValueEvent.java @@ -2,8 +2,14 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationCustomScalesRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationCustomScalesRevision; import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + public class AddCustomScaleValueEvent extends PostCoordinationCustomScalesValueEvent { public final static String TYPE = "AddCustomScaleValue"; @@ -19,6 +25,16 @@ String getType() { @Override public void applyEvent(WhoficCustomScalesValues whoficCustomScalesValues) { - + Optional existingRequest = whoficCustomScalesValues.scaleCustomizations().stream() + .filter(scale -> scale.getPostCoordinationAxis().equalsIgnoreCase(this.getPostCoordinationAxis())) + .findFirst(); + if(existingRequest.isPresent()) { + existingRequest.get().getPostCoordinationScalesValues().add(this.getPostCoordinationScaleValue()); + } else { + List scaleValues = new ArrayList<>(); + scaleValues.add(this.getPostCoordinationScaleValue()); + PostCoordinationCustomScalesRequest request = new PostCoordinationCustomScalesRequest(scaleValues, this.getPostCoordinationAxis()); + whoficCustomScalesValues.scaleCustomizations().add(request); + } } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/RemoveCustomScaleValueEvent.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/RemoveCustomScaleValueEvent.java index 0cb56fe..fd3c4d4 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/RemoveCustomScaleValueEvent.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/events/RemoveCustomScaleValueEvent.java @@ -2,14 +2,18 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationCustomScalesRequest; import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; +import java.util.Optional; + public class RemoveCustomScaleValueEvent extends PostCoordinationCustomScalesValueEvent { public final static String TYPE = "RemoveCustomScaleValue"; @JsonCreator - public RemoveCustomScaleValueEvent(@JsonProperty("postCoordinationAxis") String postCoordinationAxis, @JsonProperty("postCoordinationScaleValue") String postCoordinationScaleValue) { + public RemoveCustomScaleValueEvent(@JsonProperty("postCoordinationAxis") String postCoordinationAxis, + @JsonProperty("postCoordinationScaleValue") String postCoordinationScaleValue) { super(postCoordinationAxis, postCoordinationScaleValue); } @@ -20,6 +24,13 @@ String getType() { @Override public void applyEvent(WhoficCustomScalesValues whoficCustomScalesValues) { - + Optional existingRequest = whoficCustomScalesValues.scaleCustomizations().stream() + .filter(scale -> scale.getPostCoordinationAxis().equalsIgnoreCase(this.getPostCoordinationAxis())) + .findFirst(); + if(existingRequest.isEmpty()) { + throw new RuntimeException("Removing scale value from missing postCoordinationAxis " + this.getPostCoordinationAxis()); + } else { + existingRequest.get().getPostCoordinationScalesValues().remove(this.getPostCoordinationScaleValue()); + } } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityCustomScaleValuesCommandHandler.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityCustomScaleValuesCommandHandler.java new file mode 100644 index 0000000..b6d1d09 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityCustomScaleValuesCommandHandler.java @@ -0,0 +1,52 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.handlers; + + +import edu.stanford.protege.webprotege.ipc.CommandHandler; +import edu.stanford.protege.webprotege.ipc.ExecutionContext; +import edu.stanford.protege.webprotege.ipc.WebProtegeHandler; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityCustomScaleValueResponse; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityCustomScaleValuesRequest; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.repositories.PostCoordinationSpecificationsRepository; +import edu.stanford.protege.webprotege.postcoordinationservice.services.PostCoordinationEventProcessor; +import org.jetbrains.annotations.NotNull; +import reactor.core.publisher.Mono; + +import java.util.ArrayList; +import java.util.Collections; + + +@WebProtegeHandler +public class GetEntityCustomScaleValuesCommandHandler implements CommandHandler { + + + private final PostCoordinationSpecificationsRepository repository; + + private final PostCoordinationEventProcessor postCoordinationEventProcessor; + + public GetEntityCustomScaleValuesCommandHandler(PostCoordinationSpecificationsRepository repository, PostCoordinationEventProcessor postCoordinationEventProcessor) { + this.repository = repository; + this.postCoordinationEventProcessor = postCoordinationEventProcessor; + } + + @NotNull + @Override + public String getChannelName() { + return GetEntityCustomScaleValuesRequest.CHANNEL; + } + + @Override + public Class getRequestClass() { + return GetEntityCustomScaleValuesRequest.class; + } + + @Override + public Mono handleRequest(GetEntityCustomScaleValuesRequest request, ExecutionContext executionContext) { + WhoficCustomScalesValues processedScales = this.repository.getExistingCustomScaleHistoryOrderedByRevision(request.entityIRI(), request.projectId()) + .map(postCoordinationEventProcessor::processCustomScaleHistory) + .orElseGet(() -> new WhoficCustomScalesValues(request.entityIRI(), Collections.emptyList())); + + return Mono.just(new GetEntityCustomScaleValueResponse(request.entityIRI(), processedScales)); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java index a3c7fbe..593ebfc 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/GetEntityPostCoordinationCommandHandler.java @@ -7,6 +7,7 @@ import edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationRequest; import edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationResponse; import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.repositories.PostCoordinationSpecificationsRepository; import edu.stanford.protege.webprotege.postcoordinationservice.services.PostCoordinationEventProcessor; import edu.stanford.protege.webprotege.postcoordinationservice.services.PostCoordinationService; import org.jetbrains.annotations.NotNull; @@ -17,13 +18,13 @@ @WebProtegeHandler public class GetEntityPostCoordinationCommandHandler implements CommandHandler { - private final PostCoordinationService postCoordinationService; - private final PostCoordinationEventProcessor postCoordinationEventProcessor; - public GetEntityPostCoordinationCommandHandler(PostCoordinationService postCoordinationService, PostCoordinationEventProcessor postCoordinationEventProcessor) { - this.postCoordinationService = postCoordinationService; + private final PostCoordinationSpecificationsRepository repository; + + public GetEntityPostCoordinationCommandHandler(PostCoordinationEventProcessor postCoordinationEventProcessor, PostCoordinationSpecificationsRepository repository) { this.postCoordinationEventProcessor = postCoordinationEventProcessor; + this.repository = repository; } @NotNull @@ -41,7 +42,7 @@ public Class getRequestClass() { public Mono handleRequest(GetEntityPostCoordinationRequest request, ExecutionContext executionContext) { WhoficEntityPostCoordinationSpecification processedSpec = - this.postCoordinationService.getExistingHistoryOrderedByRevision(request.entityIRI(), request.projectId()) + this.repository.getExistingHistoryOrderedByRevision(request.entityIRI(), request.projectId()) .map(postCoordinationEventProcessor::processHistory) .orElseGet(() -> new WhoficEntityPostCoordinationSpecification(request.entityIRI(), null, Collections.emptyList())); diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java index e26cb01..8018370 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java @@ -3,7 +3,10 @@ import com.mongodb.client.model.InsertOneModel; import edu.stanford.protege.webprotege.common.ProjectId; +import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityCustomScalesValuesHistory; import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; +import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationCustomScalesRevision; +import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationRevision; import edu.stanford.protege.webprotege.postcoordinationservice.services.ReadWriteLockService; import org.bson.Document; import org.springframework.data.mongodb.core.MongoTemplate; @@ -11,8 +14,10 @@ import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Repository; +import java.util.Comparator; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import static edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory.POSTCOORDINATION_HISTORY_COLLECTION; @@ -56,5 +61,34 @@ public Optional findHistoryByEntityIriAndProjectI return readWriteLock.executeReadLock(() -> Optional.ofNullable(mongoTemplate.findOne(query, EntityPostCoordinationHistory.class, POSTCOORDINATION_HISTORY_COLLECTION))); } + public Optional getExistingHistoryOrderedByRevision(String entityIri, ProjectId projectId) { + return findHistoryByEntityIriAndProjectId(entityIri, projectId) + .map(history -> { + List sortedRevisions = history.getPostCoordinationRevisions() + .stream() + .sorted(Comparator.comparingLong(PostCoordinationRevision::timestamp)) + .collect(Collectors.toList()); + // Return a new EntityLinearizationHistory object with the sorted revisions + return new EntityPostCoordinationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions); + }); + } + public Optional getExistingCustomScaleHistoryOrderedByRevision(String entityIri, ProjectId projectId) { + Query query = new Query(); + query.addCriteria( + Criteria.where(WHOFIC_ENTITY_IRI).is(entityIri) + .and(PROJECT_ID).is(projectId.value()) + ); + + return readWriteLock.executeReadLock(() -> + Optional.ofNullable(mongoTemplate.findOne(query, EntityCustomScalesValuesHistory.class, EntityCustomScalesValuesHistory.POSTCOORDINATION_CUSTOM_SCALES_COLLECTION)) + ).map(history -> { + List sortedRevisions = history.getPostCoordinationCustomScalesRevisions() + .stream() + .sorted(Comparator.comparingLong(PostCoordinationCustomScalesRevision::timestamp)) + .collect(Collectors.toList()); + return new EntityCustomScalesValuesHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions); + }); + + } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java index 68cb708..a2318f0 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessor.java @@ -1,11 +1,9 @@ package edu.stanford.protege.webprotege.postcoordinationservice.services; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationCustomScalesValueEvent; import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent; -import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; -import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationRevision; -import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationViewEvent; -import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.model.*; import org.springframework.stereotype.Service; import javax.annotation.Nonnull; @@ -39,4 +37,13 @@ private PostCoordinationSpecification findSpecificationWithLinearizationView(Str } + public WhoficCustomScalesValues processCustomScaleHistory(EntityCustomScalesValuesHistory entityCustomScalesValuesHistory) { + WhoficCustomScalesValues response = new WhoficCustomScalesValues(entityCustomScalesValuesHistory.getWhoficEntityIri(), new ArrayList<>()); + for(PostCoordinationCustomScalesRevision revision: entityCustomScalesValuesHistory.getPostCoordinationCustomScalesRevisions()) { + for(PostCoordinationCustomScalesValueEvent event: revision.postCoordinationEventList()) { + event.applyEvent(response); + } + } + return response; + } } diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java index 5471e4c..25ae3f6 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationService.java @@ -70,19 +70,6 @@ public void crateFirstCustomScalesValuesImport(String documentLocation, ProjectI }); } - public Optional getExistingHistoryOrderedByRevision(String entityIri, ProjectId projectId) { - return specRepository.findHistoryByEntityIriAndProjectId(entityIri, projectId) - .map(history -> { - List sortedRevisions = history.getPostCoordinationRevisions() - .stream() - .sorted(Comparator.comparingLong(PostCoordinationRevision::timestamp)) - .collect(Collectors.toList()); - // Return a new EntityLinearizationHistory object with the sorted revisions - return new EntityPostCoordinationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions); - }); - - } - private Consumer> createBatchProcessorForSavingPaginatedCustomScales(ProjectId projectId, UserId userId) { return page -> { diff --git a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessorTest.java b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessorTest.java index ba20544..c8922fe 100644 --- a/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessorTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/postcoordinationservice/services/PostCoordinationEventProcessorTest.java @@ -4,10 +4,9 @@ import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; import edu.stanford.protege.webprotege.postcoordinationservice.IntegrationTest; import edu.stanford.protege.webprotege.postcoordinationservice.WebprotegePostcoordinationServiceServiceApplication; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationCustomScalesRequest; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; -import edu.stanford.protege.webprotege.postcoordinationservice.model.EntityPostCoordinationHistory; -import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationRevision; -import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.model.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -22,8 +21,7 @@ import java.io.*; import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.eq; @SpringBootTest @@ -42,12 +40,13 @@ public class PostCoordinationEventProcessorTest { private EntityPostCoordinationHistory entityPostCoordinationHistory; - @BeforeEach - public void setUp() throws IOException { + private EntityCustomScalesValuesHistory customScalesValuesHistory; + + @Test + public void GIVEN_savedDocument_WHEN_processingEvents_THEN_correctResponseIsGiven() throws IOException { File initialFile = new File("src/test/resources/processedPostCoordinationHistory.json"); - InputStream targetStream = new FileInputStream(initialFile); objectMapper = new WebProtegeJacksonApplication().objectMapper(new OWLDataFactoryImpl()); - entityPostCoordinationHistory = objectMapper.readValue(targetStream, EntityPostCoordinationHistory.class); + entityPostCoordinationHistory = objectMapper.readValue(initialFile, EntityPostCoordinationHistory.class); List sortedRevisions = entityPostCoordinationHistory.getPostCoordinationRevisions() .stream() .toList() @@ -56,10 +55,8 @@ public void setUp() throws IOException { .toList(); entityPostCoordinationHistory = new EntityPostCoordinationHistory(entityPostCoordinationHistory.getWhoficEntityIri(), entityPostCoordinationHistory.getProjectId(), sortedRevisions); - } - @Test - public void GIVEN_savedDocument_WHEN_processingEvents_THEN_correctResponseIsGiven(){ + WhoficEntityPostCoordinationSpecification specification = postCoordinationEventProcessor.processHistory(entityPostCoordinationHistory); Optional envSpec = specification.postCoordinationSpecifications().stream() @@ -83,4 +80,34 @@ public void GIVEN_savedDocument_WHEN_processingEvents_THEN_correctResponseIsGive assertEquals(29, mmsSpec.get().getNotAllowedAxes().size()); assertEquals(0, mmsSpec.get().getRequiredAxes().size()); } + + + @Test + public void GIVEN_savedCustomScaleEvents_WHEN_processing_THEN_eventsAreCorrectlyProcessed() throws IOException { + File processedCustomScales = new File("src/test/resources/processedCustomValuesEvents.json"); + customScalesValuesHistory = objectMapper.readValue(processedCustomScales, EntityCustomScalesValuesHistory.class); + List sortedScalesRevision = customScalesValuesHistory.getPostCoordinationCustomScalesRevisions() + .stream() + .toList() + .stream() + .sorted(Comparator.comparingLong(PostCoordinationCustomScalesRevision::timestamp)) + .toList(); + customScalesValuesHistory = new EntityCustomScalesValuesHistory(customScalesValuesHistory.getWhoficEntityIri(), customScalesValuesHistory.getProjectId(), sortedScalesRevision); + + WhoficCustomScalesValues response = postCoordinationEventProcessor.processCustomScaleHistory(customScalesValuesHistory); + assertNotNull(response); + assertEquals(2, response.scaleCustomizations().size()); + + Optional infectiousAgent = response.scaleCustomizations().stream() + .filter(scale -> scale.getPostCoordinationAxis().equalsIgnoreCase("http://id.who.int/icd/schema/infectiousAgent")) + .findFirst(); + assertTrue(infectiousAgent.isPresent()); + assertEquals(2, infectiousAgent.get().getPostCoordinationScalesValues().size()); + + Optional associatedWith = response.scaleCustomizations().stream() + .filter(scale -> scale.getPostCoordinationAxis().equalsIgnoreCase("http://id.who.int/icd/schema/associatedWith")) + .findFirst(); + assertTrue(associatedWith.isPresent()); + assertEquals(1, associatedWith.get().getPostCoordinationScalesValues().size()); + } } diff --git a/src/test/resources/processedCustomValuesEvents.json b/src/test/resources/processedCustomValuesEvents.json new file mode 100644 index 0000000..46e158a --- /dev/null +++ b/src/test/resources/processedCustomValuesEvents.json @@ -0,0 +1,59 @@ +{ + "whoficEntityIri": "http://id.who.int/icd/entity/257068234", + "projectId": "b717d9a3-f265-46f5-bd15-9f1cf4b132c8", + "postCoordinationCustomScalesRevisions": [ + { + "userId": "alexsilaghi", + "timestamp": 1726752697105, + "postCoordinationEventList": [ + { + "@type": "AddCustomScaleValue", + "postCoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent", + "postCoordinationScaleValue": "http://id.who.int/icd/entity/802386629" + }, + { + "@type": "AddCustomScaleValue", + "postCoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent", + "postCoordinationScaleValue": "http://id.who.int/icd/entity/194483911" + }, + { + "@type": "AddCustomScaleValue", + "postCoordinationAxis": "http://id.who.int/icd/schema/associatedWith", + "postCoordinationScaleValue": "http://id.who.int/icd/entity/1882742628" + }, + { + "@type": "AddCustomScaleValue", + "postCoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent", + "postCoordinationScaleValue": "http://id.who.int/icd/entity/21927667" + } + ] + }, + { + "userId": "alexsilaghi", + "timestamp": 1726752699105, + "postCoordinationEventList": [ + { + "@type": "RemoveCustomScaleValue", + "postCoordinationAxis": "http://id.who.int/icd/schema/infectiousAgent", + "postCoordinationScaleValue": "http://id.who.int/icd/entity/802386629" + }, + { + "@type": "RemoveCustomScaleValue", + "postCoordinationAxis": "http://id.who.int/icd/schema/associatedWith", + "postCoordinationScaleValue": "http://id.who.int/icd/entity/1882742628" + } + ] + }, + { + "userId": "alexsilaghi", + "timestamp": 1726752699905, + "postCoordinationEventList": [ + { + "@type": "AddCustomScaleValue", + "postCoordinationAxis": "http://id.who.int/icd/schema/associatedWith", + "postCoordinationScaleValue": "http://id.who.int/icd/entity/9999999" + } + ] + } + ] +} \ No newline at end of file From 020290fdf818a19ea37e38df6a39dfac4d2a07e7 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Mon, 23 Sep 2024 12:24:31 +0300 Subject: [PATCH 6/6] ordered revision in reverse. --- .../PostCoordinationSpecificationsRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java index 8018370..19bb26b 100644 --- a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/repositories/PostCoordinationSpecificationsRepository.java @@ -66,7 +66,7 @@ public Optional getExistingHistoryOrderedByRevisi .map(history -> { List sortedRevisions = history.getPostCoordinationRevisions() .stream() - .sorted(Comparator.comparingLong(PostCoordinationRevision::timestamp)) + .sorted(Comparator.comparingLong(PostCoordinationRevision::timestamp).reversed()) .collect(Collectors.toList()); // Return a new EntityLinearizationHistory object with the sorted revisions return new EntityPostCoordinationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions); @@ -85,7 +85,7 @@ public Optional getExistingCustomScaleHistoryOr ).map(history -> { List sortedRevisions = history.getPostCoordinationCustomScalesRevisions() .stream() - .sorted(Comparator.comparingLong(PostCoordinationCustomScalesRevision::timestamp)) + .sorted(Comparator.comparingLong(PostCoordinationCustomScalesRevision::timestamp).reversed()) .collect(Collectors.toList()); return new EntityCustomScalesValuesHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions); });