From 76757662104e8ead7349de8a595cbd98c422eefd Mon Sep 17 00:00:00 2001
From: Florian Lambers <fl462057@fh-muenster.de>
Date: Tue, 23 Nov 2021 12:14:05 +0100
Subject: [PATCH] updated flow matching check, refactored resultwrapper

---
 .../Testgenerator/migration/ActionType.java   |   7 +-
 .../migration/MigrationService.java           | 105 +++++++++++-------
 2 files changed, 67 insertions(+), 45 deletions(-)

diff --git a/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/migration/ActionType.java b/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/migration/ActionType.java
index 49f5a2c..6f0d223 100644
--- a/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/migration/ActionType.java
+++ b/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/migration/ActionType.java
@@ -1,6 +1,9 @@
 package de.fhmuenster.masterthesis.Testgenerator.migration;
 
 public enum ActionType {
-	ACTIVITY_ADD_MANUAL_TASK, ACTIVITY_ADD_USER_TASK, ACTIVITY_ADD_BUSINESS_RULE_TASK,
-	ACTIVITY_ADD_SCRIPT_TASK, ACTIVITY_ADD_SERVICE_TASK
+	ACTIVITY_ADD_MANUAL_TASK, ACTIVITY_ADD_USER_TASK, ACTIVITY_ADD_BUSINESS_RULE_TASK_WITH_OUTPUT,
+	ACTIVITY_ADD_BUSINESS_RULE_TASK_WITHOUT_OUTPUT, ACTIVITY_ADD_SCRIPT_TASK, ACTIVITY_ADD_SERVICE_TASK,
+	
+	ACTIVITY_DELETE_MANUAL_TASK, ACTIVITY_DELETE_USER_TASK, ACTIVITY_DELETE_BUSINESS_RULE_TASK,
+	ACTIVITY_DELETE_SCRIPT_TASK, ACTIVITY_DELETE_SERVICE_TASK
 }
diff --git a/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/migration/MigrationService.java b/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/migration/MigrationService.java
index 6170734..44556d3 100644
--- a/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/migration/MigrationService.java
+++ b/Testgenerator/src/main/java/de/fhmuenster/masterthesis/Testgenerator/migration/MigrationService.java
@@ -11,11 +11,13 @@ import org.springframework.stereotype.Service;
 
 import de.fhmuenster.masterthesis.Testgenerator.rest.dto.MigrationResultWrapperDTO;
 import de.fhmuenster.masterthesis.Testgenerator.rest.service.change.ChangeService;
+import de.fhmuenster.masterthesis.Testgenerator.yaml.MigrationResult;
 import de.fhmuenster.masterthesis.Testgenerator.yaml.MigrationResultStatus;
 import de.fhmuenster.masterthesis.Testgenerator.yaml.MigrationYaml;
 import de.fhmuenster.masterthesis.Testgenerator.yaml.YamlReader;
 import de.fhmuenster.masterthesis.serialization.TestgeneratorDSLSerializer;
 import de.fhmuenster.masterthesis.testgeneratorDSL.Flow;
+import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElement;
 import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElementReference;
 import de.fhmuenster.masterthesis.testgeneratorDSL.ManualTaskFlowElement;
 import de.fhmuenster.masterthesis.testgeneratorDSL.ScriptTaskFlowElement;
