use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.
the class SendTaskHandler method handleNode.
@SuppressWarnings("unchecked")
protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
WorkItemNode workItemNode = (WorkItemNode) node;
String messageRef = element.getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
workItemNode.getWork().setParameter("MessageType", message.getType());
}
use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.
the class TaskHandler method handleNode.
protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
dataTypeInputs.clear();
dataTypeOutputs.clear();
WorkItemNode workItemNode = (WorkItemNode) node;
String name = getTaskName(element);
Work work = new WorkImpl();
work.setName(name);
workItemNode.setWork(work);
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("ioSpecification".equals(nodeName)) {
readIoSpecification(xmlNode, dataInputs, dataOutputs, dataInputTypes);
} else if ("dataInputAssociation".equals(nodeName)) {
readDataInputAssociation(xmlNode, workItemNode, dataInputs);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, workItemNode, dataOutputs);
}
xmlNode = xmlNode.getNextSibling();
}
workItemNode.setMetaData("DataInputs", new LinkedHashMap<String, String>(dataTypeInputs));
workItemNode.setMetaData("DataOutputs", new LinkedHashMap<String, String>(dataTypeOutputs));
handleScript(workItemNode, element, "onEntry");
handleScript(workItemNode, element, "onExit");
String compensation = element.getAttribute("isForCompensation");
if (compensation != null) {
boolean isForCompensation = Boolean.parseBoolean(compensation);
if (isForCompensation) {
workItemNode.setMetaData("isForCompensation", isForCompensation);
}
}
for (Entry<String, String> entryInputTypes : dataTypeInputs.entrySet()) {
ParameterDefinition parameterDefinition = new ParameterDefinitionImpl();
parameterDefinition.setName(entryInputTypes.getKey());
parameterDefinition.setType(new ObjectDataType(constructClass(entryInputTypes.getValue()), entryInputTypes.getValue()));
work.addParameterDefinition(parameterDefinition);
}
}
use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.
the class TaskHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
Node node = (Node) parser.getCurrent();
// determine type of event definition, so the correct type of node can be
// generated
handleNode(node, element, uri, localName, parser);
org.w3c.dom.Node xmlNode = element.getFirstChild();
int uniqueIdGen = 1;
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
// create new timerNode
ForEachNode forEachNode = new ForEachNode();
forEachNode.setId(node.getId());
String uniqueId = (String) node.getMetaData().get("UniqueId");
forEachNode.setMetaData("UniqueId", uniqueId);
node.setMetaData("UniqueId", uniqueId + ":" + uniqueIdGen++);
forEachNode.addNode(node);
forEachNode.linkIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE, node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE);
forEachNode.linkOutgoingConnections(node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE, NodeImpl.CONNECTION_DEFAULT_TYPE);
forEachNode.setSequential(Boolean.parseBoolean(((Element) xmlNode).getAttribute("isSequential")));
Node orignalNode = node;
node = forEachNode;
handleForEachNode(node, element, uri, localName, parser);
// running in variable strict mode
if (orignalNode instanceof WorkItemNode) {
adjustNodeConfiguration(orignalNode, forEachNode);
}
break;
}
xmlNode = xmlNode.getNextSibling();
}
// replace node in case it's milestone
if (node instanceof WorkItemNode && ((WorkItemNode) node).getWork().getName().equals("Milestone")) {
WorkItemNode workItemNode = (WorkItemNode) node;
String milestoneCondition = (String) ((WorkItemNode) node).getWork().getParameter(CONDITION);
MilestoneNode milestoneNode = new MilestoneNode();
milestoneNode.setId(workItemNode.getId());
milestoneNode.setMetaData(workItemNode.getMetaData());
milestoneNode.setConditionExpression(milestoneCondition);
milestoneNode.setName(workItemNode.getName());
milestoneNode.setParentContainer(workItemNode.getParentContainer());
node = milestoneNode;
}
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
nodeContainer.addNode(node);
((ProcessBuildData) parser.getData()).addNode(node);
return node;
}
use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.
the class TaskHandler method readDataOutputAssociation.
protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, WorkItemNode workItemNode, 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);
// transformation.setCompiledExpression(transformer.compile(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();
}
workItemNode.addOutAssociation(new DataAssociation(sources.stream().map(source -> dataOutputs.get(source)).collect(Collectors.toList()), target, assignments, transformation));
}
use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.
the class WorkItemNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
WorkItemNode workItemNode = (WorkItemNode) node;
String type = workItemNode.getWork().getName();
if ("Manual Task".equals(type)) {
writeNode("manualTask", workItemNode, xmlDump, metaDataType);
xmlDump.append(">" + EOL);
writeExtensionElements(workItemNode, xmlDump);
endNode("manualTask", xmlDump);
return;
}
if ("Service Task".equals(type)) {
writeNode("serviceTask", workItemNode, xmlDump, metaDataType);
String impl = "Other";
if (workItemNode.getWork().getParameter("implementation") != null) {
impl = (String) workItemNode.getWork().getParameter("implementation");
}
xmlDump.append("operationRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_ServiceOperation\" implementation=\"" + impl + "\" >" + EOL);
writeExtensionElements(workItemNode, xmlDump);
xmlDump.append(" <ioSpecification>" + EOL + " <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param\" name=\"Parameter\" />" + EOL + " <dataOutput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result\" name=\"Result\" />" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</dataInputRefs>" + EOL + " </inputSet>" + EOL + " <outputSet>" + EOL + " <dataOutputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</dataOutputRefs>" + EOL + " </outputSet>" + EOL + " </ioSpecification>" + EOL);
String inMapping = workItemNode.getInMapping("Parameter");
if (inMapping != null) {
xmlDump.append(" <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(inMapping) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</targetRef>" + EOL + " </dataInputAssociation>" + EOL);
}
String outMapping = workItemNode.getOutMapping("Result");
if (outMapping != null) {
xmlDump.append(" <dataOutputAssociation>" + EOL + " <sourceRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</sourceRef>" + EOL + " <targetRef>" + XmlDumper.replaceIllegalChars(outMapping) + "</targetRef>" + EOL + " </dataOutputAssociation>" + EOL);
}
endNode("serviceTask", xmlDump);
return;
}
if ("Send Task".equals(type)) {
writeNode("sendTask", workItemNode, xmlDump, metaDataType);
xmlDump.append("messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_Message\" implementation=\"Other\" >" + EOL);
writeExtensionElements(workItemNode, xmlDump);
xmlDump.append(" <ioSpecification>" + EOL + " <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param\" name=\"Message\" />" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</dataInputRefs>" + EOL + " </inputSet>" + EOL + " <outputSet/>" + EOL + " </ioSpecification>" + EOL);
String inMapping = workItemNode.getInMapping("Message");
if (inMapping != null) {
xmlDump.append(" <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(inMapping) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</targetRef>" + EOL + " </dataInputAssociation>" + EOL);
}
endNode("sendTask", xmlDump);
return;
}
if ("Receive Task".equals(type)) {
writeNode("receiveTask", workItemNode, xmlDump, metaDataType);
String messageId = (String) workItemNode.getWork().getParameter("MessageId");
xmlDump.append("messageRef=\"" + messageId + "\" implementation=\"Other\" >" + EOL);
writeExtensionElements(workItemNode, xmlDump);
xmlDump.append(" <ioSpecification>" + EOL + " <dataOutput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result\" name=\"Message\" />" + EOL + " <inputSet/>" + EOL + " <outputSet>" + EOL + " <dataOutputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</dataOutputRefs>" + EOL + " </outputSet>" + EOL + " </ioSpecification>" + EOL);
String outMapping = workItemNode.getOutMapping("Message");
if (outMapping != null) {
xmlDump.append(" <dataOutputAssociation>" + EOL + " <sourceRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</sourceRef>" + EOL + " <targetRef>" + XmlDumper.replaceIllegalChars(outMapping) + "</targetRef>" + EOL + " </dataOutputAssociation>" + EOL);
}
endNode("receiveTask", xmlDump);
return;
}
writeNode("task", workItemNode, xmlDump, metaDataType);
Object isForCompensationObject = workItemNode.getMetaData("isForCompensation");
if (isForCompensationObject != null && ((Boolean) isForCompensationObject)) {
xmlDump.append("isForCompensation=\"true\" ");
}
xmlDump.append("tns:taskName=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" >" + EOL);
writeExtensionElements(workItemNode, xmlDump);
writeIO(workItemNode, xmlDump);
endNode("task", xmlDump);
}
Aggregations