use of io.automatiko.engine.workflow.process.core.node.Assignment 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.Assignment 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.Assignment 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);
}
use of io.automatiko.engine.workflow.process.core.node.Assignment in project automatiko-engine by automatiko-io.
the class MappableNodeFactory method inMappingWithJqAssignment.
default MappableNodeFactory inMappingWithJqAssignment(String inputExpression, String... params) {
Assignment assignment = new Assignment("jq", null, null);
assignment.setMetaData("Action", new TaskInputJqAssignmentAction(inputExpression, params));
getMappableNode().addInAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(assignment), null));
return this;
}
use of io.automatiko.engine.workflow.process.core.node.Assignment in project automatiko-engine by automatiko-io.
the class ScriptTaskHandler method readDataOutputAssociation.
protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, ActionNode actionNode, Map<String, String> dataOutputs) {
// sourceRef
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
List<String> sources = new ArrayList<>();
sources.add(subNode.getTextContent());
subNode = subNode.getNextSibling();
while ("sourceRef".equals(subNode.getNodeName())) {
sources.add(subNode.getTextContent());
subNode = subNode.getNextSibling();
}
// targetRef
String target = subNode.getTextContent();
// transformation
Transformation transformation = null;
subNode = subNode.getNextSibling();
if (subNode != null && "transformation".equals(subNode.getNodeName())) {
String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
String expression = subNode.getTextContent();
DataTransformer transformer = transformerRegistry.find(lang);
if (transformer == null) {
throw new IllegalArgumentException("No transformer registered for language " + lang);
}
transformation = new Transformation(lang, expression);
subNode = subNode.getNextSibling();
}
// assignments
List<Assignment> assignments = new LinkedList<Assignment>();
while (subNode != null) {
String expressionLang = ((Element) subNode).getAttribute("expressionLanguage");
if (expressionLang == null || expressionLang.trim().isEmpty()) {
expressionLang = "XPath";
}
org.w3c.dom.Node ssubNode = subNode.getFirstChild();
String from = ssubNode.getTextContent();
String to = ssubNode.getNextSibling().getTextContent();
assignments.add(new Assignment(expressionLang, from, to));
subNode = subNode.getNextSibling();
}
actionNode.addOutAssociation(new DataAssociation(sources.stream().map(source -> dataOutputs.get(source)).collect(Collectors.toList()), target, assignments, transformation));
}
Aggregations