de.uni.freiburg.iig.telematik.sewol.log.LogTraceUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SEWOL Show documentation
Show all versions of SEWOL Show documentation
SEWOL provides support for the handling of workflow traces. Specifically it allows to specify the shape and content of process traces in terms of entries representing the execution of a specific workflow activity. SEWOL also allows to write these traces on disk as a log file with the help of a special file writer for process logs. Currently it supports plain text, Petrify, MXML and XES log file types. In order to specify security-related context information, SEWOL provides access control models such as access control lists (ACL) and role-based access control models (RBAC). All types of models can be conveniently edited with the help of appropriate dialogs.
package de.uni.freiburg.iig.telematik.sewol.log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import de.invation.code.toval.validate.ParameterException;
import de.invation.code.toval.validate.Validate;
public class LogTraceUtils {
private static final String traceFormat = "trace%s: %s";
public static LogTrace createTraceFromActivities(int caseNumber, String... activities) {
return createTraceFromActivities(caseNumber, LogEntry.class, activities);
}
public static LogTrace createTraceFromActivities(int caseNumber, Class entryClass, String... activities) {
return createTraceFromActivities(caseNumber, entryClass, Arrays.asList(activities));
}
public static LogTrace createTraceFromActivities(int caseNumber, List activities) {
return createTraceFromActivities(caseNumber, LogEntry.class, activities);
}
public static LogTrace createTraceFromActivities(int caseNumber, Class entryClass, List activities) {
Validate.notNegative(caseNumber);
Validate.notNull(entryClass);
try {
entryClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new ParameterException("Cannot instantiate entry class: " + entryClass.getSimpleName());
}
Validate.notNull(activities);
Validate.notEmpty(activities);
Validate.noNullElements(activities);
LogTrace result = new LogTrace<>(caseNumber);
for (String activity : activities) {
E newEntry = null;
try {
newEntry = entryClass.newInstance();
newEntry.setActivity(activity);
} catch (IllegalAccessException | InstantiationException | LockingException e) {
// Cannot happen, since we validated this before.
// Cannot happen, since we validated this before.
// Cannot happen, since the field activity is not locked.
}
result.addEntry(newEntry);
}
return result;
}
public static List> createTraceList(LogTrace... traces) {
return Arrays.asList(traces);
}
public static List> createStringRepresentation(Collection> traceList, boolean onlyDistinctSequences) {
Set> distinctSequences = new HashSet<>();
List> result = new ArrayList<>();
for (LogTrace trace : traceList) {
List activityList = trace.getActivities();
if (!onlyDistinctSequences) {
result.add(activityList);
} else {
if (distinctSequences.add(activityList)) {
result.add(activityList);
}
}
}
return result;
}
public static boolean containsTracesWithDuplicates(Collection> traceList) {
for (LogTrace trace : traceList) {
if (trace.containsDuplicateActivities()) {
return true;
}
}
return false;
}
public static void print(Collection> coll) {
if (coll == null) {
throw new NullPointerException();
}
if (coll.isEmpty()) {
return;
}
for (LogTrace t : coll) {
System.out.println(String.format(traceFormat, t.getCaseNumber(), t.getActivities()));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy