From 8ae31673d9739b33c773a300961664c9f1d4ed6d Mon Sep 17 00:00:00 2001
From: Florian Lambers <fl462057@fh-muenster.de>
Date: Tue, 30 Nov 2021 12:08:18 +0100
Subject: [PATCH] added validationstatus to variables, added constraints

---
 .../masterthesis/TestgeneratorDSL.xtext         | 14 +++++++++++++-
 .../masterthesis/serialization/Main.java        |  3 ++-
 .../TestgeneratorDSLObjectCreator.java          | 17 ++++++++++++++++-
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/TestgeneratorDSL.xtext b/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/TestgeneratorDSL.xtext
index d18bc7d..589ccfa 100644
--- a/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/TestgeneratorDSL.xtext
+++ b/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/TestgeneratorDSL.xtext
@@ -107,21 +107,25 @@ Variable:
 	StringVariable | IntVariable | BooleanVariable;
 	
 VariableReference:
-	ref=[Variable];
+	ref=[Variable]
+	("(" validationStatus=ValidationState ")")?;
 	
 StringVariable:
 	"String" name=ID 
 	"with" "proposals" ASSOCIATION LIST_OPEN (proposals+=STRING (SEPARATOR proposals+=STRING)*)? LIST_CLOSED
+	"with" "constraints" ASSOCIATION LIST_OPEN (constraints+=Constraint (SEPARATOR constraints+=Constraint)*)? LIST_CLOSED
 	DECLARATION_FINISHED;
 	
 IntVariable:
 	"Integer" name=ID 
 	"with" "proposals" ASSOCIATION LIST_OPEN (proposals+=INT (SEPARATOR proposals+=INT)*)? LIST_CLOSED
+	"with" "constraints" ASSOCIATION LIST_OPEN (constraints+=Constraint (SEPARATOR constraints+=Constraint)*)? LIST_CLOSED
 	DECLARATION_FINISHED;
 	
 BooleanVariable:
 	"Boolean" name=ID 
 	"with" "proposals" ASSOCIATION LIST_OPEN (proposals+=Boolean (SEPARATOR proposals+=Boolean)*)? LIST_CLOSED
+	"with" "constraints" ASSOCIATION LIST_OPEN (constraints+=Constraint (SEPARATOR constraints+=Constraint)*)? LIST_CLOSED
 	DECLARATION_FINISHED;
 
 enum Boolean:
@@ -239,6 +243,9 @@ IntCompare:
 
 BooleanCompare:
 	key=[BooleanVariable] compareSymbol=BooleanCompareSymbol value=Boolean;
+	
+Constraint:
+	key=STRING ASSOCIATION value=INT;
 
 enum StringCompareSymbol:
 	EQUALS = "==" |
@@ -261,6 +268,11 @@ enum Flag:
 	GREEN = "GREEN" |
 	YELLOW = "YELLOW" |
 	RED = "RED";
+	
+enum ValidationState:
+	REQUIRED = "REQUIRED" |
+	OPTIONAL = "OPTIONAL"
+;
 
 terminal LIST_OPEN : '[';
 terminal LIST_CLOSED : ']';
