From 7b4af2e24a7bfd97b24fec3153ce4ca14107af36 Mon Sep 17 00:00:00 2001
From: Andrea Burattin <andrea.burattin@gmail.com>
Date: Sat, 26 Mar 2022 10:44:37 +0100
Subject: [PATCH] Full coverage for BEvent

---
 src/main/java/beamline/events/BEvent.java     | 41 +++++++++----------
 .../java/beamline/sources/CSVLogSource.java   |  2 +-
 .../java/beamline/sources/MQTTXesSource.java  |  2 +-
 .../beamline/sources/StringTestSource.java    |  2 +-
 .../java/beamline/sources/XesLogSource.java   |  4 +-
 5 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/src/main/java/beamline/events/BEvent.java b/src/main/java/beamline/events/BEvent.java
index 1af8ae5..6cf55bb 100644
--- a/src/main/java/beamline/events/BEvent.java
+++ b/src/main/java/beamline/events/BEvent.java
@@ -31,7 +31,7 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 	
 	private Map<String, Serializable> eventAttributes;
 	private Map<String, Serializable> traceAttributes;
-	private Map<String, Serializable> logAttributes;
+	private Map<String, Serializable> processAttributes;
 
 	/**
 	 * Constructor of a new event
@@ -39,7 +39,7 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 	public BEvent() {
 		this.eventAttributes = new HashMap<>();
 		this.traceAttributes = new HashMap<>();
-		this.logAttributes = new HashMap<>();
+		this.processAttributes = new HashMap<>();
 	}
 	
 	//
@@ -59,8 +59,8 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 	 */
 	public static BEvent create(
 			String processName,
-			String activityName,
 			String caseId,
+			String activityName,
 			Date time,
 			Collection<Pair<String, String>> eventAttributes) throws EventException {
 		if (processName == null || activityName == null || caseId == null) {
@@ -96,8 +96,8 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 	 * @throws EventException this exception is thrown is incomplete information
 	 * is provided
 	 */
-	public static BEvent create(String processName, String activityName, String caseId, Date time) throws EventException {
-		return create(processName, activityName, caseId, time, null);
+	public static BEvent create(String processName, String caseId, String activityName, Date time) throws EventException {
+		return create(processName, caseId, activityName, time, null);
 	}
 	
 	/**
@@ -111,19 +111,19 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 	 * @throws EventException this exception is thrown is incomplete information
 	 * is provided
 	 */
-	public static BEvent create(String processName, String activityName, String caseId) throws EventException {
-		return create(processName, activityName, caseId, null, null);
+	public static BEvent create(String processName, String caseId, String activityName) throws EventException {
+		return create(processName, caseId, activityName, null, null);
 	}
 	
 	//
 	// Specific methods
 	//
 	public void setProcessName(String name) {
-		setLogAttribute(XConceptExtension.KEY_NAME, name);
+		setProcessAttribute(XConceptExtension.KEY_NAME, name);
 	}
 	
 	public String getProcessName() {
-		return (String) logAttributes.get(XConceptExtension.KEY_NAME);
+		return (String) processAttributes.get(XConceptExtension.KEY_NAME);
 	}
 	
 	public void setTraceName(String name) {
@@ -162,8 +162,8 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 		return traceAttributes;
 	}
 	
-	public Map<String, Serializable> getLogAttributes() {
-		return logAttributes;
+	public Map<String, Serializable> getProcessAttributes() {
+		return processAttributes;
 	}
 	
 	public void setEventAttribute(String name, Serializable value) {
@@ -182,12 +182,12 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 		setAttributeFromXAttribute(traceAttributes, name, value);
 	}
 	
-	public void setLogAttribute(String name, Serializable value) {
-		logAttributes.put(name, value);
+	public void setProcessAttribute(String name, Serializable value) {
+		processAttributes.put(name, value);
 	}
 	
-	public void setLogAttribute(String name, XAttribute value) {
-		setAttributeFromXAttribute(logAttributes, name, value);
+	public void setProcessAttribute(String name, XAttribute value) {
+		setAttributeFromXAttribute(processAttributes, name, value);
 	}
 	
 	//
@@ -196,7 +196,7 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 	
 	@Override
 	public String toString() {
-		return logAttributes.toString() + " - " + traceAttributes.toString() + " - " + eventAttributes.toString();
+		return processAttributes.toString() + " - " + traceAttributes.toString() + " - " + eventAttributes.toString();
 	}
 
 	@Override
@@ -220,8 +220,7 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 		}
 		BEvent other = (BEvent) obj;
 		return new EqualsBuilder()
-				.appendSuper(super.equals(obj))
-				.append(logAttributes, other.logAttributes)
+				.append(processAttributes, other.processAttributes)
 				.append(traceAttributes, other.traceAttributes)
 				.append(eventAttributes, other.eventAttributes)
 				.isEquals();
@@ -231,7 +230,7 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 	@Override
 	public int hashCode() {
 		return new HashCodeBuilder(17, 37)
-				.append(logAttributes)
+				.append(processAttributes)
 				.append(traceAttributes)
 				.append(eventAttributes)
 				.toHashCode();
@@ -244,14 +243,14 @@ public class BEvent implements Serializable, Comparable<BEvent> {
 	private void setAttributeFromXAttribute(Map<String, Serializable> map, String name, XAttribute value) {
 		if (value instanceof XAttributeBoolean) {
 			map.put(name, ((XAttributeBoolean) value).getValue());
+		} else if (value instanceof XAttributeTimestamp) {
+			map.put(name, ((XAttributeTimestamp) value).getValue());
 		} else if (value instanceof XAttributeContinuous) {
 			map.put(name, ((XAttributeContinuous) value).getValue());
 		} else if (value instanceof XAttributeDiscrete) {
 			map.put(name, ((XAttributeDiscrete) value).getValue());
 		} else if (value instanceof XAttributeLiteral) {
 			map.put(name, ((XAttributeLiteral) value).getValue());
-		} else if (value instanceof XAttributeTimestamp) {
-			map.put(name, ((XAttributeTimestamp) value).getValue());
 		}
 	}
 }
diff --git a/src/main/java/beamline/sources/CSVLogSource.java b/src/main/java/beamline/sources/CSVLogSource.java
index 1c46f97..4cfb0d7 100644
--- a/src/main/java/beamline/sources/CSVLogSource.java
+++ b/src/main/java/beamline/sources/CSVLogSource.java
@@ -84,7 +84,7 @@ public class CSVLogSource extends BeamlineAbstractSource {
 					attributes.add(Pair.of("attribute_" + i, line[i]));
 				}
 				synchronized (ctx.getCheckpointLock()) {
-					ctx.collect(BEvent.create(filename, line[activityNameColumn], line[caseIdColumn], null, attributes));
+					ctx.collect(BEvent.create(filename, line[caseIdColumn], line[activityNameColumn], null, attributes));
 				}
 			}
 		} catch (IOException e) {
diff --git a/src/main/java/beamline/sources/MQTTXesSource.java b/src/main/java/beamline/sources/MQTTXesSource.java
index ef820e1..6a89e8b 100644
--- a/src/main/java/beamline/sources/MQTTXesSource.java
+++ b/src/main/java/beamline/sources/MQTTXesSource.java
@@ -69,7 +69,7 @@ public class MQTTXesSource extends BeamlineAbstractSource {
 					String partBeforeActName = topic.substring(0, posLastSlash);
 					String activityName = topic.substring(posLastSlash + 1);
 					String caseId = partBeforeActName.substring(partBeforeActName.lastIndexOf("/") + 1);
-					BEvent b = BEvent.create(processName, activityName, caseId);
+					BEvent b = BEvent.create(processName, caseId, activityName);
 					buffer.add(b);
 				}
 				
diff --git a/src/main/java/beamline/sources/StringTestSource.java b/src/main/java/beamline/sources/StringTestSource.java
index 613adb6..7188161 100644
--- a/src/main/java/beamline/sources/StringTestSource.java
+++ b/src/main/java/beamline/sources/StringTestSource.java
@@ -15,7 +15,7 @@ public class StringTestSource extends BeamlineAbstractSource {
 	public void run(SourceContext<BEvent> ctx) throws Exception {
 		for (int j = 0; j < traces.length; j++) {
 			for (int i = 0; i < traces[j].length(); i++) {
-				ctx.collect(BEvent.create("test-process", traces[j].substring(i, i+1), "case-"+j));
+				ctx.collect(BEvent.create("test-process", "case-"+j, traces[j].substring(i, i+1)));
 			}
 		}
 	}
diff --git a/src/main/java/beamline/sources/XesLogSource.java b/src/main/java/beamline/sources/XesLogSource.java
index 3d6a1cf..792f347 100644
--- a/src/main/java/beamline/sources/XesLogSource.java
+++ b/src/main/java/beamline/sources/XesLogSource.java
@@ -128,13 +128,13 @@ public class XesLogSource extends BeamlineAbstractSource {
 			for (XEvent e : t) {
 				BEvent be = BEvent.create(
 					processName,
-					XConceptExtension.instance().extractName(e),
 					XConceptExtension.instance().extractName(t),
+					XConceptExtension.instance().extractName(e),
 					XTimeExtension.instance().extractTimestamp(e));
 				
 				// log attributes
 				for (Map.Entry<String, XAttribute> v : log.getAttributes().entrySet()) {
-					be.setLogAttribute(v.getKey(), v.getValue());
+					be.setProcessAttribute(v.getKey(), v.getValue());
 				}
 				
 				// trace attributes
-- 
GitLab