use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException 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());
}
}
}
use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException in project scylla by bptlab.
the class BatchClusterStartEvent method eventRoutine.
@Override
public void eventRoutine(BatchCluster cluster) throws SuspendExecution {
BatchActivity activity = cluster.getBatchActivity();
int nodeId = activity.getNodeId();
List<TaskBeginEvent> parentalStartEvents = cluster.getParentalStartEvents();
// Schedule all task begin events of the process instance
for (TaskBeginEvent pse : parentalStartEvents) {
ProcessInstance pi = pse.getProcessInstance();
pse.schedule(pi);
}
// schedule subprocess start events for all process instances in parent
// processInstances and parentalStartEvents are ordered the same way
// Set the responsible process instance in the batch cluster, first one by default
cluster.setResponsibleProcessInstance(parentalStartEvents.get(0).getProcessInstance());
// Go through all process instances. If it's the first one, schedule it. If not, save it to be scheduled later on
for (int j = 0; j < parentalStartEvents.size(); j++) {
TaskBeginEvent startEvent = parentalStartEvents.get(j);
ProcessInstance responsibleProcessInstance = startEvent.getProcessInstance();
int processInstanceId = responsibleProcessInstance.getId();
boolean showInTrace = responsibleProcessInstance.traceIsOn();
SimulationModel model = (SimulationModel) responsibleProcessInstance.getModel();
String source = startEvent.getSource();
TimeInstant currentSimulationTime = cluster.presentTime();
ProcessSimulationComponents pSimComponentsOfSubprocess = cluster.getProcessSimulationComponents().getChildren().get(nodeId);
ProcessModel subprocess = pSimComponentsOfSubprocess.getProcessModel();
try {
Integer startNodeId = subprocess.getStartNode();
ProcessInstance subprocessInstance = new ProcessInstance(model, subprocess, processInstanceId, showInTrace);
subprocessInstance.setParent(responsibleProcessInstance);
ScyllaEvent subprocessEvent = new BPMNStartEvent(model, source, currentSimulationTime, pSimComponentsOfSubprocess, subprocessInstance, startNodeId);
System.out.println("Created BPMNStartEvent for PI " + subprocessInstance.getId() + " / " + responsibleProcessInstance.getId() + " in Batch Cluster");
if (j == 0) {
// If it is the first process instance, schedule it...
subprocessEvent.schedule(subprocessInstance);
cluster.setStartNodeId(startNodeId);
} else {
// ...if not, save them for later
cluster.addPIEvent(startNodeId, subprocessEvent, subprocessInstance);
}
} catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
DebugLogger.log("Start node of process model " + subprocess.getId() + " not found.");
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, responsibleProcessInstance, nodeId, traceIsOn());
return;
}
}
// move batch cluster from list of not started ones to running ones
BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
pluginInstance.setClusterToRunning(cluster);
// next node and timespan to next event determined by responsible process instance
// tasks resources only assigned to responsible subprocess instance
// only responsible subprocess instance is simulated
// other subprocess instances of batch are covered in process logs
}
use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException in project scylla by bptlab.
the class DataObjectTaskTerminate method eventRoutine.
@SuppressWarnings("unchecked")
@Override
public /* collect all fields of all dataobjects and simulate them with the given desmoj distribution. After that, pass them to the XES Logger */
void eventRoutine(TaskTerminateEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
// int processInstanceId = processInstance.getId();
try {
if (processModel.getDataObjectsGraph().getNodes().containsKey(desmojEvent.getNodeId())) {
Set<Integer> refferingObjects = processModel.getDataObjectsGraph().getTargetObjects(desmojEvent.getNodeId());
Collection<Object> allFields = desmojEvent.getDesmojObjects().getExtensionDistributions().get("dataobject").values();
for (Object fields : allFields) {
Integer i = 0;
while (((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray().length - i != 0) {
DataObjectField field = (DataObjectField) ((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray()[i];
if (refferingObjects.contains(field.getNodeId())) {
// System.out.println(processInstance.getId() + " " + desmojEvent.getDisplayName() + " " + processModel.getDisplayNames().get(field.getNodeId()) + " " + field.getDataDistributionWrapper().getSample());
SimulationModel model = (SimulationModel) desmojEvent.getModel();
Collection<Map<Integer, java.util.List<ProcessNodeInfo>>> allProcesses = model.getProcessNodeInfos().values();
for (Map<Integer, java.util.List<ProcessNodeInfo>> process : allProcesses) {
List<ProcessNodeInfo> currentProcess = process.get(processInstance.getId());
for (ProcessNodeInfo task : currentProcess) {
// System.out.println(processModel.getDisplayNames().get(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[0]) + " " + task.getTaskName());
for (Integer j = 0; j < processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray().length; j++) {
if (task.getId().equals(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[j]) && task.getTransition() == ProcessNodeTransitionType.TERMINATE) {
// check all tasks and find the ones that may be looged; already logged ones will get ignored next line
if (!task.getDataObjectField().containsKey(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName())) {
// don't log if task already has this field logged
Map<String, Object> fieldSample = new HashMap<String, Object>();
Object currentSample = field.getDataDistributionWrapper().getSample();
// log Value at TaskTerminate
fieldSample.put(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName(), currentSample);
task.SetDataObjectField(fieldSample);
// set current DataObjectFieldValue
DataObjectField.addDataObjectValue(processInstance.getId(), fieldSample.keySet().toArray()[0].toString(), currentSample);
}
}
}
}
}
}
i++;
}
}
} else {
// do nothing and continue with the next task because Node has no dataobejcts
}
} catch (ScyllaRuntimeException | ScyllaValidationException | NodeNotFoundException e) {
e.printStackTrace();
}
}
use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException in project scylla by bptlab.
the class ExclusiveGatewayEventPlugin method eventRoutine.
@SuppressWarnings("unchecked")
@Override
public void eventRoutine(GatewayEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
boolean showInTrace = desmojEvent.traceIsOn();
GatewayType type = processModel.getGateways().get(nodeId);
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
try {
Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
if (idsOfNextNodes.size() > 1) {
// split
if (type == GatewayType.DEFAULT || type == GatewayType.EXCLUSIVE) {
Map<Integer, Object> branchingDistributions = desmojObjects.getExtensionDistributions().get(getName());
DiscreteDistEmpirical<Integer> distribution = (DiscreteDistEmpirical<Integer>) branchingDistributions.get(nodeId);
// decide on next node
if (distribution != null) {
// if a distribution is given take this
Integer nextFlowId = distribution.sample().intValue();
if (!processModel.getIdentifiers().keySet().contains(nextFlowId)) {
throw new ScyllaValidationException("Flow with id " + nextFlowId + " does not exist.");
}
scheduleNextEvent(desmojEvent, processInstance, processModel, nextFlowId);
} else {
// otherwise try to get information out of the describing branches and branch on the basis of this
Map<Class<?>, ArrayList<PluginWrapper>> a = PluginLoader.getDefaultPluginLoader().getExtensions();
Collection<ArrayList<PluginWrapper>> plugins = a.values();
Boolean dataObjectPluginOn = false;
for (ArrayList<PluginWrapper> plugin : plugins) {
for (PluginWrapper p : plugin) {
if (p.toString().equals("DataObjectSCParserPlugin")) {
dataObjectPluginOn = true;
}
}
}
if (dataObjectPluginOn) {
Object[] outgoingRefs = processModel.getGraph().getTargetObjects(nodeId).toArray();
Integer DefaultPath = null;
Boolean foundAWay = false;
for (Object or : outgoingRefs) {
// go through all outgoing references
if (or.equals(getKeyByValue(processModel.getIdentifiers(), processModel.getNodeAttributes().get(desmojEvent.getNodeId()).get("default")))) {
// if it's the default path jump it
DefaultPath = (Integer) or;
continue;
}
String[] conditions = processModel.getDisplayNames().get(or).split("&&");
Integer nextFlowId = (Integer) or;
List<Boolean> test = new ArrayList<>();
for (String condition : conditions) {
condition = condition.trim();
String field = null;
String value = null;
String comparison = null;
if (condition.contains("==")) {
field = condition.split("==")[0];
value = condition.split("==")[1];
// value = processModel.getDisplayNames().get(or).substring(2, processModel.getDisplayNames().get(or).length());
comparison = "equal";
} else if (condition.contains(">=")) {
field = condition.split(">=")[0];
value = condition.split(">=")[1];
comparison = "greaterOrEqual";
} else if (condition.contains("<=")) {
field = condition.split("<=")[0];
value = condition.split("<=")[1];
comparison = "lessOrEqual";
} else if (condition.contains("!=")) {
field = condition.split("!=")[0];
value = condition.split("!=")[1];
comparison = "notEqual";
} else if (condition.contains("=")) {
field = condition.split("=")[0];
value = condition.split("=")[1];
comparison = "equal";
} else if (condition.contains("<")) {
field = condition.split("<")[0];
value = condition.split("<")[1];
comparison = "less";
} else if (condition.contains(">")) {
field = condition.split(">")[0];
value = condition.split(">")[1];
comparison = "greater";
} else {
throw new ScyllaValidationException("Condition " + condition + " does not have a comparison-operator");
}
value = value.trim();
field = field.trim();
Object fieldValue = DataObjectField.getDataObjectValue(processInstance.getId(), field);
if (!isParsableAsLong(value) || !isParsableAsLong((String.valueOf(fieldValue)))) {
// try a long comparison
Integer comparisonResult = (String.valueOf(fieldValue)).trim().compareTo(String.valueOf(value));
if (comparison.equals("equal") && comparisonResult == 0) {
break;
} else if (comparison.equals("notEqual") && comparisonResult != 0) {
break;
} else {
test.add(false);
}
} else {
// otherwise do a string compare
Long LongValue = Long.valueOf(value);
Long dOValue = Long.valueOf((String.valueOf(fieldValue)));
Integer comparisonResult = (dOValue.compareTo(LongValue));
if (comparison.equals("equal") && comparisonResult == 0) {
} else if (comparison.equals("less") && comparisonResult < 0) {
} else if (comparison.equals("greater") && comparisonResult > 0) {
} else if (comparison.equals("greaterOrEqual") && comparisonResult >= 0) {
} else if (comparison.equals("lessOrEqual") && comparisonResult <= 0) {
} else {
test.add(false);
}
}
}
if (test.size() == 0) {
scheduleNextEvent(desmojEvent, processInstance, processModel, nextFlowId);
foundAWay = true;
}
}
if (!foundAWay && DefaultPath != null) {
scheduleNextEvent(desmojEvent, processInstance, processModel, DefaultPath);
} else if (!foundAWay && DefaultPath == null) {
// everything will be killed, logical error
throw new ScyllaValidationException("No Default Path for " + desmojEvent.getDisplayName() + " given and outgoing branches not complete. No branch matches, abort.");
}
} else {
Object[] outgoingRefs = processModel.getGraph().getTargetObjects(nodeId).toArray();
Integer DefaultPath = null;
for (Object or : outgoingRefs) {
// try to find default path
if (or.equals(getKeyByValue(processModel.getIdentifiers(), processModel.getNodeAttributes().get(desmojEvent.getNodeId()).get("default")))) {
DefaultPath = (Integer) or;
break;
}
}
if (DefaultPath != null) {
scheduleNextEvent(desmojEvent, processInstance, processModel, DefaultPath);
} else {
throw new ScyllaValidationException("No Distribution for " + desmojEvent.getDisplayName() + " given, no DefaultPath given and DataObject PlugIn not activated.");
}
}
}
}
}
} catch (NodeNotFoundException | ScyllaValidationException e) {
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
return;
}
}
use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException in project scylla by bptlab.
the class ExclusiveGatewayEventPlugin method scheduleNextEvent.
private void scheduleNextEvent(GatewayEvent desmojEvent, ProcessInstance processInstance, ProcessModel processModel, Integer nextFlowId) {
Set<Integer> nodeIds = null;
try {
nodeIds = processModel.getTargetObjectIds(nextFlowId);
} catch (NodeNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (nodeIds.size() != 1) {
try {
throw new ScyllaValidationException("Flow " + nextFlowId + " does not connect to 1 node, but" + nodeIds.size() + " .");
} catch (ScyllaValidationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
int nextNodeId = nodeIds.iterator().next();
Map<Integer, ScyllaEvent> nextEventMap = desmojEvent.getNextEventMap();
List<Integer> indicesOfEventsToKeep = new ArrayList<Integer>();
for (int index : nextEventMap.keySet()) {
ScyllaEvent eventCandidate = nextEventMap.get(index);
int nodeIdOfCandidate = eventCandidate.getNodeId();
if (nodeIdOfCandidate == nextNodeId) {
indicesOfEventsToKeep.add(index);
break;
}
}
Map<Integer, TimeSpan> timeSpanToNextEventMap = desmojEvent.getTimeSpanToNextEventMap();
nextEventMap.keySet().retainAll(indicesOfEventsToKeep);
timeSpanToNextEventMap.keySet().retainAll(indicesOfEventsToKeep);
}
Aggregations