Search in sources :

Example 1 with Workflow

use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.

the class ServerlessWorkflowParsingTest method testSpecExamplesParsing.

@ParameterizedTest
@ValueSource(strings = { "/examples/applicantworkflow.sw.json", "/exec/error.sw.json", "/exec/callback.sw.json", "/exec/compensation.sw.json", "/exec/compensation.end.sw.json", "/exec/foreach.sw.json" })
public void testSpecExamplesParsing(String workflowLocation) throws IOException {
    Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
    assertNotNull(workflow);
    assertNotNull(workflow.getId());
    assertNotNull(workflow.getName());
    assertNotNull(workflow.getStates());
    assertTrue(workflow.getStates().size() > 0);
    RuleFlowProcess process = (RuleFlowProcess) getWorkflowParser(workflowLocation);
    assertNotNull(process);
    assertNotNull(process.getId());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Workflow(io.serverlessworkflow.api.Workflow) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Workflow

use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.

the class ServerlessWorkflowParsingTest method testSpecOpenApiFunctionParsing.

@ParameterizedTest
@ValueSource(strings = { "/exec/openapi-greeting-operation.sw.json" })
public void testSpecOpenApiFunctionParsing(String workflowLocation) throws IOException {
    Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
    assertNotNull(workflow);
    assertNotNull(workflow.getId());
    assertNotNull(workflow.getName());
    assertNotNull(workflow.getStates());
    assertTrue(workflow.getStates().size() > 0);
    assertEquals(1, workflow.getFunctions().getFunctionDefs().size());
    RuleFlowProcess process = (RuleFlowProcess) getWorkflowParser(workflowLocation);
    assertNotNull(process);
    assertNotNull(process.getId());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Workflow(io.serverlessworkflow.api.Workflow) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Workflow

use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.

the class ServerlessWorkflowParsingTest method testMinimumWorkflow.

@Test
public void testMinimumWorkflow() {
    Workflow workflow = new Workflow();
    workflow.setId("javierito");
    Start start = new Start();
    start.setStateName("javierito");
    End end = new End();
    end.setTerminate(true);
    SleepState startState = new SleepState();
    startState.setType(Type.SLEEP);
    startState.setDuration("1s");
    startState.setName("javierito");
    startState.setEnd(end);
    workflow.setStates(Collections.singletonList(startState));
    workflow.setStart(start);
    ServerlessWorkflowParser parser = ServerlessWorkflowParser.of(workflow, JavaKogitoBuildContext.builder().build());
    Process process = parser.getProcessInfo().info();
    assertSame(process, parser.getProcessInfo().info());
    assertEquals(ServerlessWorkflowParser.DEFAULT_NAME, process.getName());
    assertEquals(ServerlessWorkflowParser.DEFAULT_VERSION, process.getVersion());
    assertEquals(ServerlessWorkflowParser.DEFAULT_PACKAGE, process.getPackageName());
}
Also used : Start(io.serverlessworkflow.api.start.Start) ServerlessWorkflowParser(org.kie.kogito.serverless.workflow.parser.ServerlessWorkflowParser) Workflow(io.serverlessworkflow.api.Workflow) End(io.serverlessworkflow.api.end.End) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) SleepState(io.serverlessworkflow.api.states.SleepState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Workflow

use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.

the class ServerlessWorkflowParser method parseProcess.

private GeneratedInfo<KogitoWorkflowProcess> parseProcess() {
    String workflowStartStateName = workflow.getStart().getStateName();
    if (workflowStartStateName == null || workflowStartStateName.trim().isEmpty()) {
        throw new IllegalArgumentException("workflow does not define a starting state");
    }
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess(workflow.getId()).name(workflow.getName() == null ? DEFAULT_NAME : workflow.getName()).version(workflow.getVersion() == null ? DEFAULT_VERSION : workflow.getVersion()).packageName(workflow.getMetadata() != null ? workflow.getMetadata().getOrDefault("package", DEFAULT_PACKAGE) : DEFAULT_PACKAGE).visibility("Public").variable(DEFAULT_WORKFLOW_VAR, new ObjectDataType(JsonNode.class), ObjectMapperFactory.get().createObjectNode());
    ParserContext parserContext = new ParserContext(idGenerator, factory, context);
    Constants constants = workflow.getConstants();
    if (constants != null) {
        factory.metaData(Metadata.CONSTANTS, constants.getConstantsDef());
    }
    Collection<StateHandler<?>> handlers = workflow.getStates().stream().map(state -> StateHandlerFactory.getStateHandler(state, workflow, parserContext)).filter(Optional::isPresent).map(Optional::get).filter(state -> !state.usedForCompensation()).collect(Collectors.toList());
    handlers.forEach(StateHandler::handleStart);
    handlers.forEach(StateHandler::handleEnd);
    handlers.forEach(StateHandler::handleState);
    handlers.forEach(StateHandler::handleTransitions);
    handlers.forEach(StateHandler::handleErrors);
    handlers.forEach(StateHandler::handleConnections);
    if (parserContext.isCompensation()) {
        factory.metaData(Metadata.COMPENSATION, true);
        factory.addCompensationContext(workflow.getId());
    }
    return new GeneratedInfo<>(factory.validate().getProcess(), parserContext.generatedFiles());
}
Also used : ObjectMapperFactory(org.kie.kogito.jackson.utils.ObjectMapperFactory) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) Constants(io.serverlessworkflow.api.workflow.Constants) Split(org.jbpm.workflow.core.node.Split) NodeFactory(org.jbpm.ruleflow.core.factory.NodeFactory) Workflow(io.serverlessworkflow.api.Workflow) JoinFactory(org.jbpm.ruleflow.core.factory.JoinFactory) StateHandlerFactory(org.kie.kogito.serverless.workflow.parser.handlers.StateHandlerFactory) StateHandler(org.kie.kogito.serverless.workflow.parser.handlers.StateHandler) DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) Map(java.util.Map) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) SubProcessNodeFactory(org.jbpm.ruleflow.core.factory.SubProcessNodeFactory) UNIQUE_ID(org.jbpm.ruleflow.core.Metadata.UNIQUE_ID) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) Join(org.jbpm.workflow.core.node.Join) Metadata(org.jbpm.ruleflow.core.Metadata) TimerNodeFactory(org.jbpm.ruleflow.core.factory.TimerNodeFactory) Collection(java.util.Collection) RuleFlowNodeContainerFactory(org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory) TIME_DURATION(org.jbpm.process.core.timer.Timer.TIME_DURATION) IOException(java.io.IOException) Reader(java.io.Reader) EventDefinition(io.serverlessworkflow.api.events.EventDefinition) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) GeneratedInfo(org.kie.kogito.codegen.api.GeneratedInfo) SWFConstants(org.kie.kogito.serverless.workflow.SWFConstants) Optional(java.util.Optional) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) Collections(java.util.Collections) SplitFactory(org.jbpm.ruleflow.core.factory.SplitFactory) ServerlessWorkflowUtils(org.kie.kogito.serverless.workflow.utils.ServerlessWorkflowUtils) StateHandler(org.kie.kogito.serverless.workflow.parser.handlers.StateHandler) Optional(java.util.Optional) Constants(io.serverlessworkflow.api.workflow.Constants) SWFConstants(org.kie.kogito.serverless.workflow.SWFConstants) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) JsonNode(com.fasterxml.jackson.databind.JsonNode) GeneratedInfo(org.kie.kogito.codegen.api.GeneratedInfo) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory)

