Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions src/main/java/de/hpi/bpt/scylla/model/process/ProcessModel.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package de.hpi.bpt.scylla.model.process;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import org.jdom2.Element;

Expand Down Expand Up @@ -122,6 +119,43 @@ public void setNodeIdInParent(Integer nodeIdInParent) {
this.nodeIdInParent = nodeIdInParent;
}

/**
* Builds a identifier of a node which is unique across all levels of a BPMN process.
*
* @param nodeId
* the identifier of the node
* @return the identifier which is unique across all levels of the BPMN process
*
* TODO This method is only used for ProcessNodeInfo; consider replacing
*/
public String getRootProcessScopeNodeId(Integer nodeId) {
String processScopeNodeId = nodeId.toString();
ProcessModel processModel = this;
while (processModel.getParent() != null) {
Integer nodeIdInParent = processModel.getNodeIdInParent();
processScopeNodeId = nodeIdInParent + "_" + processScopeNodeId;

processModel = processModel.getParent();
}
return processScopeNodeId;
}

/**
* Inverts {@link ProcessModel#getRootProcessScopeNodeId(Integer)}
* @param nodeId
* @return
*/
public String rootScopeIdToProcessElementId(String nodeId) {
List<Integer> levelIds = Arrays.stream(nodeId.split("_")).map(Integer::parseInt).collect(Collectors.toList());
ProcessModel contextModel = this;
Integer id = levelIds.remove(0);
for (Integer nextId : levelIds) {
contextModel = contextModel.getSubProcesses().get(id);
id = nextId;
}
return contextModel.getIdentifiers().get(id);
}

public ProcessModel getParent() {
return parent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void writeToLog(SimulationModel model, String outputPathWithoutExtension)
batchActivity.clusterId = clusterId;
/**Write information for all tasks inside cluster*/
for(Integer taskId : tasksOfCluster) {
BatchCSVEntry task = tasksOfProcessInstance.get(SimulationUtils.getProcessScopeNodeId(clusterSubProcess, taskId));
BatchCSVEntry task = tasksOfProcessInstance.get(clusterSubProcess.getRootProcessScopeNodeId(taskId));
if(task == null)continue; //Not all tasks are necessarily visited due to XOR-Gateways and similar
task.batchNumber = batchNumber;
task.batchType = batchType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void logBPMNEventForNonResponsiblePI(BPMNEvent event) {

String taskName = event.getDisplayName();
int nodeId = event.getNodeId();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
String source = event.getSource();

int sourceSuffix = 0;
Expand Down Expand Up @@ -142,7 +142,7 @@ private void logTaskEventForNonResponsiblePI(TaskEvent event) throws ScyllaRunti

String taskName = event.getDisplayName();
int nodeId = event.getNodeId();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
String source = event.getSource();

ProcessNodeTransitionType transition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.hpi.bpt.scylla.logger.ProcessNodeTransitionType;
import de.hpi.bpt.scylla.logger.ResourceInfo;
import de.hpi.bpt.scylla.logger.ResourceStatus;
import de.hpi.bpt.scylla.model.process.ProcessModel;
import de.hpi.bpt.scylla.plugin_type.logger.OutputLoggerPluggable;
import de.hpi.bpt.scylla.simulation.ResourceObject;
import de.hpi.bpt.scylla.simulation.SimulationModel;
Expand All @@ -33,7 +34,7 @@ public String getName() {
}

public void writeToLog(SimulationModel model, String outputPathWithoutExtension) throws IOException {

TimeUnit timeUnit = DateTimeUtils.getReferenceTimeUnit();
double totalEndTime = model.presentTime().getTimeAsDouble(timeUnit);
Map<String, Map<Integer, List<ProcessNodeInfo>>> processNodeInfos = model.getProcessNodeInfos();
Expand Down Expand Up @@ -352,8 +353,12 @@ else if (transition == ProcessNodeTransitionType.EVENT_BEGIN


Map<String, Map<String, StatisticsTaskInstanceObject>> statsPerTaskOfProcess = statsPerTask.get(processId);
ProcessModel rootProcessModel = model.getDesmojObjectsMap().get(processId).getProcessModel();
// add activities
for (String processScopeNodeId : statsPerTaskOfProcess.keySet()) {


String originalId = rootProcessModel.rootScopeIdToProcessElementId(processScopeNodeId);

long taskDuration = 0;
for (StatisticsTaskInstanceObject instance : statsPerTaskOfProcess.get(processScopeNodeId).values()) {
Expand All @@ -372,7 +377,7 @@ else if (transition == ProcessNodeTransitionType.EVENT_BEGIN
Element activity = new Element("activity");
processActivities.addContent(activity);

activity.addContent(new Element("id").setText(processScopeNodeId));
activity.addContent(new Element("id").setText(originalId));
Element activityName = new Element("name");
Element activityCost = new Element("cost");
Element activityTime = new Element("time");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void addToLog(ProcessInstance processInstance) {

SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);

ProcessNodeInfo info;
info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
Expand All @@ -53,7 +53,7 @@ public void addToLogAsCanceled(ProcessInstance processInstance) {

SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);

ProcessNodeInfo info;
info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected void addToLog(ProcessInstance processInstance) {

SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);

ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
transition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected void addToLog(ProcessInstance processInstance) {

SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);

ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
transition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected void addToLog(ProcessInstance processInstance) {

SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);

ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, getName(), timestamp, taskName, resources,
transition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected void addToLog(ProcessInstance processInstance) {

if (!alreadyCanceled(model)) {
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);

ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
transition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public static TimeInstant getTaskTerminationTime(TimeSpan timeSpan, TimeInstant
String source = event.getSource();
String taskName = event.getDisplayName();
int nodeId = event.getNodeId();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);

Set<String> resources = new HashSet<String>();
Set<ResourceObject> resourceObjects = tuple.getResourceObjects();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,6 @@ public static void sendElementNotSupportedTraceNote(SimulationModel model, Proce
model.sendTraceNote(sb.toString());
}

/**
* Builds a identifier of a node which is unique across all levels of a BPMN process.
*
* @param processModel
* the (sub-)process model
* @param nodeId
* the identifier of the node
* @return the identifier which is unique across all levels of the BPMN process
*/
public static String getProcessScopeNodeId(ProcessModel processModel, Integer nodeId) {
String processScopeNodeId = nodeId.toString();
ProcessModel parent = processModel.getParent();
while (parent != null) {
Integer nodeIdInParent = processModel.getNodeIdInParent();
processScopeNodeId = nodeIdInParent + "_" + processScopeNodeId;

parent = parent.getParent();
}
return processScopeNodeId;
}

/**
* Creates and schedules a DesmoJ event which represents a resource instance which returns from idle
* for the beginning of the next timetable item for this resource instance.
Expand Down
Loading