use of io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_PROCESS_ID in project automatiko-engine by automatiko-io.
the class LambdaSubProcessNodeVisitor method visitNode.
@Override
public void visitNode(WorkflowProcess process, String factoryField, SubProcessNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
InputStream resourceAsStream = this.getClass().getResourceAsStream("/class-templates/SubProcessFactoryTemplate.java");
Optional<Expression> retValue = parse(resourceAsStream).findFirst(Expression.class);
String name = node.getName();
String subProcessId = node.getProcessId();
String subProcessVersion = ModelMetaData.version(node.getProcessVersion());
NodeValidator.of(getNodeKey(), name).notEmpty("subProcessId", subProcessId).validate();
body.addStatement(getAssignedFactoryMethod(factoryField, SubProcessNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Call Activity")).addStatement(getFactoryMethod(getNodeId(node), METHOD_PROCESS_ID, new StringLiteralExpr(subProcessId))).addStatement(getFactoryMethod(getNodeId(node), METHOD_PROCESS_NAME, new StringLiteralExpr(getOrDefault(node.getProcessName(), "")))).addStatement(getFactoryMethod(getNodeId(node), METHOD_PROCESS_VERSION, new StringLiteralExpr(getOrDefault(node.getProcessVersion(), "")))).addStatement(getFactoryMethod(getNodeId(node), METHOD_WAIT_FOR_COMPLETION, new BooleanLiteralExpr(node.isWaitForCompletion()))).addStatement(getFactoryMethod(getNodeId(node), METHOD_INDEPENDENT, new BooleanLiteralExpr(node.isIndependent())));
Map<String, String> inputTypes = (Map<String, String>) node.getMetaData("BPMN.InputTypes");
String subProcessModelClassName = ProcessToExecModelGenerator.extractModelClassName(subProcessId, subProcessVersion);
ModelMetaData subProcessModel = new ModelMetaData(process.getType(), subProcessId, subProcessVersion, metadata.getPackageName(), subProcessModelClassName, WorkflowProcess.PRIVATE_VISIBILITY, VariableDeclarations.ofRawInfo(inputTypes), false, "Data model for " + name, "A complete data model for " + name);
retValue.ifPresent(retValueExpression -> {
retValueExpression.findAll(ClassOrInterfaceType.class).stream().filter(t -> t.getNameAsString().equals("$Type$")).forEach(t -> t.setName(subProcessModelClassName));
retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("bind")).ifPresent(m -> m.setBody(bind(variableScope, node, subProcessModel)));
retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("createInstance")).ifPresent(m -> m.setBody(createInstance(node, metadata)));
retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("unbind")).ifPresent(m -> m.setBody(unbind(variableScope, node)));
retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("abortInstance")).ifPresent(m -> m.setBody(abortInstance(node, metadata)));
});
if (retValue.isPresent()) {
body.addStatement(getFactoryMethod(getNodeId(node), getNodeKey(), retValue.get()));
} else {
body.addStatement(getFactoryMethod(getNodeId(node), getNodeKey()));
}
visitMetaData(node.getMetaData(), body, getNodeId(node));
body.addStatement(getDoneMethod(getNodeId(node)));
}
Aggregations