Example 5 with Workflow

use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.

the class BuildExpressionsTest method testReplaceExpr.

@Test
void testReplaceExpr() {
    Workflow flow = mock(Workflow.class);
    FunctionDefinition functionDefinition = new FunctionDefinition();
    functionDefinition.setType(Type.EXPRESSION);
    functionDefinition.setOperation(".pepe");
    functionDefinition.setName("pepe");
    Functions functions = new Functions(Collections.singletonList(functionDefinition));
    when(flow.getFunctions()).thenReturn(functions);
    assertEquals("\"fn:pepe\"", ExpressionHandlerUtils.replaceExpr(flow, "\"fn:pepe\""));
    assertEquals(".pepe", ExpressionHandlerUtils.replaceExpr(flow, "fn:pepe"));
    assertEquals(".pepe", ExpressionHandlerUtils.replaceExpr(flow, "${fn:pepe}"));
    assertThrows(IllegalArgumentException.class, () -> ExpressionHandlerUtils.replaceExpr(flow, "${fn:NoPepe}"));
}
Also used : Workflow(io.serverlessworkflow.api.Workflow) FunctionDefinition(io.serverlessworkflow.api.functions.FunctionDefinition) Functions(io.serverlessworkflow.api.workflow.Functions) Test(org.junit.jupiter.api.Test)

Aggregations

Workflow (io.serverlessworkflow.api.Workflow)13 Connection (io.automatiko.engine.api.definition.process.Connection)5 DateTimeUtils (io.automatiko.engine.workflow.base.core.timer.DateTimeUtils)5 OutputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.OutputJqAssignmentAction)5 NodeContainer (io.automatiko.engine.workflow.process.core.NodeContainer)5 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)5 Assignment (io.automatiko.engine.workflow.process.core.node.Assignment)5 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)5 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)5 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)5 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)5 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)5 EventDefinition (io.serverlessworkflow.api.events.EventDefinition)5 FunctionDefinition (io.serverlessworkflow.api.functions.FunctionDefinition)5 Collections (java.util.Collections)5 List (java.util.List)5 Map (java.util.Map)5 Join (io.automatiko.engine.workflow.process.core.node.Join)4 Split (io.automatiko.engine.workflow.process.core.node.Split)4 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)4