Search in sources :

Example 1 with GeneratedInfo

use of org.kie.kogito.codegen.api.GeneratedInfo 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)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Workflow (io.serverlessworkflow.api.Workflow)1 EventDefinition (io.serverlessworkflow.api.events.EventDefinition)1 Constants (io.serverlessworkflow.api.workflow.Constants)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 VariableScope (org.jbpm.process.core.context.variable.VariableScope)1 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)1 TIME_DURATION (org.jbpm.process.core.timer.Timer.TIME_DURATION)1 Metadata (org.jbpm.ruleflow.core.Metadata)1 UNIQUE_ID (org.jbpm.ruleflow.core.Metadata.UNIQUE_ID)1 RuleFlowNodeContainerFactory (org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory)1 RuleFlowProcessFactory (org.jbpm.ruleflow.core.RuleFlowProcessFactory)1 JoinFactory (org.jbpm.ruleflow.core.factory.JoinFactory)1 NodeFactory (org.jbpm.ruleflow.core.factory.NodeFactory)1