use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method serviceNode.
public WorkItemNode serviceNode(long id, Action action, FunctionDefinition function, NodeContainer nodeContainer) {
String actionName = action.getName();
String[] operationParts = function.getOperation().split("#");
String interfaceStr = operationParts[0];
String operationStr = operationParts[1];
WorkItemNode workItemNode = new WorkItemNode();
workItemNode.setId(id);
workItemNode.setName(actionName);
workItemNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
workItemNode.setMetaData("Type", SERVICE_TASK_TYPE);
workItemNode.setMetaData("Implementation", "##WebService");
Work work = new WorkImpl();
workItemNode.setWork(work);
work.setName(SERVICE_TASK_TYPE);
work.setParameter("Interface", interfaceStr);
work.setParameter("Operation", operationStr);
work.setParameter("interfaceImplementationRef", interfaceStr);
work.setParameter("implementation", "##WebService");
JsonNode params = action.getFunctionRef().getArguments();
String inputFilter = null;
String outputFilter = null;
String scopeFilter = null;
if (action.getActionDataFilter() != null) {
inputFilter = unwrapExpression(action.getActionDataFilter().getFromStateData());
outputFilter = unwrapExpression(action.getActionDataFilter().getResults());
scopeFilter = unwrapExpression(action.getActionDataFilter().getToStateData());
}
Set<String> paramNames = new LinkedHashSet<>();
if (params != null) {
Iterator<String> it = params.fieldNames();
while (it.hasNext()) {
String name = it.next();
String value = params.get(name).toString();
work.setParameter(name, unwrapExpression(value));
paramNames.add(name);
work.addParameterDefinition(new ParameterDefinitionImpl(name, new JsonNodeDataType()));
}
} else {
work.setParameter("ParameterType", JSON_NODE);
}
Assignment assignment = new Assignment("jq", null, null);
assignment.setMetaData("Action", new TaskInputJqAssignmentAction(inputFilter, paramNames));
workItemNode.addInAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(assignment), null));
Assignment outAssignment = new Assignment("jq", null, null);
outAssignment.setMetaData("Action", new TaskOutputJqAssignmentAction(outputFilter, scopeFilter));
workItemNode.addOutAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(outAssignment), null));
nodeContainer.addNode(workItemNode);
return workItemNode;
}
use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction 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.base.instance.impl.jq.TaskOutputJqAssignmentAction in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method messageStartNode.
public StartNode messageStartNode(long id, EventDefinition eventDefinition, OnEvents onEvents, NodeContainer nodeContainer) {
StartNode startNode = new StartNode();
startNode.setId(id);
startNode.setName(eventDefinition.getName());
startNode.setMetaData(Metadata.TRIGGER_MAPPING, DEFAULT_WORKFLOW_VAR);
startNode.setMetaData(Metadata.TRIGGER_TYPE, "ConsumeMessage");
// if (ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()) != null) {
// startNode.setMetaData(Metadata.TRIGGER_CORRELATION_EXPR,
// ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()));
// }
startNode.setMetaData(Metadata.TRIGGER_REF, eventDefinition.getName());
startNode.setMetaData(Metadata.MESSAGE_TYPE, JSON_NODE);
if (eventDefinition.getCorrelation() != null && !eventDefinition.getCorrelation().isEmpty()) {
startNode.setMetaData("TriggerCorrelationExpr", "extensionAttribute(eventData, \"" + eventDefinition.getCorrelation().get(0).getContextAttributeName() + "\")");
startNode.setMetaData("acceptStartSignal", "true");
}
startNode.setMetaData(Metadata.TRIGGER_FILTER_EXPR, "hasAttributeWithValue(eventData, \"type\", \"" + eventDefinition.getType() + "\")");
EventTrigger trigger = new EventTrigger();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Message-" + eventDefinition.getName());
trigger.addEventFilter(eventFilter);
String mapping = (String) startNode.getMetaData(Metadata.TRIGGER_MAPPING);
if (mapping != null) {
trigger.addInMapping(mapping, startNode.getOutMapping(mapping));
}
startNode.addTrigger(trigger);
startNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
if (eventDefinition.getMetadata() != null) {
eventDefinition.getMetadata().forEach((k, v) -> startNode.setMetaData(k, v));
}
// 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 (onEvents.getEventDataFilter() != null) {
useData = onEvents.getEventDataFilter().isUseData();
outputFilter = unwrapExpression(onEvents.getEventDataFilter().getData());
scopeFilter = unwrapExpression(onEvents.getEventDataFilter().getToStateData());
}
if (useData) {
Assignment outAssignment = new Assignment("jq", null, null);
outAssignment.setMetaData("Action", new TaskOutputJqAssignmentAction(outputFilter, scopeFilter, true));
startNode.addOutAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(outAssignment), null));
}
nodeContainer.addNode(startNode);
return startNode;
}
use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction in project automatiko-engine by automatiko-io.
the class StartNodeVisitor method visitNode.
@Override
public void visitNode(WorkflowProcess process, String factoryField, StartNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, StartNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Start")).addStatement(getFactoryMethod(getNodeId(node), METHOD_INTERRUPTING, new BooleanLiteralExpr(node.isInterrupting())));
visitMetaData(node.getMetaData(), body, getNodeId(node));
boolean serverless = ProcessToExecModelGenerator.isServerlessWorkflow(process);
if (serverless) {
for (DataAssociation association : node.getOutAssociations()) {
if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
TaskOutputJqAssignmentAction action = (TaskOutputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
String outputFilter = action.getOutputFilterExpression();
String scopeFilter = action.getScopeFilter();
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_OUT_JQ_MAPPING, (outputFilter != null ? new StringLiteralExpr().setString(outputFilter) : new NullLiteralExpr()), (scopeFilter != null ? new StringLiteralExpr().setString(scopeFilter) : new NullLiteralExpr()), new BooleanLiteralExpr(action.isIgnoreScopeFilter())));
}
}
} else {
for (DataAssociation entry : node.getOutAssociations()) {
if (entry.getAssignments() != null && !entry.getAssignments().isEmpty()) {
Assignment assignment = entry.getAssignments().get(0);
body.addStatement(getFactoryMethod(getNodeId(node), "outMapping", new StringLiteralExpr(entry.getSources().get(0)), new NullLiteralExpr(), new StringLiteralExpr(assignment.getDialect()), new StringLiteralExpr(assignment.getFrom()), new StringLiteralExpr(assignment.getTo())));
} else {
body.addStatement(getFactoryMethod(getNodeId(node), "outMapping", new StringLiteralExpr(entry.getSources().get(0)), new StringLiteralExpr(entry.getTarget()), new NullLiteralExpr(), new NullLiteralExpr(), new NullLiteralExpr()));
}
}
}
body.addStatement(getDoneMethod(getNodeId(node)));
if (node.getTimer() != null) {
Timer timer = node.getTimer();
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_TIMER, getOrNullExpr(timer.getDelay()), getOrNullExpr(timer.getPeriod()), getOrNullExpr(timer.getDate()), new IntegerLiteralExpr(node.getTimer().getTimeType())));
} else if (node.getTriggers() != null && !node.getTriggers().isEmpty()) {
Map<String, Object> nodeMetaData = node.getMetaData();
TriggerMetaData trigger = new TriggerMetaData((String) nodeMetaData.get(TRIGGER_REF), (String) nodeMetaData.get(TRIGGER_TYPE), (String) nodeMetaData.get(MESSAGE_TYPE), (String) nodeMetaData.get(TRIGGER_MAPPING), String.valueOf(node.getId()), node.getName(), (String) nodeMetaData.get(TRIGGER_CORRELATION), (String) nodeMetaData.get(TRIGGER_CORRELATION_EXPR)).validate();
trigger.addContext(node.getMetaData());
trigger.addContext(Collections.singletonMap("_node_", node));
// mark the trigger as capable of starting new instance only if this is top level start node
if (node.getParentContainer() instanceof WorkflowProcess) {
trigger.setStart(true);
}
metadata.addTrigger(trigger);
handleTrigger(node, nodeMetaData, body, variableScope, metadata);
} else {
// since there is start node without trigger then make sure it is startable
metadata.setStartable(true);
}
}
use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction in project automatiko-engine by automatiko-io.
the class AbstractNodeVisitor method addNodeMappings.
protected void addNodeMappings(WorkflowProcess process, Mappable node, BlockStmt body, String variableName) {
boolean serverless = ProcessToExecModelGenerator.isServerlessWorkflow(process);
if (serverless) {
for (DataAssociation association : node.getInAssociations()) {
if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
TaskInputJqAssignmentAction action = (TaskInputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
String inputFilter = action.getInputFilterExpression();
Set<String> params = action.getParamNames();
List<Expression> expressions = new ArrayList<>();
expressions.add(inputFilter != null ? new StringLiteralExpr().setString(inputFilter) : new NullLiteralExpr());
for (String param : params) {
expressions.add(param != null ? new StringLiteralExpr().setString(param) : new NullLiteralExpr());
}
body.addStatement(getFactoryMethod(variableName, METHOD_IN_JQ_MAPPING, expressions.toArray(Expression[]::new)));
}
}
for (DataAssociation association : node.getOutAssociations()) {
if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
TaskOutputJqAssignmentAction action = (TaskOutputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
String outputFilter = action.getOutputFilterExpression();
String scopeFilter = action.getScopeFilter();
body.addStatement(getFactoryMethod(variableName, METHOD_OUT_JQ_MAPPING, (outputFilter != null ? new StringLiteralExpr().setString(outputFilter) : new NullLiteralExpr()), (scopeFilter != null ? new StringLiteralExpr().setString(scopeFilter) : new NullLiteralExpr()), new BooleanLiteralExpr(action.isIgnoreScopeFilter())));
}
}
} else {
for (Entry<String, String> entry : node.getInMappings().entrySet()) {
body.addStatement(getFactoryMethod(variableName, METHOD_IN_MAPPING, new StringLiteralExpr(entry.getKey()), new StringLiteralExpr(entry.getValue())));
}
for (Entry<String, String> entry : node.getOutMappings().entrySet()) {
body.addStatement(getFactoryMethod(variableName, METHOD_OUT_MAPPING, new StringLiteralExpr(entry.getKey()), new StringLiteralExpr(entry.getValue())));
}
}
}
Aggregations