forked from imixs/open-bpmn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add BPMN conpare (1=1) based on camunda tool - prepare all BPMN need to be tested
- Loading branch information
1 parent
9a29d61
commit 50fcfc2
Showing
33 changed files
with
5,155 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module version="4"> | ||
<component name="AdditionalModuleElements"> | ||
<content url="file://$MODULE_DIR$" dumb="true"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
</content> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/discovery/compare/BPMNComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.openbpmn.bpmn.discovery.compare; | ||
import org.camunda.bpm.model.bpmn.instance.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
public class BPMNComparator { | ||
|
||
public static boolean compareElements(List<FlowElement> elements1, List<FlowElement> elements2) { | ||
Map<String, Integer> countMap1 = createCountMap(elements1); | ||
Map<String, Integer> countMap2 = createCountMap(elements2); | ||
|
||
return countMap1.equals(countMap2); | ||
} | ||
|
||
private static Map<String, Integer> createCountMap(List<FlowElement> elements) { | ||
Map<String, Integer> countMap = new HashMap<>(); | ||
|
||
for (FlowElement element : elements) { | ||
String key = ""; | ||
if (element instanceof Task) { | ||
key = "Task:" + element.getName(); | ||
} else if (element instanceof Gateway) { | ||
key = "Gateway:" + element.getElementType().getTypeName(); | ||
} else if (element instanceof StartEvent) { | ||
key = "StartEvent:" + element.getElementType().getTypeName(); | ||
} else if (element instanceof EndEvent) { | ||
key = "EndEvent:" + element.getElementType().getTypeName(); | ||
} else if (element instanceof IntermediateThrowEvent) { | ||
key = "IntermediateEvent:" + element.getElementType().getTypeName(); | ||
} else if (element instanceof SubProcess) { | ||
key = "SubProcess:" + element.getName(); | ||
} | ||
|
||
countMap.put(key, countMap.getOrDefault(key, 0) + 1); | ||
} | ||
|
||
return countMap; | ||
} | ||
|
||
public static boolean compareFlows(List<SequenceFlow> flows1, List<SequenceFlow> flows2) { | ||
if (flows1.size() != flows2.size()) { | ||
return false; | ||
} | ||
|
||
for (SequenceFlow flow1 : flows1) { | ||
boolean matchFound = false; | ||
for (SequenceFlow flow2 : flows2) { | ||
if (flow1.getSource().getElementType().getTypeName().equals(flow2.getSource().getElementType().getTypeName()) && | ||
flow1.getTarget().getElementType().getTypeName().equals(flow2.getTarget().getElementType().getTypeName())) { | ||
matchFound = true; | ||
break; | ||
} | ||
} | ||
if (!matchFound) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
|
38 changes: 38 additions & 0 deletions
38
...n.metamodel/src/main/java/org/openbpmn/bpmn/discovery/compare/BPMNComparatorExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.openbpmn.bpmn.discovery.compare; | ||
|
||
import org.camunda.bpm.model.bpmn.BpmnModelInstance; | ||
import org.camunda.bpm.model.bpmn.instance.FlowElement; | ||
import org.camunda.bpm.model.bpmn.instance.SequenceFlow; | ||
|
||
import java.util.List; | ||
|
||
public class BPMNComparatorExecutor { | ||
public static void main(String[] args) { | ||
BPMNComparatorExecutor.execute( | ||
"C:\\Users\\AliNourEldin\\Desktop\\da-bpmn\\open-bpmn\\open-bpmn.metamodel\\src\\test\\resources\\discovery\\loop\\test.bpmn", | ||
"C:\\Users\\AliNourEldin\\Desktop\\da-bpmn\\open-bpmn\\open-bpmn.metamodel\\src\\test\\resources\\discovery\\loop\\test1.bpmn" | ||
); | ||
} | ||
public static boolean execute(String path1, String path2) { | ||
BpmnModelInstance model1 = BPMNLoader.loadBPMN(path1); | ||
BpmnModelInstance model2 = BPMNLoader.loadBPMN(path2); | ||
|
||
List<FlowElement> elements1 = BPMNExtractor.extractElements(model1); | ||
List<FlowElement> elements2 = BPMNExtractor.extractElements(model2); | ||
|
||
List<SequenceFlow> flows1 = BPMNExtractor.extractFlows(model1); | ||
List<SequenceFlow> flows2 = BPMNExtractor.extractFlows(model2); | ||
|
||
boolean areElementsEqual = BPMNComparator.compareElements(elements1, elements2); | ||
boolean areFlowsEqual = BPMNComparator.compareFlows(flows1, flows2); | ||
|
||
if (areElementsEqual && areFlowsEqual) { | ||
System.out.println("The BPMN models are equivalent."); | ||
return true; | ||
} else { | ||
System.out.println("The BPMN models are not equivalent."); | ||
return false; | ||
} | ||
} | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/discovery/compare/BPMNExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.openbpmn.bpmn.discovery.compare; | ||
|
||
import org.camunda.bpm.model.bpmn.instance.*; | ||
import java.util.*; | ||
import org.camunda.bpm.model.bpmn.BpmnModelInstance; | ||
|
||
|
||
public class BPMNExtractor { | ||
public static List<FlowElement> extractElements(BpmnModelInstance modelInstance) { | ||
Collection<FlowElement> flowElements = modelInstance.getModelElementsByType(FlowElement.class); | ||
return new ArrayList<>(flowElements); | ||
} | ||
|
||
public static List<SequenceFlow> extractFlows(BpmnModelInstance modelInstance) { | ||
return new ArrayList<>(modelInstance.getModelElementsByType(SequenceFlow.class)); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/discovery/compare/BPMNLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.openbpmn.bpmn.discovery.compare; | ||
import org.camunda.bpm.model.bpmn.Bpmn; | ||
import org.camunda.bpm.model.bpmn.BpmnModelInstance; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.NodeList; | ||
import org.w3c.dom.Element; | ||
import org.xml.sax.SAXException; | ||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.transform.Transformer; | ||
import javax.xml.transform.TransformerException; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.dom.DOMSource; | ||
import javax.xml.transform.stream.StreamResult; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class BPMNLoader { | ||
public static BpmnModelInstance loadBPMN(String filePath) { | ||
cleanBPMN(filePath); | ||
return Bpmn.readModelFromFile(new File(filePath)); | ||
} | ||
|
||
static void cleanBPMN(String path) { | ||
try { | ||
// Load the XML file | ||
File inputFile = new File(path); | ||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder dBuilder; | ||
|
||
dBuilder = dbFactory.newDocumentBuilder(); | ||
|
||
Document doc = dBuilder.parse(inputFile); | ||
doc.getDocumentElement().normalize(); | ||
|
||
// Get all elements with the expand attribute | ||
NodeList nodeList = doc.getElementsByTagName("*"); | ||
for (int i = 0; i < nodeList.getLength(); i++) { | ||
Element element = (Element) nodeList.item(i); | ||
if (element.hasAttribute("expand")) { | ||
element.removeAttribute("expand"); | ||
} | ||
if (element.hasAttribute("num")) { | ||
element.removeAttribute("num"); | ||
} | ||
} | ||
|
||
// Save the modified XML to a new file | ||
TransformerFactory transformerFactory = TransformerFactory.newInstance(); | ||
Transformer transformer = transformerFactory.newTransformer(); | ||
DOMSource source = new DOMSource(doc); | ||
StreamResult result = new StreamResult(new File(path)); | ||
transformer.transform(source, result); | ||
|
||
} catch (ParserConfigurationException | SAXException | IOException | TransformerException e) { | ||
System.out.println(path); | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
Oops, something went wrong.