Skip to content
Snippets Groups Projects
Commit 3a09eae5 authored by Till Josef Brinkhus's avatar Till Josef Brinkhus
Browse files

Erste Erkennung von FLow-Zusammengehörigkeiten

parent 5cb15ed3
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,14 @@ import java.io.FileReader; ...@@ -6,8 +6,14 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.eclipse.emf.common.util.EList;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -15,43 +21,196 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -15,43 +21,196 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import de.fhmuenster.masterthesis.Testgenerator.rest.dto.BPMNFlowDTO;
import de.fhmuenster.masterthesis.Testgenerator.rest.dto.BPMNFlowSetDTO;
import de.fhmuenster.masterthesis.Testgenerator.rest.dto.FlowElementDTO;
import de.fhmuenster.masterthesis.Testgenerator.rest.mapper.ObjectMapper;
import de.fhmuenster.masterthesis.Testgenerator.rest.service.flow.FlowService;
import de.fhmuenster.masterthesis.Testgenerator.rest.service.project.Project; import de.fhmuenster.masterthesis.Testgenerator.rest.service.project.Project;
import de.fhmuenster.masterthesis.Testgenerator.rest.service.project.ProjectDirectories;
import de.fhmuenster.masterthesis.Testgenerator.rest.service.project.ProjectService; import de.fhmuenster.masterthesis.Testgenerator.rest.service.project.ProjectService;
import de.fhmuenster.masterthesis.Testgenerator.rest.service.test.TestService;
import de.fhmuenster.masterthesis.Testgenerator.utils.ProjectDirectoryUtils;
import de.fhmuenster.masterthesis.serialization.TestgeneratorDSLSerializer;
import de.fhmuenster.masterthesis.testgeneratorDSL.Flow;
import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElement;
import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElementReference;
@RestController @RestController
public class ChangeController { public class ChangeController {
private static final ObjectMapper MAPPER_FLOW = new ObjectMapper()
.withFlowConverter();
@Autowired @Autowired
private ProjectService projectService; private ProjectService projectService;
@Autowired
private FlowService flowService;
@Autowired
private TestService testService;
@RequestMapping(path = "/project/{projectId}/match", method = RequestMethod.GET) @RequestMapping(path = "/project/{projectId}/match", method = RequestMethod.GET)
public String test() { public String getNewFlows(@PathVariable(required = true) Long projectId) {
boolean success = true; boolean success = true;
// List <List<String>> newFlowsElements = new ArrayList<List<String>>();
// List <List<String>> oldFlowsElements = new ArrayList<List<String>>();
// if(success) {
// System.out.println("success"); //neue Flow ist erste Element, alte Flow zweite
// return "success"; List <List<String>> matchingFlows = new ArrayList<List<String>>();
// String[] keywords = { "Flow Flow_", "with elements", "without elements"};
// try {
// BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\tillb\\Desktop\\fe_projekt\\fe-pda-testing-tool\\OnlineSchuhDemo\\dsl_matching\\Testcollection1.bpmn-testgen"));
// String line = reader.readLine();
// while(line !=null)
// {
// for(int i = 0 ; i<keywords.length;i++){
// if(line.startsWith(keywords[i])){
// System.out.println(line);
// }
// }
// line=reader.readLine();
// }
// } catch (Exception ex) {
// System.out.println(ex.getMessage());
// }
Project projectForId = projectService.getProjectForId(projectId);
//speichern von neuen Flow Elementen aller Flows
List<Flow> newFlows = flowService.getFlows(projectForId.getProjectDirectories());
List<BPMNFlowDTO> newFlowDtos = MAPPER_FLOW.mapToList(newFlows, BPMNFlowDTO.class);
System.out.println("neu:");
//for Schleife durchläuft alle Flows
for (int i= 0; i<newFlowDtos.size(); i++) {
List<String> currentFlow = new ArrayList<String>();
currentFlow.add("Flow_"+i);
//for Schleife durchläuft alle Flow-Elemente
for(FlowElementDTO flowElement : newFlowDtos.get(i).getFlowElements()){
currentFlow.add(flowElement.getId());
}
newFlowsElements.add(currentFlow);
}
// System.out.println("new: " +newFlowsElements);
// System.out.println("old flow --------------------------------------------");
//für alte Flows
String pathOld = "C:\\Users\\tillb\\Desktop\\fe_projekt\\fe-pda-testing-tool\\OnlineSchuhDemo\\dsl_matching\\MatchingTestcollectionOld.bpmn-testgen";
List<Flow> oldFlows = flowService.getOldFlows(pathOld);
List<BPMNFlowDTO> oldFlowDtos = MAPPER_FLOW.mapToList(oldFlows, BPMNFlowDTO.class);
//for Schleife durchläuft alle alten Flows
for (int i= 0; i<oldFlowDtos.size(); i++) {
List<String> currentFlow = new ArrayList<String>();
currentFlow.add("Flow_"+i);
//for Schleife durchläuft alle Flow-Elemente
for(FlowElementDTO flowElement : oldFlowDtos.get(i).getFlowElements()){
currentFlow.add(flowElement.getId());
}
oldFlowsElements.add(currentFlow);
}
// System.out.println("old :"+ oldFlowsElements);
// System.out.println("alt:");
// for(FlowElementReference e : oldFlows.get(0).getInclElements()){
// System.out.println(e.getRef().getName());
// } // }
// else
String[] keywords = { "Flow Flow_", "with elements", "without elements"};
try {
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\tillb\\Desktop\\fe_projekt\\fe-pda-testing-tool\\OnlineSchuhDemo\\dsl_matching\\Testcollection1.bpmn-testgen"));
String line = reader.readLine();
while(line !=null)
{
for(int i = 0 ; i<keywords.length;i++){
if(line.startsWith(keywords[i])){
System.out.println(line);
}
}
line=reader.readLine();
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
matchingFlows = compareFlows(newFlowsElements, oldFlowsElements);
// System.out.println(matchingFlows);
return "false"; return "false";
} }
}
private List<List<String>> compareFlows(List<List<String>> newFlowsElements, List<List<String>> oldFlowsElements) {
List <Integer> checkedFlowsOld = new ArrayList <Integer>();
List <String> checkedElements = new ArrayList <String>();
//an Stelle [x][0] ist neuer Flow, [x][1] alter Flow, [x][2] Gemeinsamkeiten, [x][3] Unterschiede
String [][] matchingFlows = new String [newFlowsElements.size()][4];
int currentNewFlow = 0;
for (List newFlow: newFlowsElements) {
int currentOldFlow = 0;
for (List oldFlow: oldFlowsElements) {
int similarities = 0;
int differences = 0;
if(checkedFlowsOld.contains(currentOldFlow));
else {
for (Object newFlowElement: newFlow) {
if((newFlowElement.toString().contains("Flow_"+currentNewFlow)&& newFlowElement.toString().length()==6) || checkedElements.contains(newFlowElement.toString())) {}
else {
for (Object oldFlowElement: oldFlow) {
if((oldFlowElement.toString().contains("Flow_"+currentOldFlow)&& oldFlowElement.toString().length()==6) || checkedElements.contains(oldFlowElement.toString())) {}
else {
if(newFlowElement.equals(oldFlowElement)) {
similarities++;
checkedElements.add(newFlowElement.toString());
}
}
}
}
}
}
//berechnen der Elemente, die aus dem alten und neuen Flow nicht zueinander gepasst haben
differences = oldFlow.size()-similarities + newFlow.size()-similarities;
// System.out.println("Neuer Flow: "+ currentNewFlow+ " ; alter Flow: "+currentOldFlow+" ; similarities: "+similarities + " ; difference: "+ differences);
// falls aktuell übprüfte Flow alt und neu Kombination die meisten Gemeinsamkeiten haben oder noch nichts in matchingFlows gespeichert wurde
if(matchingFlows[currentNewFlow][2]==null || Integer.parseInt(matchingFlows[currentNewFlow][2])<similarities ||
(Integer.parseInt(matchingFlows[currentNewFlow][2])==similarities && Integer.parseInt(matchingFlows[currentNewFlow][3])> differences)) {
// System.out.println(currentNewFlow +" "+ currentOldFlow +" "+ similarities+ " "+ differences);
matchingFlows[currentNewFlow][0] = "Flow_"+currentNewFlow;
matchingFlows[currentNewFlow][1] = "Flow_"+currentOldFlow;
matchingFlows[currentNewFlow][2] = Integer.toString(similarities);
matchingFlows[currentNewFlow][3] = Integer.toString(differences);
// System.out.println("checked: "+checkedElements + " "+ checkedElements.size());
}
checkedElements = new ArrayList <String>();
currentOldFlow++;
}
currentNewFlow++;
}
for (int i=0; i<newFlowsElements.size();i++) {
System.out.println(matchingFlows[i][0]+" "+matchingFlows[i][1]+" "+matchingFlows[i][2]+" "+matchingFlows[i][3]);
}
return null;
}
}
\ No newline at end of file
...@@ -35,6 +35,8 @@ public class FlowService { ...@@ -35,6 +35,8 @@ public class FlowService {
} }
} catch (IOException e) { } catch (IOException e) {
// //
System.out.println(e.getMessage());
} }
throw new FlowNotFoundException(name); throw new FlowNotFoundException(name);
...@@ -42,11 +44,12 @@ public class FlowService { ...@@ -42,11 +44,12 @@ public class FlowService {
public List<Flow> getFlows(ProjectDirectories projectDirectories) { public List<Flow> getFlows(ProjectDirectories projectDirectories) {
Path testspecificationPath = ProjectDirectoryUtils.getTestspecificationPath(projectDirectories); Path testspecificationPath = ProjectDirectoryUtils.getTestspecificationPath(projectDirectories);
try { try {
TestgeneratorDSLSerializer serializer = new TestgeneratorDSLSerializer(testspecificationPath.toString()); TestgeneratorDSLSerializer serializer = new TestgeneratorDSLSerializer(testspecificationPath.toString());
List<Flow> flows = serializer.getFlows(); List<Flow> flows = serializer.getFlows();
return flows; return flows;
} catch (IOException e) { } catch (IOException e) {
// //
...@@ -55,6 +58,21 @@ public class FlowService { ...@@ -55,6 +58,21 @@ public class FlowService {
return null; return null;
} }
public List<Flow> getOldFlows(String pathOld) {
try {
TestgeneratorDSLSerializer serializer = new TestgeneratorDSLSerializer(pathOld);
List<Flow> flows = serializer.getFlows();
return flows;
} catch (IOException e) {
//
}
return null;
}
public List<ServiceTaskFlowElement> getDelegateServiceTasks(ProjectDirectories projectDirectories) { public List<ServiceTaskFlowElement> getDelegateServiceTasks(ProjectDirectories projectDirectories) {
Path testspecificationPath = ProjectDirectoryUtils.getTestspecificationPath(projectDirectories); Path testspecificationPath = ProjectDirectoryUtils.getTestspecificationPath(projectDirectories);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment