Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
NourEldin-Ali committed Jun 21, 2024
1 parent 07e7632 commit 93a52ab
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class BPMNDiscovery {
private Gateway splitGateway = null;
private Boolean isAdded = false;


public BPMNDiscovery(DependencyGraph dependenciesGraph) {
logger.info("...Creating BPMN stated");
model = BPMNModelFactory.createInstance("demo", "1.0.0", "http://org.openbpmn");
Expand Down Expand Up @@ -304,45 +303,51 @@ public void DependencyGraphToBPMN() throws BPMNModelException, CloneNotSupported
if (sourceElement.getOutgoingSequenceFlows().size() > 0) {
System.out.println(
"--- probably split ---: " + sourceElement.getId() + "->" + targetElement.getId());

BPMNElementNode precedingOfTarget = targetElement.getIngoingSequenceFlows().iterator()
.next().getSourceElement();
if (BPMNTypes.BPMN_GATEWAYS.contains(precedingOfTarget.getType())) {
System.out.println("--- probably do nothing ---");
// System.out.println(targetElement.getIngoingSequenceFlows().size());
if (targetElement.getIngoingSequenceFlows().size() > 0) {
BPMNElementNode precedingOfTarget = targetElement.getIngoingSequenceFlows().iterator()
.next().getSourceElement();
if (BPMNTypes.BPMN_GATEWAYS.contains(precedingOfTarget.getType())) {
System.out.println("--- probably do nothing ---");
// System.out.println(precedingOfTarget.getId());
Set<String> targetsElementFromBPMN = model.openDefaultProces()
.getAllSuccesssors(precedingOfTarget).stream().map(e -> e.getId())
.collect(Collectors.toSet());
// get source of element1
Set<DefaultWeightedEdge> targetsEdgeElementEdge = dependenciesGraph.dependencyGraph
.outgoingEdgesOf(sourceElement.getId());
Set<String> targetsElement = new HashSet<>();
targetsEdgeElementEdge.stream().forEach(edge -> targetsElement
.add(dependenciesGraph.dependencyGraph.getEdgeTarget(edge)));
Set<String> targetsElementFromBPMN = model.openDefaultProces()
.getAllSuccesssors(precedingOfTarget).stream().map(e -> e.getId())
.collect(Collectors.toSet());
// get source of element1
Set<DefaultWeightedEdge> targetsEdgeElementEdge = dependenciesGraph.dependencyGraph
.outgoingEdgesOf(sourceElement.getId());
Set<String> targetsElement = new HashSet<>();
targetsEdgeElementEdge.stream().forEach(edge -> targetsElement
.add(dependenciesGraph.dependencyGraph.getEdgeTarget(edge)));
// System.out.println(targetsElementFromBPMN);
// System.out.println(targetsElement);
// TODO: valide it by examples
if (targetsElement.containsAll(targetsElementFromBPMN)) {
// TODO: valide it by examples
if (targetsElement.containsAll(targetsElementFromBPMN)) {

if (!process.isPreceding(sourceElement, targetElement, targetElement)) {
System.out.println("--- error gateway---");
continue;
} else {
// call split gateway function

System.out.print("--- nothing to do ---");
System.out.println("--- PROBABLY SKIP ---");
continue;
}

if (!process.isPreceding(sourceElement, targetElement, targetElement)) {
System.out.println("--- error gateway---");
continue;
} else {
// call split gateway function

System.out.print("--- nothing to do ---");
System.out.println("--- PROBABLY SKIP ---");
continue;
System.out.println("--- split1 ---");
addSplitGateway(sourceElement, targetElement);
}

} else {
System.out.println("--- split2 ---");
// call split gateway function
System.out.println("--- split1 ---");
addSplitGateway(sourceElement, targetElement);
}

} else {
System.out.println("--- split2 ---");
System.out.println("--- split3 ---");
// call split gateway function
addSplitGateway(sourceElement, targetElement);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.openbpmn.discovery;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import org.junit.jupiter.api.Test;
import org.openbpmn.bpmn.discovery.BPMNDiscovery;
import org.openbpmn.bpmn.discovery.model.DependencyGraph;
import org.openbpmn.bpmn.exceptions.BPMNModelException;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class LogInspector {
private static Logger logger = Logger.getLogger(LogInspector.class.getName());

/**
* This test creates an empty BPMN model instance
*
* @throws BPMNModelException
* @throws CloneNotSupportedException
*/
@Test
public void loopInput() throws BPMNModelException, CloneNotSupportedException {
String path = "src/test/resources/discovery/test.bpmn";
String startEventString = "Order read";
String dependencyRelationsString = "[\"Order read -> Read order from automatic order management system\", \"Read order from automatic order management system -> Check if first product is in stock\", \"Check if first product is in stock -> Withdraw product from warehouse\", \"Check if first product is in stock -> Reorder product from wholesaler\", \"Withdraw product from warehouse -> Register ordered product in stock management system\", \"Reorder product from wholesaler -> Demand delivery delay penalty\", \"Demand delivery delay penalty -> Register ordered product in stock management system\", \"Register ordered product in stock management system -> Verify if entire order is ready for shipment\", \"Verify if entire order is ready for shipment -> Request courier\", \"Verify if entire order is ready for shipment -> Pack products\", \"Request courier -> Ship products\", \"Pack products -> Ship products\", \"Ship products -> Products shipped\", \"Demand delivery delay penalty -> Delivery delay penalty demanded\", \"Verify if entire order is ready for shipment -> Check if first product is in stock\"]";
String parallelRelationString = "[[\"Request courier\", \"Pack products\"]]";
String elementInfoString = "{\"Order read\": {\"type\": \"start\", \"participant\": \"Automatic Order Management System\"}, \"Products shipped\": {\"type\": \"end\", \"participant\": \"Courier\"}, \"Delivery delay penalty demanded\": {\"type\": \"end\", \"participant\": \"Wholesaler\"}, \"Read order from automatic order management system\": {\"type\": \"service\", \"participant\": \"Automatic Order Management System\"}, \"Check if first product is in stock\": {\"type\": \"service\", \"participant\": \"Warehouse\"}, \"Withdraw product from warehouse\": {\"type\": \"service\", \"participant\": \"Warehouse\"}, \"Reorder product from wholesaler\": {\"type\": \"service\", \"participant\": \"Wholesaler\"}, \"Demand delivery delay penalty\": {\"type\": \"service\", \"participant\": \"Wholesaler\"}, \"Register ordered product in stock management system\": {\"type\": \"service\", \"participant\": \"Stock Management System\"}, \"Verify if entire order is ready for shipment\": {\"type\": \"service\", \"participant\": \"\"}, \"Request courier\": {\"type\": \"service\", \"participant\": \"Courier\"}, \"Pack products\": {\"type\": \"service\", \"participant\": \"\"}, \"Ship products\": {\"type\": \"service\", \"participant\": \"\"}}";

List<String> startsEvents = new ArrayList<>();
startsEvents.add(startEventString);

// List<String> endEvents = stringToList(endEventsString);
// LinkedList<String> events = stringToList(dependencyRelationsString);
// Set<Set<String>> parallelRelations = transformStringToList(parallelRelationString);

Gson gson = new Gson();

// Define the type of the data structure for deserialization
Type listOfListsType = new TypeToken<Set<Set<String>>>() {
}.getType();
Type listOfStringsType = new TypeToken<List<String>>() {
}.getType();
Type listOfMapType = new TypeToken<Map<String, Map<String, String>>>() {
}.getType();
// Deserialize JSON to Java objects
List<String> events = gson.fromJson(dependencyRelationsString, listOfStringsType);
Set<Set<String>> parallelRelations = gson.fromJson(parallelRelationString, listOfListsType);
Map<String, Map<String, String>> elementsInfo = gson.fromJson(elementInfoString, listOfMapType);
List<String> endEvents = new LinkedList();
for (Map.Entry<String, Map<String, String>> entry : elementsInfo.entrySet()) {
if (entry.getValue().get("type").contentEquals("end")) {
endEvents.add(entry.getKey());
}
}
// Initialize the HashMap
Map<String, String> elementsName = new HashMap();
DependencyGraph bpmnTransformation = new DependencyGraph();
for (String dependency : events) {
// Split the dependency string into source and target
String[] parts = dependency.split("->");

// Extract source and target
String sourceId = DependencyGraph.regex(parts[0]);
String targetId = DependencyGraph.regex(parts[1]);

elementsName.put(sourceId, parts[0]);
elementsName.put(targetId, parts[1]);

bpmnTransformation.addVertex(sourceId);
bpmnTransformation.addVertex(targetId);
bpmnTransformation.addEdge(sourceId, targetId);
}
System.out.println(events);
bpmnTransformation.startActivities = startsEvents;
bpmnTransformation.endActivities = endEvents;
bpmnTransformation.parallelism = parallelRelations;
bpmnTransformation.elementInformations = elementsInfo;
bpmnTransformation.elementsName = elementsName;
bpmnTransformation.changeVertexNameToRegex();
bpmnTransformation.regexOnElementInfo();
bpmnTransformation.findAndRemoveLoops();
System.out.println(bpmnTransformation.loops);
System.out.println(bpmnTransformation.getLoops());

BPMNDiscovery bpmnDiscovery = new BPMNDiscovery(bpmnTransformation);
bpmnDiscovery.DependencyGraphToBPMN();
bpmnDiscovery.saveMode(path);

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ public class S6 {
*/
@Test
public void testInputProcess() throws BPMNModelException, CloneNotSupportedException {
String path = "src/test/resources/discovery/process_1-empty-1.bpmn";
String path = "src/test/resources/discovery/loop/s6.bpmn";
LinkedList<String> list = new LinkedList<>();
List<String> startsEvent = new ArrayList<>();
Set<Set<String>> parallelRelations = new HashSet();
DependencyGraph bpmnTransformation = new DependencyGraph();
Map<String, Map<String, String>> elementsInfo = new HashMap<>();
List<String> endEvents = new LinkedList();
Map<String,String> elementsName = new HashMap();


// start event
String startEvent = "start";
Expand All @@ -39,31 +41,27 @@ public void testInputProcess() throws BPMNModelException, CloneNotSupportedExcep
// dependencies
list.add("start->a");
list.add("a->b");
list.add("a->c");
list.add("b->c");
list.add("b->d");
list.add("b->f");
list.add("c->d");
list.add("c->f");
list.add("f->end");
list.add("d->end");
list.add("c->b");
list.add("d->b");
list.add("b->end");

// parallelism
parallelRelations.add(new HashSet<>() {
{
add("c");
add("d");
add("f");
}
});

// elements info
// start/end/human/service
Map<String, String> ele1 = new HashMap<>();
ele1.put("type", "start");
elementsInfo.put(startEvent, ele1);

Map<String, String> ele2 = new HashMap<>();
ele2.put("type", "end");
elementsInfo.put("end", ele2);
elementsInfo.put(startEvent, new HashMap<String, String>() {{ put("type", "start"); }});
elementsInfo.put("end", new HashMap<String, String>() {{ put("type", "end"); }});



// extract dependencies
for (String dependency : list) {
Expand All @@ -73,9 +71,12 @@ public void testInputProcess() throws BPMNModelException, CloneNotSupportedExcep
// Extract source and target
String sourceId = parts[0].trim();
String targetId = parts[1].trim();
elementsName.put(sourceId, parts[0]);
elementsName.put(targetId, parts[1]);
bpmnTransformation.addVertex(sourceId);
bpmnTransformation.addVertex(targetId);
bpmnTransformation.addEdge(sourceId, targetId);

}

// extract end events
Expand All @@ -88,12 +89,14 @@ public void testInputProcess() throws BPMNModelException, CloneNotSupportedExcep
bpmnTransformation.startActivities = startsEvent;
bpmnTransformation.parallelism = parallelRelations;
bpmnTransformation.elementInformations = elementsInfo;
bpmnTransformation.elementsName = elementsName;
// find loops
bpmnTransformation.findAndRemoveLoops();

BPMNDiscovery bpmnDiscovery = new BPMNDiscovery(bpmnTransformation);
bpmnDiscovery.DependencyGraphToBPMN();
bpmnDiscovery.saveMode(path);


}
}
Loading

0 comments on commit 93a52ab

Please sign in to comment.