Skip to content

Commit

Permalink
added creation of postcoordination specification to new created entity
Browse files Browse the repository at this point in the history
  • Loading branch information
soimugeo committed Oct 15, 2024
1 parent 8e99cda commit 6149f70
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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<CreatePostcoordinationFromParentRequest, CreatePostcoordinationFromParentResponse> {

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<CreatePostcoordinationFromParentRequest> getRequestClass() {
return CreatePostcoordinationFromParentRequest.class;
}

@Override
public Mono<CreatePostcoordinationFromParentResponse> handleRequest(CreatePostcoordinationFromParentRequest request, ExecutionContext executionContext) {
List<LinearizationDefinition> definitionList = linService.getLinearizationDefinitions();

var parentWhoficSpec = postCoordProcessor.fetchHistory(request.parentEntityIri().toString(), request.projectId());
List<PostCoordinationSpecification> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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<CreatePostcoordinationFromParentResponse> {

public final static String CHANNEL = "webprotege.postcoordination.CreateFromParentEntity";

@Override
public String getChannel() {
return CHANNEL;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<PostCoordinationSpecification> postcoordinationSpecifications) {

@JsonCreator
public WhoficEntityPostCoordinationSpecification(@JsonProperty("whoficEntityIri") @NotNull String whoficEntityIri,
@JsonProperty("entityType") String entityType,
@JsonProperty("postcoordinationSpecifications") List<PostCoordinationSpecification> postcoordinationSpecifications) {
public WhoficEntityPostCoordinationSpecification(@NotNull String whoficEntityIri,
String entityType,
List<PostCoordinationSpecification> 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<PostCoordinationSpecification> postcoordinationSpecifications) {
return new WhoficEntityPostCoordinationSpecification(whoficEntityIri,
entityType,
postcoordinationSpecifications);
}
}

0 comments on commit 6149f70

Please sign in to comment.