-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added creation of postcoordination specification to new created entity
- Loading branch information
Showing
4 changed files
with
117 additions
and
10 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...tege/postcoordinationservice/handlers/CreatePostcoordinationFromParentCommandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
.../webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...webprotege/postcoordinationservice/handlers/CreatePostcoordinationFromParentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
26 changes: 16 additions & 10 deletions
26
...e/webprotege/postcoordinationservice/model/WhoficEntityPostCoordinationSpecification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |