Search in sources :

Example 1 with SysoutActionSupplier

use of org.kie.kogito.serverless.workflow.suppliers.SysoutActionSupplier in project kogito-runtimes by kiegroup.

the class CompositeContextNodeHandler method getActionNode.

private NodeFactory<?, ?> getActionNode(RuleFlowNodeContainerFactory<?, ?> embeddedSubProcess, FunctionRef functionRef, String inputVar, String outputVar, String collectVar, String... extraVariables) {
    JsonNode functionArgs = functionRef.getArguments();
    String actionName = functionRef.getRefName();
    FunctionDefinition actionFunction = workflow.getFunctions().getFunctionDefs().stream().filter(wf -> wf.getName().equals(actionName)).findFirst().orElseThrow(() -> new IllegalArgumentException("cannot find function " + actionName));
    ActionType actionType = ActionType.from(actionFunction);
    String operation = actionType.getOperation(actionFunction);
    switch(actionType) {
        case SCRIPT:
            return embeddedSubProcess.actionNode(parserContext.newId()).name(actionName).action(JavaDialect.ID, functionRef.getArguments().get(SCRIPT_TYPE_PARAM).asText());
        case EXPRESSION:
            return embeddedSubProcess.actionNode(parserContext.newId()).name(actionName).action(ExpressionActionSupplier.of(workflow, operation).withVarNames(inputVar, outputVar).withCollectVar(collectVar).withAddInputVars(extraVariables).build());
        case SYSOUT:
            return embeddedSubProcess.actionNode(parserContext.newId()).name(actionName).action(new SysoutActionSupplier(workflow.getExpressionLang(), functionRef.getArguments().get(SYSOUT_TYPE_PARAM).asText(), inputVar, extraVariables));
        case SERVICE:
            WorkItemNodeFactory<?> serviceFactory = addServiceParameters(embeddedSubProcess.workItemNode(parserContext.newId()).name(actionName).metaData(TaskDescriptor.KEY_WORKITEM_TYPE, SERVICE_TASK_TYPE).workName(SERVICE_TASK_TYPE).inMapping(inputVar, WORKITEM_PARAM).outMapping(WORKITEM_PARAM, outputVar), actionFunction, operation);
            if (functionArgs == null || functionArgs.isEmpty()) {
                serviceFactory.workParameter(WORKITEM_PARAM_TYPE, ServerlessWorkflowParser.JSON_NODE);
            } else {
                processArgs(serviceFactory, functionArgs, WORKITEM_PARAM, ObjectResolver.class);
            }
            return serviceFactory;
        case REST:
            WorkItemNodeFactory<?> workItemFactory = addRestParameters(embeddedSubProcess.workItemNode(parserContext.newId()).name(actionFunction.getName()).metaData(TaskDescriptor.KEY_WORKITEM_TYPE, RestWorkItemHandler.REST_TASK_TYPE).workName(RestWorkItemHandler.REST_TASK_TYPE).workParameter(RestWorkItemHandler.BODY_BUILDER, new RestBodyBuilderSupplier()).inMapping(inputVar, RestWorkItemHandler.CONTENT_DATA).outMapping(RestWorkItemHandler.RESULT, outputVar), actionFunction, operation);
            if (functionArgs != null && !functionArgs.isEmpty()) {
                processArgs(workItemFactory, functionArgs, RestWorkItemHandler.CONTENT_DATA, ObjectResolver.class);
            }
            return workItemFactory;
        case OPENAPI:
            return OpenApiTaskDescriptor.builderFor(ServerlessWorkflowUtils.getOpenApiURI(actionFunction), ServerlessWorkflowUtils.getOpenApiOperationId(actionFunction)).withExprLang(workflow.getExpressionLang()).withModelParameter(WORKITEM_PARAM).withArgs(functionsToMap(functionArgs), JsonNodeResolver.class, JsonNode.class).build(embeddedSubProcess.workItemNode(parserContext.newId())).name(functionRef.getRefName()).inMapping(inputVar, WORKITEM_PARAM).outMapping(WORKITEM_RESULT, outputVar);
        default:
            return emptyNode(embeddedSubProcess, actionName);
    }
}
Also used : SysoutActionSupplier(org.kie.kogito.serverless.workflow.suppliers.SysoutActionSupplier) RestBodyBuilderSupplier(org.kie.kogito.serverless.workflow.suppliers.RestBodyBuilderSupplier) JsonNode(com.fasterxml.jackson.databind.JsonNode) FunctionDefinition(io.serverlessworkflow.api.functions.FunctionDefinition)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 FunctionDefinition (io.serverlessworkflow.api.functions.FunctionDefinition)1 RestBodyBuilderSupplier (org.kie.kogito.serverless.workflow.suppliers.RestBodyBuilderSupplier)1 SysoutActionSupplier (org.kie.kogito.serverless.workflow.suppliers.SysoutActionSupplier)1