@@ -92,6 +94,9 @@ public class MigrationService {
 		Flow [][] matchingFlows = this.changeService.compareFlows(newFlows, oldFlows);
 		
 		for(int i=0; i < matchingFlows.length; i++) {
+			//Wenn kein alter Flow vorhanden ist, konnte das Matching nicht durchgeführt werden
+			if(matchingFlows[i][1] == null) continue;
+			
 			result.addAll(compareFlowsForAddAction(matchingFlows[i][1], matchingFlows[i][0]));
 		}
 		
@@ -105,6 +110,9 @@ public class MigrationService {
 		Flow [][] matchingFlows = this.changeService.compareFlows(newFlows, oldFlows);
 		
 		for(int i=0; i < matchingFlows.length; i++) {
+			//Wenn kein alter Flow vorhanden ist, konnte das Matching nicht durchgeführt werden
+			if(matchingFlows[i][1] == null) continue;
+			
 			result.addAll(compareFlowsForDeleteAction(matchingFlows[i][1], matchingFlows[i][0]));
 		}
 		
@@ -134,44 +142,25 @@ public class MigrationService {
 		
 		for(FlowElementReference e : addedFlowElements) {
 			if(e.getRef() instanceof ManualTaskFlowElement) {
-				FlowChangeWrapper fcw = new FlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_MANUAL_TASK,
-						e.getRef(), yaml.getActivity().getAdd().getManualTask());
-				if(fcw.getMigrationResult().getPriority() == null) {
-					fcw.getMigrationResult().setPriority(this.loadGlobalPriority(fcw.getMigrationResult().getStatus(), yaml));
-				}
-				
-				result.add(fcw);
+				result.add(this.prepareFlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_MANUAL_TASK, e.getRef(), yaml));
 			}
 			if(e.getRef() instanceof UserTaskFlowElement) {
-				FlowChangeWrapper fcw = new FlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_USER_TASK,
-						e.getRef(), yaml.getActivity().getAdd().getUserTask());
-				if(fcw.getMigrationResult().getPriority() == null) {
-					fcw.getMigrationResult().setPriority(this.loadGlobalPriority(fcw.getMigrationResult().getStatus(), yaml));
-				}
-				
-				result.add(fcw);
+				result.add(this.prepareFlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_USER_TASK, e.getRef(), yaml));
 			}
 			if(e.getRef() instanceof BusinessRuleTaskFlowElement) {
 				BusinessRuleTaskFlowElement element = (BusinessRuleTaskFlowElement) e.getRef();
 				FlowChangeWrapper fcw = null;
-				if(element.getResultVariable() != "") {
-					fcw = new FlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_BUSINESS_RULE_TASK,
-							e.getRef(), yaml.getActivity().getAdd().getBusinessRuleTask().getWithOutput());
+				if(element.getResultVariable() != "") {	
+					result.add(this.prepareFlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_BUSINESS_RULE_TASK_WITH_OUTPUT,
+							e.getRef(), yaml));
 				}
 				else {
-					fcw = new FlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_BUSINESS_RULE_TASK,
-							e.getRef(), yaml.getActivity().getAdd().getBusinessRuleTask().getWithoutOutput());
-				}
-				if(fcw.getMigrationResult().getPriority() == null) {
-					fcw.getMigrationResult().setPriority(this.loadGlobalPriority(fcw.getMigrationResult().getStatus(), yaml));
+					result.add(this.prepareFlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_BUSINESS_RULE_TASK_WITHOUT_OUTPUT,
+							e.getRef(), yaml));
 				}
-				
-				result.add(fcw);
 			}
 			if(e.getRef() instanceof ServiceTaskFlowElement) {
 				ServiceTaskFlowElement element = (ServiceTaskFlowElement) e.getRef();
-				FlowChangeWrapper fcw = null;
-				
 				//erstmal als todo gelassen
 				/*
 				if(element.get != "") {
@@ -183,18 +172,11 @@ public class MigrationService {
 							e.getRef(), yaml.getActivity().getAdd().getBusinessRuleTask().getWithoutOutput());
 				}
 				*/
-				fcw = new FlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_SERVICE_TASK,
-						e.getRef(), yaml.getActivity().getAdd().getServiceTask().getWithoutOutput());
 				
