use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method consumeEventNode.
public EventNode consumeEventNode(long id, EventDefinition eventDefinition, EventDataFilter eventDataFilter, NodeContainer nodeContainer) {
EventNode eventNode = new EventNode();
eventNode.setId(id);
eventNode.setName(eventDefinition.getName());
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Message-" + eventDefinition.getName());
eventNode.addEventFilter(eventFilter);
eventNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
eventNode.setMetaData(Metadata.TRIGGER_TYPE, "ConsumeMessage");
eventNode.setMetaData(Metadata.TRIGGER_REF, eventDefinition.getName());
eventNode.setMetaData(Metadata.EVENT_TYPE, "message");
eventNode.setMetaData(Metadata.MESSAGE_TYPE, JSON_NODE);
eventNode.setMetaData(Metadata.TRIGGER_FILTER_EXPR, "hasAttributeWithValue(eventData, \"type\", \"" + eventDefinition.getType() + "\")");
eventNode.setVariableName(DEFAULT_WORKFLOW_VAR);
if (eventDefinition.getMetadata() != null) {
eventDefinition.getMetadata().forEach((k, v) -> eventNode.setMetaData(k, v));
}
if (eventDefinition.getCorrelation() != null && !eventDefinition.getCorrelation().isEmpty()) {
eventNode.setMetaData("TriggerCorrelationExpr", "extensionAttribute(eventData, \"" + eventDefinition.getCorrelation().get(0).getContextAttributeName() + "\")");
}
// if (ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()) != null) {
// eventNode.setMetaData(Metadata.TRIGGER_CORRELATION_EXPR,
// ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()));
// }
boolean useData = true;
String outputFilter = null;
String scopeFilter = null;
if (eventDataFilter != null) {
useData = eventDataFilter.isUseData();
outputFilter = unwrapExpression(eventDataFilter.getData());
scopeFilter = unwrapExpression(eventDataFilter.getToStateData());
}
if (useData) {
Assignment outAssignment = new Assignment("jq", null, null);
outAssignment.setMetaData("Action", new TaskOutputJqAssignmentAction(outputFilter, scopeFilter, true));
eventNode.addOutAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(outAssignment), null));
}
nodeContainer.addNode(eventNode);
return eventNode;
}
use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.
the class ServiceTaskDescriptor method completeWorkItemViaHandler.
private MethodCallExpr completeWorkItemViaHandler() {
ClassOrInterfaceType errorMapper = new ClassOrInterfaceType(null, implementation.equalsIgnoreCase("##webservice") ? "io.automatiko.engine.service.rest.WebErrorMapper" : "io.automatiko.engine.workflow.ErrorMapper");
Expression name = null;
Expression source = null;
List<DataAssociation> outAssociations = workItemNode.getOutAssociations();
if (hasReturn()) {
if (outAssociations.isEmpty()) {
name = new NullLiteralExpr();
} else {
name = new StringLiteralExpr(outAssociations.get(0).getSources().isEmpty() ? "workflowdata" : outAssociations.get(0).getSources().get(0));
}
source = new NameExpr("result");
} else if (outAssociations.isEmpty()) {
name = new NullLiteralExpr();
source = new NullLiteralExpr();
} else {
name = new StringLiteralExpr(outAssociations.get(0).getSources().isEmpty() ? "workflowdata" : outAssociations.get(0).getSources().get(0));
source = new NameExpr("result");
}
MethodCallExpr complitionHandlerCompleteMethod = new MethodCallExpr(new NameExpr("completionHandler"), "complete").addArgument(new MethodCallExpr(new NameExpr("workItem"), "getProcessId")).addArgument(name).addArgument(new NameExpr("workItem")).addArgument(new NameExpr("workItemManager")).addArgument(source).addArgument(new ObjectCreationExpr(null, errorMapper, NodeList.nodeList()));
return complitionHandlerCompleteMethod;
}
use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.
the class ActionNodeVisitor method visitNode.
@Override
public void visitNode(WorkflowProcess process, String factoryField, ActionNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, ActionNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Script"));
// if there is trigger defined on end event create TriggerMetaData for it
if (node.getMetaData(TRIGGER_REF) != null) {
LambdaExpr lambda = TriggerMetaData.buildLambdaExpr(node, metadata);
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
} else if (node.getMetaData(TRIGGER_TYPE) != null && node.getMetaData(TRIGGER_TYPE).equals("Compensation")) {
// compensation
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, new ObjectCreationExpr(null, new ClassOrInterfaceType(null, "io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction"), NodeList.nodeList(new StringLiteralExpr((String) node.getMetaData("CompensationEvent"))))));
} else if (node.getMetaData(TRIGGER_TYPE) != null && node.getMetaData(TRIGGER_TYPE).equals("Signal")) {
// throw signal
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, new ObjectCreationExpr(null, new ClassOrInterfaceType(null, "io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction"), NodeList.nodeList(new StringLiteralExpr((String) node.getMetaData("Ref")), node.getMetaData("Variable") != null ? new StringLiteralExpr((String) node.getMetaData("Variable")) : new NullLiteralExpr()))));
} else {
String consequence = getActionConsequence(node.getAction());
if (consequence == null || consequence.trim().isEmpty()) {
throw new IllegalStateException("Action node " + node.getId() + " name '" + node.getName() + "' has no action defined");
}
BlockStmt actionBody = new BlockStmt();
List<Variable> variables = variableScope.getVariables();
variables.stream().filter(v -> consequence.contains(v.getName())).map(ActionNodeVisitor::makeAssignment).forEach(actionBody::addStatement);
variables.stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(ActionNodeVisitor::makeAssignmentVersions).forEach(actionBody::addStatement);
actionBody.addStatement(new NameExpr(consequence));
LambdaExpr lambda = new // (kcontext) ->
LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
}
visitMetaData(node.getMetaData(), body, getNodeId(node));
for (DataAssociation association : node.getInAssociations()) {
}
body.addStatement(getDoneMethod(getNodeId(node)));
}
use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.
the class CompositeContextNodeInstance method processInputMappings.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void processInputMappings() {
VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
for (DataAssociation association : getCompositeContextNode().getInAssociations()) {
if (association.getTransformation() != null) {
Transformation transformation = association.getTransformation();
DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
if (transformer != null) {
Object parameterValue = transformer.transform(transformation.getCompiledExpression(), getProcessInstance().getVariables());
if (parameterValue != null) {
compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
}
}
} else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
Object parameterValue = null;
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getSources().get(0));
if (variableScopeInstance != null) {
parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
} else {
try {
ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
} catch (Throwable t) {
logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
logger.error("Continuing without setting parameter.");
}
}
if (parameterValue != null) {
compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
}
} else {
association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
}
}
}
use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.
the class CompositeContextNodeInstance method triggerCompleted.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void triggerCompleted(String outType) {
VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
for (DataAssociation association : getCompositeContextNode().getOutAssociations()) {
if (association.getTransformation() != null) {
Transformation transformation = association.getTransformation();
DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
if (transformer != null) {
Object parameterValue = transformer.transform(transformation.getCompiledExpression(), compositeVariableScopeInstance.getVariables());
if (parameterValue != null) {
getProcessInstance().setVariable(association.getTarget(), parameterValue);
}
}
} else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
Object parameterValue = null;
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getSources().get(0));
if (variableScopeInstance != null) {
parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
} else {
try {
ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
} catch (Throwable t) {
logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
logger.error("Continuing without setting parameter.");
}
}
if (parameterValue != null) {
getProcessInstance().setVariable(association.getTarget(), parameterValue);
}
} else {
association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
}
}
super.triggerCompleted(outType);
}
Aggregations