Skip to content

Commit

Permalink
SED-2970 opening-target-of-call-plan-within-composite-failing (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-stephan authored Apr 11, 2024
1 parent 9af72f6 commit e2a9bc2
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.bson.types.ObjectId;
import step.artefacts.CallPlan;
import step.artefacts.handlers.PlanLocator;
import step.artefacts.handlers.SelectorHelper;
import step.core.GlobalContext;
import step.core.artefacts.AbstractArtefact;
import step.core.deployment.AbstractStepServices;
import step.core.deployment.ControllerServiceException;
import step.core.plans.Plan;
import step.core.plans.PlanAccessor;
import step.core.plans.PlanType;
import step.core.plans.PlanTypeRegistry;
import step.core.dynamicbeans.DynamicJsonObjectResolver;
import step.core.dynamicbeans.DynamicJsonValueResolver;
import step.core.objectenricher.ObjectPredicate;
import step.core.objectenricher.ObjectPredicateFactory;
import step.core.plans.*;
import step.framework.server.security.Secured;
import step.functions.Function;
import step.functions.accessor.FunctionAccessor;
Expand All @@ -49,6 +53,7 @@ public class CompositeFunctionServices extends AbstractStepServices {
private FunctionAccessor functionAccessor;
private PlanTypeRegistry planTypeRegistry;
private PlanAccessor planAccessor;
private ObjectPredicateFactory objectPredicateFactory;

@PostConstruct
public void init() throws Exception {
Expand All @@ -57,6 +62,7 @@ public void init() throws Exception {
functionAccessor = getContext().get(FunctionAccessor.class);
planAccessor = getContext().getPlanAccessor();
planTypeRegistry = context.get(PlanTypeRegistry.class);
objectPredicateFactory = context.get(ObjectPredicateFactory.class);
}

@Operation(operationId = "cloneCompositePlan", description = "Clones the plan of the composite to a new plan")
Expand Down Expand Up @@ -84,6 +90,30 @@ public Plan clone(@PathParam("id") String id) {
return clonePlan;
}

@Operation(description = "Returns the plan referenced by the given artifact within the given composite.")
@GET
@Path("/{id}/artefacts/{artefactid}/lookup/plan")
@Produces(MediaType.APPLICATION_JSON)
@Secured(right="plan-read")
public Plan lookupPlan(@PathParam("id") String id, @PathParam("artefactid") String artefactId) {
Function function = functionAccessor.get(id);
if (!(function instanceof CompositeFunction)) {
throw new ControllerServiceException("The look of plan can only be performed for composite keywords.");
}
Plan plan = ((CompositeFunction) function).getPlan();
Plan result = null;
PlanNavigator planNavigator = new PlanNavigator(plan);
CallPlan artefact = (CallPlan) planNavigator.findArtefactById(artefactId);
DynamicJsonObjectResolver dynamicJsonObjectResolver = new DynamicJsonObjectResolver(new DynamicJsonValueResolver(getContext().getExpressionHandler()));
SelectorHelper selectorHelper = new SelectorHelper(dynamicJsonObjectResolver);
PlanLocator planLocator = new PlanLocator(getContext().getPlanAccessor(), selectorHelper);
ObjectPredicate objectPredicate = objectPredicateFactory.getObjectPredicate(getSession());
try {
result = planLocator.selectPlan(artefact, objectPredicate, null);
} catch (RuntimeException e) {}
return result;
}

private void assignNewId(AbstractArtefact artefact) {
artefact.setId(new ObjectId());
artefact.getChildren().forEach(this::assignNewId);
Expand Down

0 comments on commit e2a9bc2

Please sign in to comment.