Skip to content

Commit

Permalink
Merge pull request #189 from apromore/academic_release_bugfixes
Browse files Browse the repository at this point in the history
Academic release bugfixes
  • Loading branch information
raboczi authored Apr 9, 2019
2 parents 0ccd1e3 + 05fa110 commit 786fd5e
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 2,343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,24 @@ private void renderVersionSummary(final Listitem listItem, final VersionDetailTy
@Override
public void onEvent(Event event) throws Exception {
AnnotationsType annotation = getLastestAnnotation(data.getVersion().getAnnotations());
String nativeType = (annotation != null) ? getNativeType(annotation.getNativeType()) : getNativeType(data.getProcess().getOriginalNativeType());
String annotationName = (annotation != null) ? annotation.getAnnotationName().get(0) : null;
if (nativeType.equals("BPMN 2.0")) {
mainController.editProcess2(data.getProcess(), data.getVersion(), nativeType, annotationName,
"false", new HashSet<RequestParameterType<?>>(), false);
} else {
mainController.editProcess(data.getProcess(), data.getVersion(), nativeType, null, "false",
new HashSet<RequestParameterType<?>>());
}
/*
if (annotation != null) {
mainController.editProcess(data.getProcess(), data.getVersion(), getNativeType(annotation.getNativeType()),
annotation.getAnnotationName().get(0), "false", new HashSet<RequestParameterType<?>>());
} else {
mainController.editProcess(data.getProcess(), data.getVersion(), getNativeType(data.getProcess().getOriginalNativeType()),
null, "false", new HashSet<RequestParameterType<?>>());
}
*/
}

/* Sometimes we have merged models with no native type, we should give them a default so they can be edited. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ public interface BPMNMinerService {
String discoverBPMNModel(XLog log, boolean sortLog, boolean structProcess, int miningAlgorithm, MiningSettings params, int dependencyAlgorithm, double interruptingEventTolerance, double timerEventPercentage,
double timerEventTolerance, double multiInstancePercentage, double multiInstanceTolerance,
double noiseThreshold, List<String> listCandidates, Map<Set<String>, Set<String>> primaryKeySelections) throws Exception;

String annotateBPMNModelForBIMP(String model, XLog log) throws InterruptedException, IOException, TimeoutException;;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@

package org.apromore.service.bpmnminer.impl;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeoutException;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.stream.Collectors;
import javax.swing.UIManager;

import javax.inject.Inject;
Expand All @@ -50,7 +41,6 @@
import org.deckfour.xes.classification.XEventNameClassifier;
import org.deckfour.xes.info.XLogInfoFactory;
import org.deckfour.xes.model.XLog;
import org.deckfour.xes.out.XesXmlSerializer;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.processmining.contexts.uitopia.UIContext;
import org.processmining.contexts.uitopia.UIPluginContext;
Expand All @@ -59,7 +49,6 @@
import org.processmining.plugins.bpmn.BpmnDefinitions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import org.apromore.service.bpmnminer.BPMNMinerService;
Expand All @@ -73,16 +62,10 @@ public class BPMNMinerServiceImpl implements BPMNMinerService {
private static final Logger LOGGER = LoggerFactory.getLogger(BPMNMinerServiceImpl.class);

private final IBPStructService ibpstructService;
private final String pythonExecutable;
private final File simoScript;

@Inject
public BPMNMinerServiceImpl(final IBPStructService ibpstructService,
@Qualifier("python") final String pythonExecutable,
@Qualifier("simo") final File simoScript) {
public BPMNMinerServiceImpl(final IBPStructService ibpstructService) {
this.ibpstructService = ibpstructService;
this.pythonExecutable = pythonExecutable;
this.simoScript = simoScript;
}

@Override
Expand Down Expand Up @@ -203,58 +186,4 @@ private HashMap<Set<String>, String> generateEntitiesNames(DiscoverERmodel erMod
}
return primaryKeys_entityName;
}

@Override
public String annotateBPMNModelForBIMP(String model, XLog log) throws IOException, InterruptedException, TimeoutException {
LOGGER.info("Annotating BPMN model for BIMP, python = " + pythonExecutable);

// Data is passed to Python via scratch files
File inputLog = File.createTempFile("inputLog_", ".xes", null);
File inputModel = File.createTempFile("inputModel_", ".bpmn", null);
File outputModel = File.createTempFile("outputModel_", ".bpmn", null);

// Write the log to its scratch file
try (FileOutputStream out = new FileOutputStream(inputLog)) {
LOGGER.info("Serializing log to " + inputLog);
(new XesXmlSerializer()).serialize(log, out);
}

// Write the process model to its scratch file
try (FileWriter writer = new FileWriter(inputModel)) {
LOGGER.info("Serializing model to " + inputModel);
writer.write(model);
}

// Execute the Python script
ProcessBuilder pb = new ProcessBuilder(pythonExecutable, simoScript.getName(), inputLog.toString(), inputModel.toString(), outputModel.toString());
pb.directory(simoScript.getParentFile());
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); // gather any error messages

// Block and await Python execution
if (!p.waitFor(300, SECONDS)) {
p.destroy();
throw new TimeoutException("Timed out waiting for BIMP annotation");
}

// See if the Python script executed successfully
assert !p.isAlive();
if (p.exitValue() == 0) {
// Read the annotated process model back from the scratch file
LOGGER.info("Obtaining annotated model from " + outputModel);
model = new BufferedReader(new FileReader(outputModel)).lines().collect(Collectors.joining("\n"));

// Delete all the scratch files
outputModel.delete();
inputModel.delete();
inputLog.delete();
return model;

} else {
// Fail, hopefully with a useful diagnostic message
String message = reader.lines().collect(Collectors.joining("\n"));
throw new RuntimeException("Exited with error code " + p.exitValue() + "\n" + message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@

<aop:aspectj-autoproxy />

<bean id="python" class="java.lang.String">
<qualifier value="python"/>
<constructor-arg type="String" value="${simo.python}"/>
</bean>

<bean id="simo" class="java.io.File">
<qualifier value="simo"/>
<constructor-arg type="String" value="${simo.backend}"/>
</bean>

<!-- Other OSGi services this component consumes -->
<osgi:reference id="ibpstructService" interface="org.apromore.service.ibpstruct.IBPStructService"/>

Expand Down

This file was deleted.

Loading

0 comments on commit 786fd5e

Please sign in to comment.