-				if(fcw.getMigrationResult().getPriority() == null) {
-					fcw.getMigrationResult().setPriority(this.loadGlobalPriority(fcw.getMigrationResult().getStatus(), yaml));
-				}
-				
-				result.add(fcw);
+				result.add(this.prepareFlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_SERVICE_TASK, e.getRef(), yaml));
 			}
 			if(e.getRef() instanceof ScriptTaskFlowElement) {
 				ScriptTaskFlowElement element = (ScriptTaskFlowElement) e.getRef();
-				FlowChangeWrapper fcw = null;
 				
 				//erstmal als todo gelassen
 				/*
@@ -207,14 +189,7 @@ public class MigrationService {
 							e.getRef(), yaml.getActivity().getAdd().getBusinessRuleTask().getWithoutOutput());
 				}
 				*/
-				fcw = new FlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_SCRIPT_TASK,
-						e.getRef(), yaml.getActivity().getAdd().getScriptTask().getWithoutOutput());
-				
-				if(fcw.getMigrationResult().getPriority() == null) {
-					fcw.getMigrationResult().setPriority(this.loadGlobalPriority(fcw.getMigrationResult().getStatus(), yaml));
-				}
-				
-				result.add(fcw);
+				result.add(this.prepareFlowChangeWrapper(newFlow, ActionType.ACTIVITY_ADD_SCRIPT_TASK, e.getRef(), yaml));
 			}
 		}
 		
@@ -244,7 +219,15 @@ public class MigrationService {
 		MigrationYaml yaml = yamlReader.loadMigrationYaml();
 		
 		for(FlowElementReference e : deletedFlowElements) {
-			
+			if(e.getRef() instanceof ManualTaskFlowElement) {
+				FlowChangeWrapper fcw = new FlowChangeWrapper(newFlow, ActionType.ACTIVITY_DELETE_MANUAL_TASK,
+						e.getRef(), yaml.getActivity().getAdd().getManualTask());
+				if(fcw.getMigrationResult().getPriority() == null) {
+					fcw.getMigrationResult().setPriority(this.loadGlobalPriority(fcw.getMigrationResult().getStatus(), yaml));
+				}
+				
+				result.add(fcw);
+			}
 			
 			
 		}
@@ -356,4 +339,40 @@ public class MigrationService {
 			score += yaml.getConfiguration().getRed();
 		return score;
 	}
+	
+	private FlowChangeWrapper prepareFlowChangeWrapper(Flow flow, ActionType actionType,
+			FlowElement element, MigrationYaml yaml) {
+		MigrationResult migrationResult = null;
+		
+		switch(actionType) {
+			case ACTIVITY_ADD_MANUAL_TASK:
+				migrationResult = yaml.getActivity().getAdd().getManualTask();
+				break;
+			case ACTIVITY_ADD_USER_TASK:
+				migrationResult = yaml.getActivity().getAdd().getUserTask();
+				break;
+			case ACTIVITY_ADD_BUSINESS_RULE_TASK_WITH_OUTPUT:
+				migrationResult = yaml.getActivity().getAdd().getBusinessRuleTask().getWithOutput();
+				break;
+			case ACTIVITY_ADD_BUSINESS_RULE_TASK_WITHOUT_OUTPUT:
+				migrationResult = yaml.getActivity().getAdd().getBusinessRuleTask().getWithoutOutput();
+				break;
+			case ACTIVITY_ADD_SERVICE_TASK:
+				//TODO: Muss noch unterschieden werden ob mit oder ohne Output
+				migrationResult = yaml.getActivity().getAdd().getServiceTask().getWithOutput();
+				break;
+			case ACTIVITY_ADD_SCRIPT_TASK:
+				//TODO: Muss noch unterschieden werden ob mit oder ohne Output
+				migrationResult = yaml.getActivity().getAdd().getScriptTask().getWithOutput();
+				break;
+		}
+		
+		if(migrationResult.getPriority() == null) {
+			migrationResult.setPriority(this.loadGlobalPriority(migrationResult.getStatus(), yaml));
+		}
+		
+		FlowChangeWrapper fcw = new FlowChangeWrapper(flow, actionType, element, migrationResult);
+		
+		return fcw;
+	}
 }
-- 
GitLab