Search in sources :

Example 1 with ProcessNodeInfo

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();
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 2 with ProcessNodeInfo

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();
    }
}
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)

Example 3 with ProcessNodeInfo

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);
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 4 with ProcessNodeInfo

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();
}
Also used : ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) TimeSpan(desmoj.core.simulator.TimeSpan) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 5 with ProcessNodeInfo

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);
}
Also used : ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Aggregations

ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)17 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)13 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)13 ProcessNodeTransitionType (de.hpi.bpt.scylla.logger.ProcessNodeTransitionType)9 ResourceObject (de.hpi.bpt.scylla.simulation.ResourceObject)7 HashSet (java.util.HashSet)6 List (java.util.List)6 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)3 ResourceInfo (de.hpi.bpt.scylla.logger.ResourceInfo)3 ResourceStatus (de.hpi.bpt.scylla.logger.ResourceStatus)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)3 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)3 TimeInstant (desmoj.core.simulator.TimeInstant)3 FileOutputStream (java.io.FileOutputStream)3 ZonedDateTime (java.time.ZonedDateTime)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2