Skip to content

Commit

Permalink
added GetParentThatIsLinearizationPathParentCommandHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
soimugeoWB committed Jan 15, 2025
1 parent 026612e commit 5819f1d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
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));
}
}
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);
}

}
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 {
}

0 comments on commit 5819f1d

Please sign in to comment.