use of org.kie.kogito.serverless.workflow.parser.handlers.StateHandler 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());
}
Aggregations