Skip to content
Snippets Groups Projects
Commit 587489ed authored by Andrea Burattin's avatar Andrea Burattin
Browse files

Worked to remove code smells and code quality

parent 377994a5
Branches
Tags
No related merge requests found
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
......
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=11
...@@ -26,7 +26,7 @@ public class InfiniteSizeDirectlyFollowsMapper extends StreamMiningAlgorithm<Dir ...@@ -26,7 +26,7 @@ public class InfiniteSizeDirectlyFollowsMapper extends StreamMiningAlgorithm<Dir
private Map<String, BEvent> map = new HashMap<>(); private Map<String, BEvent> map = new HashMap<>();
@Override @Override
public DirectlyFollowsRelation ingest(BEvent event) throws Exception { public DirectlyFollowsRelation ingest(BEvent event) {
String caseId = event.getTraceName(); String caseId = event.getTraceName();
DirectlyFollowsRelation toRet = null; DirectlyFollowsRelation toRet = null;
......
...@@ -44,10 +44,8 @@ public abstract class StreamMiningAlgorithm<T extends Response> extends RichFlat ...@@ -44,10 +44,8 @@ public abstract class StreamMiningAlgorithm<T extends Response> extends RichFlat
* *
* @param event the new event being observed * @param event the new event being observed
* @return the result of the mining of the event * @return the result of the mining of the event
* @throws Exception general exception that can occur with the ingestion of
* the event
*/ */
public abstract T ingest(BEvent event) throws Exception; public abstract T ingest(BEvent event);
/** /**
* Returns the total number of events processed so far * Returns the total number of events processed so far
......
...@@ -4,12 +4,18 @@ import java.io.File; ...@@ -4,12 +4,18 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.SystemUtils;
import org.deckfour.xes.extension.std.XConceptExtension; import org.deckfour.xes.extension.std.XConceptExtension;
import org.deckfour.xes.extension.std.XTimeExtension; import org.deckfour.xes.extension.std.XTimeExtension;
import org.deckfour.xes.in.XMxmlGZIPParser; import org.deckfour.xes.in.XMxmlGZIPParser;
...@@ -61,9 +67,9 @@ public class XesLogSource extends BeamlineAbstractSource { ...@@ -61,9 +67,9 @@ public class XesLogSource extends BeamlineAbstractSource {
* is created * is created
*/ */
public XesLogSource(XLog log) throws IOException { public XesLogSource(XLog log) throws IOException {
File tmpFile = Files.createTempFile("file", ".xes.gz").toFile(); Path tmpFile = getTempFile();
new XesXmlGZIPSerializer().serialize(log, new FileOutputStream(tmpFile)); new XesXmlGZIPSerializer().serialize(log, new FileOutputStream(tmpFile.toFile()));
this.fileName = tmpFile.getAbsolutePath(); this.fileName = tmpFile.toFile().getAbsolutePath();
} }
@Override @Override
...@@ -148,4 +154,19 @@ public class XesLogSource extends BeamlineAbstractSource { ...@@ -148,4 +154,19 @@ public class XesLogSource extends BeamlineAbstractSource {
// sort events // sort events
Collections.sort(events); Collections.sort(events);
} }
private Path getTempFile() throws IOException {
Path p = null;
if (SystemUtils.IS_OS_UNIX) {
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------"));
p = Files.createTempFile("log", ".xes.gz", attr); // Compliant
} else {
File f = Files.createTempFile("log", ".xes.gz").toFile(); // Compliant
f.setReadable(true, true);
f.setWritable(true, true);
f.setExecutable(true, true);
p = f.toPath();
}
return p;
}
} }
...@@ -22,7 +22,7 @@ public class AlgorithmTest { ...@@ -22,7 +22,7 @@ public class AlgorithmTest {
private static final long serialVersionUID = -8445717838576941924L; private static final long serialVersionUID = -8445717838576941924L;
@Override @Override
public StringResponse ingest(BEvent event) throws Exception { public StringResponse ingest(BEvent event) {
return new StringResponse(event.getProcessName() + event.getEventName() + event.getTraceName()); return new StringResponse(event.getProcessName() + event.getEventName() + event.getTraceName());
} }
}; };
...@@ -51,7 +51,7 @@ public class AlgorithmTest { ...@@ -51,7 +51,7 @@ public class AlgorithmTest {
private static final long serialVersionUID = -8445717838576941924L; private static final long serialVersionUID = -8445717838576941924L;
@Override @Override
public StringResponse ingest(BEvent event) throws Exception { public StringResponse ingest(BEvent event) {
return new StringResponse(event.getProcessName() + event.getEventName() + event.getTraceName()); return new StringResponse(event.getProcessName() + event.getEventName() + event.getTraceName());
} }
}; };
......
...@@ -5,7 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; ...@@ -5,7 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Date; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -22,9 +22,9 @@ public class ResponsesTest { ...@@ -22,9 +22,9 @@ public class ResponsesTest {
public void response_tests() { public void response_tests() {
Response r = new Response(); Response r = new Response();
Date now = new Date(); long rand = new Random().nextLong();
r.setProcessedEvents(now.getTime()); r.setProcessedEvents(rand);
assertEquals(now, r.getProcessedEvents()); assertEquals(rand, r.getProcessedEvents());
} }
@Test @Test
......
...@@ -212,12 +212,10 @@ public class SourcesTest { ...@@ -212,12 +212,10 @@ public class SourcesTest {
java.nio.file.Files.write(tmpFile.toPath(), toWrite.getBytes(), StandardOpenOption.APPEND); java.nio.file.Files.write(tmpFile.toPath(), toWrite.getBytes(), StandardOpenOption.APPEND);
} }
}); });
// JobClient job = env.executeAsync();
env.executeAsync(); env.executeAsync();
Thread.sleep(2000); Thread.sleep(2000);
System.out.println("going");
MqttClient client = new MqttClient("tcp://localhost:9999", "clientid", new MemoryPersistence()); MqttClient client = new MqttClient("tcp://localhost:9999", "clientid", new MemoryPersistence());
client.connect(); client.connect();
publish(client, "c1", "a11"); publish(client, "c1", "a11");
...@@ -227,8 +225,6 @@ public class SourcesTest { ...@@ -227,8 +225,6 @@ public class SourcesTest {
publish(client, "c2", "a23"); publish(client, "c2", "a23");
Thread.sleep(2000); Thread.sleep(2000);
// job.cancel();
System.out.println("Done");
assertEquals( assertEquals(
"name-c1-a11/name-c2-a21/name-c2-a22/name-c1-a12/name-c2-a23/", "name-c1-a11/name-c2-a21/name-c2-a22/name-c1-a12/name-c2-a23/",
org.apache.commons.io.FileUtils.readFileToString(tmpFile, "utf-8")); org.apache.commons.io.FileUtils.readFileToString(tmpFile, "utf-8"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment