use of org.deckfour.xes.classification.XEventAttributeClassifier 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();
}
}
Aggregations