use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project automatiko-engine by automatiko-io.
the class DataStoreHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
DataStore store = new DataStore();
store.setId(attrs.getValue("id"));
store.setName(attrs.getValue("name"));
final String itemSubjectRef = attrs.getValue("itemSubjectRef");
store.setItemSubjectRef(itemSubjectRef);
Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
// retrieve type from item definition
// FIXME we bypass namespace resolving here. That's not a good idea when we
// start having several documents, with imports.
String localItemSubjectRef = itemSubjectRef.substring(itemSubjectRef.indexOf(":") + 1);
DataType dataType = new ObjectDataType();
if (itemDefinitions != null) {
ItemDefinition itemDefinition = itemDefinitions.get(localItemSubjectRef);
if (itemDefinition != null) {
dataType = new ObjectDataType(constructClass(itemDefinition.getStructureRef(), parser.getClassLoader()), itemDefinition.getStructureRef());
}
}
store.setType(dataType);
Definitions parent = (Definitions) parser.getParent();
List<DataStore> dataStores = parent.getDataStores();
if (dataStores == null) {
dataStores = new ArrayList<DataStore>();
parent.setDataStores(dataStores);
}
dataStores.add(store);
return store;
}
use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project automatiko-engine by automatiko-io.
the class AbstractNodeHandler method getErrorIdForErrorCode.
protected String getErrorIdForErrorCode(String errorCode, Node node) {
io.automatiko.engine.api.definition.process.NodeContainer parent = node.getParentContainer();
while (!(parent instanceof ExecutableProcess) && parent instanceof Node) {
parent = ((Node) parent).getParentContainer();
}
if (!(parent instanceof ExecutableProcess)) {
throw new RuntimeException("This should never happen: !(parent instanceof RuleFlowProcess): parent is " + parent.getClass().getSimpleName());
}
List<Error> errors = ((Definitions) ((ExecutableProcess) parent).getMetaData("Definitions")).getErrors();
Error error = null;
for (Error listError : errors) {
if (errorCode.equals(listError.getErrorCode())) {
error = listError;
break;
} else if (errorCode.equals(listError.getId())) {
error = listError;
break;
}
}
if (error == null) {
throw new IllegalArgumentException("Could not find error with errorCode " + errorCode);
}
return error.getId();
}
use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project automatiko-engine by automatiko-io.
the class ProcessHandler method end.
@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
parser.endElementBuilder();
ExecutableProcess process = (ExecutableProcess) parser.getCurrent();
List<IntermediateLink> throwLinks = (List<IntermediateLink>) process.getMetaData(LINKS);
linkIntermediateLinks(process, throwLinks);
List<SequenceFlow> connections = (List<SequenceFlow>) process.getMetaData(CONNECTIONS);
linkConnections(process, connections);
linkBoundaryEvents(process);
// This must be done *after* linkConnections(process, connections)
// because it adds hidden connections for compensations
List<Association> associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
linkAssociations((Definitions) process.getMetaData("Definitions"), process, associations);
List<Lane> lanes = (List<Lane>) process.getMetaData(LaneHandler.LANES);
assignLanes(process, lanes);
postProcessNodes(process, process);
// process tags if any defined
processTags(process);
return process;
}
use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project automatiko-engine by automatiko-io.
the class StartEventHandler method handleNode.
@Override
@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);
StartNode startNode = (StartNode) node;
// TODO: StartEventHandler.handleNode(): the parser doesn't discriminate between
// the schema default and the actual set value
// However, while the schema says the "isInterrupting" attr should default to
// true
// The spec says that Escalation start events should default to not
// interrupting..
startNode.setInterrupting(Boolean.parseBoolean(element.getAttribute("isInterrupting")));
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataOutput".equals(nodeName)) {
readDataOutput(xmlNode, parser);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, startNode);
} else if ("outputSet".equals(nodeName)) {
// p. 225, BPMN2 spec (2011-01-03)
// InputSet and OutputSet elements imply that process execution should wait for
// them to be filled
// and are therefore not applicable to catch events
String message = "Ignoring <" + nodeName + "> element: " + "<" + nodeName + "> elements should not be used on start or other catch events.";
SAXParseException saxpe = new SAXParseException(message, parser.getLocator());
parser.warning(saxpe);
// no exception thrown for backwards compatibility (we used to ignore these
// elements)
} else if ("conditionalEventDefinition".equals(nodeName)) {
String constraint = null;
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
while (subNode != null) {
String subnodeName = subNode.getNodeName();
if ("condition".equals(subnodeName)) {
constraint = xmlNode.getTextContent();
break;
}
subNode = subNode.getNextSibling();
}
ConstraintTrigger trigger = new ConstraintTrigger();
trigger.setConstraint(constraint);
startNode.addTrigger(trigger);
startNode.setMetaData(TRIGGER_REF, "Condition-" + node.getId());
startNode.setMetaData(TRIGGER_TYPE, "Condition");
break;
} else if ("signalEventDefinition".equals(nodeName)) {
String type = ((Element) xmlNode).getAttribute("signalRef");
Signal signal = findSignalByName(parser, type);
type = checkSignalAndConvertToRealSignalNam(parser, type);
if (type != null && type.trim().length() > 0) {
addTriggerWithInMappings(startNode, type);
}
startNode.setMetaData(MESSAGE_TYPE, type);
startNode.setMetaData(TRIGGER_TYPE, "Signal");
if (signal != null) {
String eventType = signal.getStructureRef();
ProcessBuildData buildData = ((ProcessBuildData) parser.getData());
Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) buildData.getMetaData("ItemDefinitions");
if (itemDefinitions != null && itemDefinitions.containsKey(eventType)) {
startNode.setMetaData(TRIGGER_REF, itemDefinitions.get(eventType).getStructureRef());
} else {
startNode.setMetaData(TRIGGER_REF, type);
}
} else {
startNode.setMetaData(TRIGGER_REF, type);
}
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).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);
}
startNode.setMetaData(MESSAGE_TYPE, message.getType());
startNode.setMetaData(TRIGGER_TYPE, "ConsumeMessage");
startNode.setMetaData(TRIGGER_REF, message.getName());
startNode.setMetaData(TRIGGER_CORRELATION, message.getCorrelation());
startNode.setMetaData(TRIGGER_CORRELATION_EXPR, message.getCorrelationExpression());
for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
startNode.setMetaData(entry.getKey(), entry.getValue());
}
addTriggerWithInMappings(startNode, "Message-" + message.getName());
} else if ("timerEventDefinition".equals(nodeName)) {
handleTimerNode(startNode, element, uri, localName, parser);
startNode.setMetaData(TRIGGER_TYPE, "Timer");
// following event definitions are only for event sub process and will be
// validated to not be included in top process definitions
} else if ("errorEventDefinition".equals(nodeName)) {
if (!startNode.isInterrupting()) {
// BPMN2 spec (p.245-246, (2011-01-03)) implies that
// - a <startEvent> in an Event Sub-Process
// - *without* the 'isInterupting' attribute always interrupts (containing
// process)
String errorMsg = "Error Start Events in an Event Sub-Process always interrupt the containing (sub)process(es).";
throw new IllegalArgumentException(errorMsg);
}
String errorRef = ((Element) xmlNode).getAttribute("errorRef");
if (errorRef != null && errorRef.trim().length() > 0) {
List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
if (errors == null) {
throw new IllegalArgumentException("No errors found");
}
Error error = null;
for (Error listError : errors) {
if (errorRef.equals(listError.getId())) {
error = listError;
}
}
if (error == null) {
throw new IllegalArgumentException("Could not find error " + errorRef);
}
startNode.setMetaData("FaultCode", error.getErrorCode());
addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode());
startNode.setMetaData(TRIGGER_TYPE, "Error");
startNode.setMetaData(TRIGGER_REF, "Error-" + error.getErrorCode());
if (error.getMetaData().get("retry") != null) {
startNode.setMetaData("ErrorRetry", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retry"))).intValue());
if (error.getMetaData().get("retryLimit") != null) {
startNode.setMetaData("ErrorRetryLimit", Integer.parseInt((String) error.getMetaData().get("retryLimit")));
}
if (error.getMetaData().get("retryIncrement") != null) {
startNode.setMetaData("ErrorRetryIncrement", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retryIncrement"))).intValue());
}
if (error.getMetaData().get("retryMultiplier") != null) {
startNode.setMetaData("ErrorRetryIncrementMultiplier", Float.parseFloat((String) error.getMetaData().get("retryMultiplier")));
}
}
}
} else if ("escalationEventDefinition".equals(nodeName)) {
String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
if (escalationRef != null && escalationRef.trim().length() > 0) {
Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
if (escalations == null) {
throw new IllegalArgumentException("No escalations found");
}
Escalation escalation = escalations.get(escalationRef);
if (escalation == null) {
throw new IllegalArgumentException("Could not find escalation " + escalationRef);
}
addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
startNode.setMetaData(TRIGGER_TYPE, "Escalation");
}
} else if ("compensateEventDefinition".equals(nodeName)) {
handleCompensationNode(startNode, xmlNode);
}
xmlNode = xmlNode.getNextSibling();
}
node.setMetaData("DataOutputs", new LinkedHashMap<String, String>(dataOutputTypes));
}
use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project automatiko-engine by automatiko-io.
the class SubProcessHandler method handleForEachNode.
@SuppressWarnings("unchecked")
protected void handleForEachNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, boolean isAsync) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
ForEachNode forEachNode = (ForEachNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("ioSpecification".equals(nodeName)) {
readIoSpecification(xmlNode, dataInputs, dataOutputs, dataInputTypes, dataOutputTypes);
} else if ("dataInputAssociation".equals(nodeName)) {
readDataInputAssociation(xmlNode, inputAssociation);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, outputAssociation);
} else if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser);
}
xmlNode = xmlNode.getNextSibling();
}
handleScript(forEachNode, element, "onEntry");
handleScript(forEachNode, element, "onExit");
// List<SequenceFlow> connections = (List<SequenceFlow>) ((CompositeNode) node).getMetaData(ProcessHandler.CONNECTIONS);
// ProcessHandler processHandler = new ProcessHandler();
// processHandler.linkConnections((io.automatiko.engine.api.definition.process.NodeContainer) node, connections);
// processHandler.linkBoundaryEvents((io.automatiko.engine.api.definition.process.NodeContainer) node);
// This must be done *after* linkConnections(process, connections)
// because it adds hidden connections for compensations
List<Association> associations = (List<Association>) forEachNode.getMetaData(ProcessHandler.ASSOCIATIONS);
ProcessHandler.linkAssociations((Definitions) forEachNode.getMetaData("Definitions"), forEachNode, associations);
applyAsync(node, isAsync);
}
Aggregations