-
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 GetParentThatIsLinearizationPathParentCommandHandler
- Loading branch information
1 parent
026612e
commit 5819f1d
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...e/linearizationservice/handlers/GetParentThatIsLinearizationPathParentCommandHandler.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,59 @@ | ||
package edu.stanford.protege.webprotege.linearizationservice.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.linearizationservice.model.WhoficEntityLinearizationSpecification; | ||
import edu.stanford.protege.webprotege.linearizationservice.services.LinearizationEventsProcessorService; | ||
import edu.stanford.protege.webprotege.linearizationservice.services.LinearizationHistoryService; | ||
import org.jetbrains.annotations.NotNull; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Collections; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@WebProtegeHandler | ||
public class GetParentThatIsLinearizationPathParentCommandHandler implements CommandHandler<GetParentThatIsLinearizationPathParentRequest, GetParentThatIsLinearizationPathParentResponse> { | ||
|
||
private final LinearizationHistoryService linearizationHistoryService; | ||
private final LinearizationEventsProcessorService linearizationEventsProcessor; | ||
|
||
|
||
public GetParentThatIsLinearizationPathParentCommandHandler(LinearizationHistoryService linearizationHistoryService, | ||
LinearizationEventsProcessorService linearizationEventsProcessor) { | ||
this.linearizationHistoryService = linearizationHistoryService; | ||
this.linearizationEventsProcessor = linearizationEventsProcessor; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getChannelName() { | ||
return GetParentThatIsLinearizationPathParentRequest.CHANNEL; | ||
} | ||
|
||
@Override | ||
public Class<GetParentThatIsLinearizationPathParentRequest> getRequestClass() { | ||
return GetParentThatIsLinearizationPathParentRequest.class; | ||
} | ||
|
||
@Override | ||
public Mono<GetParentThatIsLinearizationPathParentResponse> handleRequest(GetParentThatIsLinearizationPathParentRequest request, ExecutionContext executionContext) { | ||
|
||
WhoficEntityLinearizationSpecification processedSpec = | ||
this.linearizationHistoryService.getExistingHistoryOrderedByRevision(request.currentEntityIri(), request.projectId()) | ||
.map(linearizationEventsProcessor::processHistory) | ||
.orElseGet(() -> new WhoficEntityLinearizationSpecification(request.currentEntityIri(), null, Collections.emptyList())); | ||
|
||
var linearizationParents = processedSpec.linearizationSpecifications() | ||
.stream() | ||
.map(spec -> Stream.of(spec.getLinearizationParent())) | ||
.collect(Collectors.toSet()); | ||
var matchingParent = request.parentEntityIris() | ||
.stream() | ||
.filter(linearizationParents::contains) | ||
.findAny(); | ||
|
||
return Mono.just(new GetParentThatIsLinearizationPathParentResponse(matchingParent)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...bprotege/linearizationservice/handlers/GetParentThatIsLinearizationPathParentRequest.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,29 @@ | ||
package edu.stanford.protege.webprotege.linearizationservice.handlers; | ||
|
||
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 org.semanticweb.owlapi.model.IRI; | ||
|
||
import java.util.Set; | ||
|
||
@JsonTypeName(GetParentThatIsLinearizationPathParentRequest.CHANNEL) | ||
public record GetParentThatIsLinearizationPathParentRequest( | ||
@JsonProperty("currentEntityIri") IRI currentEntityIri, | ||
@JsonProperty("parentEntityIris") Set<IRI> parentEntityIris, | ||
@JsonProperty("projectId") ProjectId projectId | ||
) implements Request<GetParentThatIsLinearizationPathParentResponse> { | ||
|
||
public final static String CHANNEL = "webprotege.linearization.GetParentThatIsLinearizationPathParent"; | ||
|
||
@Override | ||
public String getChannel() { | ||
return CHANNEL; | ||
} | ||
|
||
public static GetParentThatIsLinearizationPathParentRequest create(IRI currentEntityIri, Set<IRI> parentEntityIris, ProjectId projectId) { | ||
return new GetParentThatIsLinearizationPathParentRequest(currentEntityIri, parentEntityIris, projectId); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...protege/linearizationservice/handlers/GetParentThatIsLinearizationPathParentResponse.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,14 @@ | ||
package edu.stanford.protege.webprotege.linearizationservice.handlers; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import edu.stanford.protege.webprotege.common.Response; | ||
import org.semanticweb.owlapi.model.IRI; | ||
|
||
import java.util.Optional; | ||
|
||
@JsonTypeName(GetParentThatIsLinearizationPathParentRequest.CHANNEL) | ||
public record GetParentThatIsLinearizationPathParentResponse( | ||
@JsonProperty("parentAsLinearizationPathParent") Optional<IRI> parentAsLinearizationPathParent | ||
) implements Response { | ||
} |