diff --git a/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/serialization/Main.java b/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/serialization/Main.java
index f5f994b..f2895fa 100644
--- a/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/serialization/Main.java
+++ b/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/serialization/Main.java
@@ -2,6 +2,7 @@ package de.fhmuenster.masterthesis.serialization;
 
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import de.fhmuenster.masterthesis.testgeneratorDSL.BPMNDiagram;
@@ -31,7 +32,7 @@ public class Main {
 		
 		FlowElement start = TestgeneratorDSLObjectCreator.createStartFlowElement("Start_123", Arrays.asList());
 		FlowElement gateway = TestgeneratorDSLObjectCreator.createGatewayFlowElement("Gateway_123");
-		FlowElement activity = TestgeneratorDSLObjectCreator.createUserTaskFlowElement("Activity_123", Arrays.asList(), Arrays.asList(), "Activity 123");
+		FlowElement activity = TestgeneratorDSLObjectCreator.createUserTaskFlowElement("Activity_123", Arrays.asList(), Arrays.asList(), "Activity 123", null);
 		FlowElement end = TestgeneratorDSLObjectCreator.createEndFlowElement("End_123");
 		FlowElement activity2 = TestgeneratorDSLObjectCreator.createServiceTaskFlowElement("Activity_234");
 		FlowElement end2 = TestgeneratorDSLObjectCreator.createEndFlowElement("End_234");
diff --git a/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/serialization/TestgeneratorDSLObjectCreator.java b/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/serialization/TestgeneratorDSLObjectCreator.java
index 7bc2ceb..17e3ee9 100644
--- a/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/serialization/TestgeneratorDSLObjectCreator.java
+++ b/de.fhmuenster.masterthesis.textgeneratordsl/src/de/fhmuenster/masterthesis/serialization/TestgeneratorDSLObjectCreator.java
@@ -16,6 +16,7 @@ import de.fhmuenster.masterthesis.testgeneratorDSL.BooleanVariableEquals;
 import de.fhmuenster.masterthesis.testgeneratorDSL.BooleanVariableNotEquals;
 import de.fhmuenster.masterthesis.testgeneratorDSL.BusinessRuleTaskFlowElement;
 import de.fhmuenster.masterthesis.testgeneratorDSL.Compare;
+import de.fhmuenster.masterthesis.testgeneratorDSL.Constraint;
 import de.fhmuenster.masterthesis.testgeneratorDSL.DelegateMock;
 import de.fhmuenster.masterthesis.testgeneratorDSL.DelegateServiceTaskFlowElement;
 import de.fhmuenster.masterthesis.testgeneratorDSL.DelegateServiceTaskReference;
@@ -57,6 +58,7 @@ import de.fhmuenster.masterthesis.testgeneratorDSL.StringVariableNotEquals;
 import de.fhmuenster.masterthesis.testgeneratorDSL.Test;
 import de.fhmuenster.masterthesis.testgeneratorDSL.TestgeneratorDSLFactory;
 import de.fhmuenster.masterthesis.testgeneratorDSL.UserTaskFlowElement;
+import de.fhmuenster.masterthesis.testgeneratorDSL.ValidationState;
 import de.fhmuenster.masterthesis.testgeneratorDSL.Variable;
 import de.fhmuenster.masterthesis.testgeneratorDSL.VariableDeclaration;
 import de.fhmuenster.masterthesis.testgeneratorDSL.VariableDeclarations;
@@ -108,7 +110,8 @@ public class TestgeneratorDSLObjectCreator {
 		return element;
 	}
 	
-	public static UserTaskFlowElement createUserTaskFlowElement(String name, List<Variable> inputVariables, List<Variable> outputVariables, String label) {
+	public static UserTaskFlowElement createUserTaskFlowElement(String name, List<Variable> inputVariables, List<Variable> outputVariables, String label,
+			HashMap<String, List<Constraint>> taskSpecificConstraints) {
 		UserTaskFlowElement element = TestgeneratorDSLFactory.eINSTANCE.createUserTaskFlowElement();
 		element.setName(name);
 		element.setLabel(label);
@@ -116,6 +119,18 @@ public class TestgeneratorDSLObjectCreator {
 		for (Variable inputVariable : inputVariables) {
 			VariableReference variableReference = TestgeneratorDSLFactory.eINSTANCE.createVariableReference();
 			variableReference.setRef(inputVariable);
+			
+			if(taskSpecificConstraints.get(inputVariable.getName()) != null) {
+				for(Constraint c : taskSpecificConstraints.get(inputVariable.getName())) {
+					if(c.getKey().equals("required")) {
+						if(c.getValue() == 0) {
+							variableReference.setValidationStatus(ValidationState.OPTIONAL);
+						}
+					}
+				}
+			}
+			
+			
 			element.getInputVariables().add(variableReference);
 		}
 		
-- 
GitLab