From 6149f70b42cdc0bf70b0f1a1879498bb54fa0b62 Mon Sep 17 00:00:00 2001 From: Gheorghe Soimu Date: Tue, 15 Oct 2024 18:17:36 +0300 Subject: [PATCH] added creation of postcoordination specification to new created entity --- ...tcoordinationFromParentCommandHandler.java | 69 +++++++++++++++++++ ...eatePostcoordinationFromParentRequest.java | 20 ++++++ ...atePostcoordinationFromParentResponse.java | 12 ++++ ...icEntityPostCoordinationSpecification.java | 26 ++++--- 4 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentCommandHandler.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentRequest.java create mode 100644 src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentResponse.java diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentCommandHandler.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentCommandHandler.java new file mode 100644 index 0000000..d5ee037 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentCommandHandler.java @@ -0,0 +1,69 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.handlers; + +import edu.stanford.protege.webprotege.ipc.*; +import edu.stanford.protege.webprotege.postcoordinationservice.dto.*; +import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification; +import edu.stanford.protege.webprotege.postcoordinationservice.services.*; +import org.jetbrains.annotations.NotNull; +import reactor.core.publisher.Mono; + +import java.util.*; + +@WebProtegeHandler +public class CreatePostcoordinationFromParentCommandHandler implements CommandHandler { + + private final PostCoordinationEventProcessor postCoordProcessor; + private final LinearizationService linService; + + public CreatePostcoordinationFromParentCommandHandler(PostCoordinationEventProcessor postCoordProcessor, + LinearizationService linService) { + + this.postCoordProcessor = postCoordProcessor; + this.linService = linService; + } + + @NotNull + @Override + public String getChannelName() { + return CreatePostcoordinationFromParentRequest.CHANNEL; + } + + @Override + public Class getRequestClass() { + return CreatePostcoordinationFromParentRequest.class; + } + + @Override + public Mono handleRequest(CreatePostcoordinationFromParentRequest request, ExecutionContext executionContext) { + List definitionList = linService.getLinearizationDefinitions(); + + var parentWhoficSpec = postCoordProcessor.fetchHistory(request.parentEntityIri().toString(), request.projectId()); + List newSpecsList = new ArrayList<>(); + + parentWhoficSpec.postcoordinationSpecifications().forEach(spec -> { + var currDef = definitionList.stream().filter(lin -> lin.getWhoficEntityIri().equalsIgnoreCase(spec.getLinearizationView())).findFirst(); + if (currDef.isEmpty()) { + return; + } + var allAxes = new ArrayList<>(spec.getAllowedAxes()); + allAxes.addAll(spec.getDefaultAxes()); + allAxes.addAll(spec.getRequiredAxes()); + allAxes.addAll(spec.getNotAllowedAxes()); + PostCoordinationSpecification newSpec = new PostCoordinationSpecification(spec.getLinearizationView(), null, null, null, null); + + if (currDef.get().getCoreLinId() != null) { + newSpec.getDefaultAxes().addAll(allAxes); + } else { + newSpec.getNotAllowedAxes().addAll(allAxes); + } + newSpecsList.add(newSpec); + }); + + postCoordProcessor.saveNewSpecificationRevision( + WhoficEntityPostCoordinationSpecification.create(request.newEntityIri().toString(), parentWhoficSpec.entityType(), newSpecsList), + executionContext.userId(), + request.projectId() + ); + return Mono.just(CreatePostcoordinationFromParentResponse.create()); + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentRequest.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentRequest.java new file mode 100644 index 0000000..c45dd40 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentRequest.java @@ -0,0 +1,20 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.handlers; + +import com.fasterxml.jackson.annotation.*; +import edu.stanford.protege.webprotege.common.*; +import org.semanticweb.owlapi.model.IRI; + +@JsonTypeName(CreatePostcoordinationFromParentRequest.CHANNEL) +public record CreatePostcoordinationFromParentRequest( + @JsonProperty("newEntityIri") IRI newEntityIri, + @JsonProperty("parentEntityIri") IRI parentEntityIri, + @JsonProperty("projectId") ProjectId projectId +) implements Request { + + public final static String CHANNEL = "webprotege.postcoordination.CreateFromParentEntity"; + + @Override + public String getChannel() { + return CHANNEL; + } +} diff --git a/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentResponse.java b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentResponse.java new file mode 100644 index 0000000..90dd8ff --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentResponse.java @@ -0,0 +1,12 @@ +package edu.stanford.protege.webprotege.postcoordinationservice.handlers; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import edu.stanford.protege.webprotege.common.Response; + + +@JsonTypeName(CreatePostcoordinationFromParentRequest.CHANNEL) +public record CreatePostcoordinationFromParentResponse() implements Response { + public static CreatePostcoordinationFromParentResponse create() { + return new CreatePostcoordinationFromParentResponse(); + } +} 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 0395e2b..dc746d5 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 @@ -1,23 +1,29 @@ package edu.stanford.protege.webprotege.postcoordinationservice.model; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.*; import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import java.util.*; -public record WhoficEntityPostCoordinationSpecification(@JsonProperty("whoficEntityIri") String whoficEntityIri, @JsonProperty("entityType") String entityType, +public record WhoficEntityPostCoordinationSpecification(@JsonProperty("whoficEntityIri") String whoficEntityIri, + @JsonProperty("entityType") String entityType, @JsonProperty("postcoordinationSpecifications") List postcoordinationSpecifications) { - @JsonCreator - public WhoficEntityPostCoordinationSpecification(@JsonProperty("whoficEntityIri") @NotNull String whoficEntityIri, - @JsonProperty("entityType") String entityType, - @JsonProperty("postcoordinationSpecifications") List postcoordinationSpecifications) { + public WhoficEntityPostCoordinationSpecification(@NotNull String whoficEntityIri, + String entityType, + List postcoordinationSpecifications) { this.whoficEntityIri = whoficEntityIri; this.entityType = Objects.requireNonNullElse(entityType, "ICD"); this.postcoordinationSpecifications = Objects.requireNonNullElseGet(postcoordinationSpecifications, ArrayList::new); } + + @JsonCreator + public static WhoficEntityPostCoordinationSpecification create(@JsonProperty("whoficEntityIri") @NotNull String whoficEntityIri, + @JsonProperty("entityType") String entityType, + @JsonProperty("postcoordinationSpecifications") List postcoordinationSpecifications) { + return new WhoficEntityPostCoordinationSpecification(whoficEntityIri, + entityType, + postcoordinationSpecifications); + } }