use of de.hpi.bpt.scylla.simulation.ProcessSimulationComponents in project scylla by bptlab.
the class BoundaryEventPluginUtils method initializeBoundaryObject.
// This sets all necessary values for the current boundary object and stores them in the global boundary objects map.
void initializeBoundaryObject(double beginTimeOfTask, ScyllaEvent desmojEvent, List<Integer> referenceToBoundaryEvents) {
ProcessInstance processInstance = desmojEvent.getProcessInstance();
int nodeId = desmojEvent.getNodeId();
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
String eventName = desmojEvent.getName();
String source = desmojEvent.getSource();
BoundaryObject bo = new BoundaryObject(source, beginTimeOfTask, processInstance, nodeId, desmojObjects, referenceToBoundaryEvents);
boundaryObjects.put(eventName, bo);
}
use of de.hpi.bpt.scylla.simulation.ProcessSimulationComponents 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.simulation.ProcessSimulationComponents in project scylla by bptlab.
the class XESLogger method writeToLog.
public void writeToLog(SimulationModel model, String outputPathWithoutExtension) throws IOException {
Map<String, ProcessSimulationComponents> desmojObjectsMap = model.getDesmojObjectsMap();
for (String processId : desmojObjectsMap.keySet()) {
String fileNameWithoutExtension = model.getDesmojObjectsMap().get(processId).getCommonProcessElements().getBpmnFileNameWithoutExtension();
ZonedDateTime baseDateTime = model.getStartDateTime();
Map<Integer, List<ProcessNodeInfo>> nodeInfos = model.getProcessNodeInfos().get(processId);
XFactory factory = XFactoryRegistry.instance().currentDefault();
XLog log = factory.createLog();
List<XExtension> extensions = new ArrayList<XExtension>();
XLifecycleExtension lifecycleExt = XLifecycleExtension.instance();
extensions.add(lifecycleExt);
XOrganizationalExtension organizationalExt = XOrganizationalExtension.instance();
extensions.add(organizationalExt);
XTimeExtension timeExt = XTimeExtension.instance();
extensions.add(timeExt);
XConceptExtension conceptExt = XConceptExtension.instance();
extensions.add(conceptExt);
log.getExtensions().addAll(extensions);
List<XAttribute> globalTraceAttributes = new ArrayList<XAttribute>();
globalTraceAttributes.add(XConceptExtension.ATTR_NAME);
log.getGlobalTraceAttributes().addAll(globalTraceAttributes);
List<XAttribute> globalEventAttributes = new ArrayList<XAttribute>();
globalEventAttributes.add(XConceptExtension.ATTR_NAME);
globalEventAttributes.add(XLifecycleExtension.ATTR_TRANSITION);
log.getGlobalEventAttributes().addAll(globalEventAttributes);
List<XEventClassifier> classifiers = new ArrayList<XEventClassifier>();
classifiers.add(new XEventAttributeClassifier("MXML Legacy Classifier", XConceptExtension.KEY_NAME, XLifecycleExtension.KEY_TRANSITION));
classifiers.add(new XEventAttributeClassifier("Event Name", XConceptExtension.KEY_NAME));
classifiers.add(new XEventAttributeClassifier("Resource", XOrganizationalExtension.KEY_RESOURCE));
classifiers.add(new XEventAttributeClassifier("Event Name AND Resource", XConceptExtension.KEY_NAME, XOrganizationalExtension.KEY_RESOURCE));
log.getClassifiers().addAll(classifiers);
log.getAttributes().put("source", factory.createAttributeLiteral("source", "Scylla", null));
log.getAttributes().put(XConceptExtension.KEY_NAME, factory.createAttributeLiteral(XConceptExtension.KEY_NAME, processId, conceptExt));
log.getAttributes().put("description", factory.createAttributeLiteral("description", "Log file created in Scylla", null));
log.getAttributes().put(XLifecycleExtension.KEY_MODEL, XLifecycleExtension.ATTR_MODEL);
for (Integer processInstanceId : nodeInfos.keySet()) {
XTrace trace = factory.createTrace();
trace.getAttributes().put(XConceptExtension.KEY_NAME, factory.createAttributeLiteral(XConceptExtension.KEY_NAME, processInstanceId.toString(), conceptExt));
List<ProcessNodeInfo> nodeInfoList = nodeInfos.get(processInstanceId);
for (ProcessNodeInfo info : nodeInfoList) {
XAttributeMap attributeMap = factory.createAttributeMap();
Set<String> resources = info.getResources();
for (String res : resources) {
attributeMap.put(res, factory.createAttributeLiteral(XOrganizationalExtension.KEY_RESOURCE, res, organizationalExt));
}
/* Set<String> dataObjects = info.getDataObejcts();
for (String dO : dataObjects) {
attributeMap.put(dO, factory.createAttributeLiteral(XOrganizationalExtension.KEY_RESOURCE, dO,
organizationalExt));
}*/
ZonedDateTime zonedDateTime = baseDateTime.plus(info.getTimestamp(), DateTimeUtils.getReferenceChronoUnit());
Date timestamp = new Date(zonedDateTime.toInstant().toEpochMilli());
attributeMap.put(XTimeExtension.KEY_TIMESTAMP, factory.createAttributeTimestamp(XTimeExtension.KEY_TIMESTAMP, timestamp, timeExt));
String taskName = info.getTaskName();
attributeMap.put(XConceptExtension.KEY_NAME, factory.createAttributeLiteral(XConceptExtension.KEY_NAME, taskName, conceptExt));
ProcessNodeTransitionType transition = info.getTransition();
if (transition == ProcessNodeTransitionType.BEGIN || transition == ProcessNodeTransitionType.EVENT_BEGIN) {
attributeMap.put(XLifecycleExtension.KEY_TRANSITION, factory.createAttributeLiteral(XLifecycleExtension.KEY_TRANSITION, "start", lifecycleExt));
} else if (transition == ProcessNodeTransitionType.TERMINATE || transition == ProcessNodeTransitionType.EVENT_TERMINATE) {
attributeMap.put(XLifecycleExtension.KEY_TRANSITION, factory.createAttributeLiteral(XLifecycleExtension.KEY_TRANSITION, "complete", lifecycleExt));
if (!info.getDataObjectField().isEmpty()) {
Integer size = info.getDataObjectField().size();
Object[] test = info.getDataObjectField().keySet().toArray();
Object[] test2 = info.getDataObjectField().values().toArray();
for (int i = 0; i < size; i++) {
attributeMap.put(Integer.toString(i), factory.createAttributeLiteral(Objects.toString(test[i]), Objects.toString(test2[i], null), lifecycleExt));
}
}
} else if (transition == ProcessNodeTransitionType.CANCEL) {
attributeMap.put(XLifecycleExtension.KEY_TRANSITION, factory.createAttributeLiteral(XLifecycleExtension.KEY_TRANSITION, "ate_abort", lifecycleExt));
} else if (transition == ProcessNodeTransitionType.ENABLE || transition == ProcessNodeTransitionType.PAUSE || transition == ProcessNodeTransitionType.RESUME) {
continue;
} else {
System.out.println("Transition type " + transition + " not supported in XESLogger.");
}
XEvent event = factory.createEvent(attributeMap);
trace.add(event);
}
log.add(trace);
}
XesXmlSerializer serializer;
FileOutputStream fos;
if (gzipOn) {
serializer = new XesXmlGZIPSerializer();
fos = new FileOutputStream(outputPathWithoutExtension + fileNameWithoutExtension + ".tar");
} else {
serializer = new XesXmlSerializer();
fos = new FileOutputStream(outputPathWithoutExtension + fileNameWithoutExtension + ".xes");
}
;
serializer.serialize(log, fos);
fos.close();
}
}
use of de.hpi.bpt.scylla.simulation.ProcessSimulationComponents in project scylla by bptlab.
the class BPMNEscalationBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
boolean showInTrace = model.traceIsOn();
try {
for (EventDefinitionType definition : definitions.keySet()) {
if (definition == EventDefinitionType.ESCALATION) {
if (processModel.getParent() != null) {
Map<String, String> eventAttributes = processModel.getEventDefinitions().get(nodeId).get(definition);
String escalationRef = eventAttributes.get("escalationRef");
// Map<String, Map<String, String>> escalations =
// model.getCommonProcessElements().getEscalations();
// Map<String, String> escalation = escalations.get("escalationRef");
ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
ProcessModel parentModel = processModel.getParent();
int nodeIdInParent = processModel.getNodeIdInParent();
Integer nextNodeId = null;
// find boundary event of parentModel which has the same escalationRef
List<Integer> referencesToBoundaryEvents = parentModel.getReferencesToBoundaryEvents().get(nodeIdInParent);
for (int nId : referencesToBoundaryEvents) {
Map<EventDefinitionType, Map<String, String>> boundaryEventDefinitions = parentModel.getEventDefinitions().get(nId);
Map<String, String> boundaryEscalationEventDefinition = boundaryEventDefinitions.get(EventDefinitionType.ESCALATION);
if (boundaryEscalationEventDefinition != null) {
if (escalationRef.equals(boundaryEscalationEventDefinition.get("escalationRef"))) {
nextNodeId = nId;
break;
}
}
}
if (nextNodeId == null) {
DebugLogger.error("Could not find referenced escalation " + escalationRef + ".");
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
return;
}
ProcessInstance parentProcessInstance = processInstance.getParent();
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
TimeSpan timeSpan = new TimeSpan(0);
/**
* first event in the map is the node that comes after the subprocess when normal behavior
* applies, so remove it;
*/
int indexOfTaskTerminateEvent = 0;
desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
for (ScyllaEvent event : events) {
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, event);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
processInstance.cancel();
}
}
}
} catch (NodeNotFoundException | ScyllaValidationException e) {
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
}
}
use of de.hpi.bpt.scylla.simulation.ProcessSimulationComponents in project scylla by bptlab.
the class BPMNTimerPIGEPlugin method eventRoutine.
@Override
public void eventRoutine(ProcessInstanceGenerationEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
String processId = desmojEvent.getProcessId();
ProcessSimulationComponents desmojObjects = model.getDesmojObjectsMap().get(processId);
ProcessModel processModel = desmojObjects.getProcessModel();
Integer startNodeId;
try {
startNodeId = processModel.getStartNode();
if (desmojObjects.getDistributions().get(startNodeId) == null) {
// no arrival rate defined, check if start event is timer event and use value from there
Map<EventDefinitionType, Map<String, String>> eventDefinitions = processModel.getEventDefinitions().get(startNodeId);
Map<String, String> definitionAttributes = eventDefinitions.get(EventDefinitionType.TIMER);
if (definitionAttributes != null) {
// if start event is timer event
// ISO 8601 duration
String timeDuration = definitionAttributes.get("timeCycle");
if (timeDuration == null) {
String identifier = processModel.getIdentifiers().get(startNodeId);
DebugLogger.log("Timer event " + identifier + " has no timer definition, skip.");
} else // TODO support timeDate and timeDuration attributes?
{
Duration javaDuration = Duration.parse(timeDuration);
long duration = javaDuration.get(ChronoUnit.SECONDS);
TimeUnit unit = TimeUnit.SECONDS;
TimeSpan timeSpan = new TimeSpan(duration, unit);
desmojEvent.setTimeSpanToNextProcessInstance(timeSpan);
}
}
}
} catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
DebugLogger.error(e.getMessage());
DebugLogger.log("Error during instantiation of process model " + processModel.getId() + ".");
}
}
Aggregations