use of de.hpi.bpt.scylla.model.process.node.MessageFlow in project scylla by bptlab.
the class ProcessModelParser method parse.
@Override
public ProcessModel parse(Element rootElement) throws ScyllaValidationException {
Namespace bpmnNamespace = rootElement.getNamespace();
List<Element> processElements = rootElement.getChildren("process", bpmnNamespace);
if (processElements.isEmpty()) {
throw new ScyllaValidationException("No process in file.");
}
// pool references to process models
Map<String, String> processIdToPoolName = new HashMap<String, String>();
Map<String, MessageFlow> messageFlows = new HashMap<String, MessageFlow>();
Element collaboration = rootElement.getChild("collaboration", bpmnNamespace);
if (collaboration != null) {
for (Element el : collaboration.getChildren()) {
String elementName = el.getName();
if (elementName.equals("participant")) {
if (el.getAttributeValue("processRef") != null) {
String participantName = el.getAttributeValue("name");
String processId = el.getAttributeValue("processRef");
processIdToPoolName.put(processId, participantName);
}
} else if (elementName.equals("messageFlow")) {
String id = el.getAttributeValue("id");
String sourceRef = el.getAttributeValue("sourceRef");
String targetRef = el.getAttributeValue("targetRef");
MessageFlow messageFlow = new MessageFlow(id, sourceRef, targetRef);
messageFlows.put(id, messageFlow);
} else {
DebugLogger.log("Element " + el.getName() + " of collaboration not supported.");
}
}
}
Map<String, ProcessModel> processModels = new HashMap<String, ProcessModel>();
for (Element process : processElements) {
ProcessModel processModel = parseProcess(process, bpmnNamespace, false, commonProcessElements);
String processId = processModel.getId();
if (processIdToPoolName.containsKey(processId)) {
String participant = processIdToPoolName.get(processId);
processModel.setParticipant(participant);
}
processModels.put(processId, processModel);
}
if (processModels.size() == 1) {
return processModels.values().iterator().next();
} else {
try {
Set<ProcessModel> processModelsTriggeredInCollaboration = new HashSet<ProcessModel>();
ProcessModel processModelTriggeredExternally = null;
for (String processId : processModels.keySet()) {
ProcessModel pm = processModels.get(processId);
int startNodeId = pm.getStartNode();
String identifierOfStartNode = pm.getIdentifiers().get(startNodeId);
boolean isTriggeredInCollaboration = false;
for (MessageFlow mf : messageFlows.values()) {
if (mf.getTargetRef().equals(identifierOfStartNode)) {
isTriggeredInCollaboration = true;
break;
}
}
if (isTriggeredInCollaboration) {
processModelsTriggeredInCollaboration.add(pm);
} else {
if (processModelTriggeredExternally != null) {
throw new ScyllaValidationException("BPMN file contains multiple process models that are triggered externally.");
}
processModelTriggeredExternally = pm;
}
}
processModelTriggeredExternally.setProcessModelsInCollaboration(processModelsTriggeredInCollaboration);
return processModelTriggeredExternally;
} catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
e.printStackTrace();
throw new ScyllaValidationException(e.getMessage());
}
}
}
Aggregations