use of de.hpi.bpt.scylla.logger.ProcessNodeInfo 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.logger.ProcessNodeInfo 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.logger.ProcessNodeInfo in project scylla by bptlab.
the class BPMNEvent method addToLog.
protected void addToLog(ProcessInstance processInstance) {
long timestamp = Math.round(getModel().presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
String taskName = displayName;
Set<String> resources = new HashSet<String>();
SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
ProcessNodeInfo info;
info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_BEGIN);
model.addNodeInfo(processModel, processInstance, info);
info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_TERMINATE);
model.addNodeInfo(processModel, processInstance, info);
}
use of de.hpi.bpt.scylla.logger.ProcessNodeInfo in project scylla by bptlab.
the class ScyllaEvent method scheduleNextEvents.
public void scheduleNextEvents() throws ScyllaRuntimeException, SuspendExecution {
for (int i : nextEventMap.keySet()) {
ScyllaEvent nextEvent = nextEventMap.get(i);
SimulationModel model = (SimulationModel) nextEvent.getModel();
TimeSpan timeSpanToNextEvent = timeSpanToNextEventMap.get(i);
// if this is known as canceld don't schedule outgoing Elements of this
boolean alreadyCanceled = false;
Collection<Map<Integer, 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) {
if (task.getId().equals(nodeId) && task.getTransition().equals(ProcessNodeTransitionType.CANCEL)) {
alreadyCanceled = true;
}
}
}
if (!alreadyCanceled) {
SimulationUtils.scheduleEvent(nextEvent, timeSpanToNextEvent);
}
}
// to make sure that one will not schedule events twice
nextEventMap.clear();
timeSpanToNextEventMap.clear();
}
use of de.hpi.bpt.scylla.logger.ProcessNodeInfo in project scylla by bptlab.
the class TaskBeginEvent method addToLog.
@Override
protected void addToLog(ProcessInstance processInstance) {
long timestamp = Math.round(getModel().presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
String taskName = displayName;
Set<String> resources = new HashSet<String>();
Set<ResourceObject> resourceObjects = processInstance.getAssignedResources().get(source).getResourceObjects();
for (ResourceObject res : resourceObjects) {
String resourceName = res.getResourceType() + "_" + res.getId();
resources.add(resourceName);
}
ProcessNodeTransitionType transition = ProcessNodeTransitionType.BEGIN;
SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, transition);
model.addNodeInfo(processModel, processInstance, info);
}
Aggregations