Search in sources :

Example 1 with XesXmlSerializer

use of org.deckfour.xes.out.XesXmlSerializer 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();
    }
}
Also used : ArrayList(java.util.ArrayList) XesXmlSerializer(org.deckfour.xes.out.XesXmlSerializer) XEvent(org.deckfour.xes.model.XEvent) XEventAttributeClassifier(org.deckfour.xes.classification.XEventAttributeClassifier) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ZonedDateTime(java.time.ZonedDateTime) XEventClassifier(org.deckfour.xes.classification.XEventClassifier) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) XFactory(org.deckfour.xes.factory.XFactory) ArrayList(java.util.ArrayList) List(java.util.List) XTimeExtension(org.deckfour.xes.extension.std.XTimeExtension) XAttribute(org.deckfour.xes.model.XAttribute) XLog(org.deckfour.xes.model.XLog) XAttributeMap(org.deckfour.xes.model.XAttributeMap) XOrganizationalExtension(org.deckfour.xes.extension.std.XOrganizationalExtension) XConceptExtension(org.deckfour.xes.extension.std.XConceptExtension) XExtension(org.deckfour.xes.extension.XExtension) XLifecycleExtension(org.deckfour.xes.extension.std.XLifecycleExtension) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) Date(java.util.Date) XesXmlGZIPSerializer(org.deckfour.xes.out.XesXmlGZIPSerializer) XTrace(org.deckfour.xes.model.XTrace) FileOutputStream(java.io.FileOutputStream)

Aggregations

ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)1 ProcessNodeTransitionType (de.hpi.bpt.scylla.logger.ProcessNodeTransitionType)1 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)1 FileOutputStream (java.io.FileOutputStream)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 XEventAttributeClassifier (org.deckfour.xes.classification.XEventAttributeClassifier)1 XEventClassifier (org.deckfour.xes.classification.XEventClassifier)1 XExtension (org.deckfour.xes.extension.XExtension)1 XConceptExtension (org.deckfour.xes.extension.std.XConceptExtension)1 XLifecycleExtension (org.deckfour.xes.extension.std.XLifecycleExtension)1 XOrganizationalExtension (org.deckfour.xes.extension.std.XOrganizationalExtension)1 XTimeExtension (org.deckfour.xes.extension.std.XTimeExtension)1 XFactory (org.deckfour.xes.factory.XFactory)1 XAttribute (org.deckfour.xes.model.XAttribute)1 XAttributeMap (org.deckfour.xes.model.XAttributeMap)1 XEvent (org.deckfour.xes.model.XEvent)1 XLog (org.deckfour.xes.model.XLog)1