Skip to content
Snippets Groups Projects
Commit 90fbcb64 authored by Florian Lambers's avatar Florian Lambers
Browse files
parents 9b9dc5c1 c4c5293b
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,11 @@ ...@@ -55,7 +55,11 @@
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>
<version>2.13.0</version> <version>2.13.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.camunda.bpm.model</groupId> <groupId>org.camunda.bpm.model</groupId>
<artifactId>camunda-bpmn-model</artifactId> <artifactId>camunda-bpmn-model</artifactId>
......
...@@ -6,6 +6,13 @@ import java.util.List; ...@@ -6,6 +6,13 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import de.fhmuenster.masterthesis.serialization.TestgeneratorDSLObjectCreator;
import de.fhmuenster.masterthesis.testgeneratorDSL.BooleanVariable;
import de.fhmuenster.masterthesis.testgeneratorDSL.IntVariable;
import de.fhmuenster.masterthesis.testgeneratorDSL.StringVariable;
import de.fhmuenster.masterthesis.testgeneratorDSL.TestgeneratorDSLFactory;
import de.fhmuenster.masterthesis.testgeneratorDSL.VariableReference;
public class BPMNIOParameters { public class BPMNIOParameters {
private HashMap<String, List<String>> inputVariables = new HashMap<String, List<String>>(); private HashMap<String, List<String>> inputVariables = new HashMap<String, List<String>>();
...@@ -13,6 +20,7 @@ public class BPMNIOParameters { ...@@ -13,6 +20,7 @@ public class BPMNIOParameters {
private HashMap<String, List<String>> innerOutputVariables = new HashMap<String, List<String>>(); private HashMap<String, List<String>> innerOutputVariables = new HashMap<String, List<String>>();
private HashMap<String, List<String>> removeVariables = new HashMap<String, List<String>>(); private HashMap<String, List<String>> removeVariables = new HashMap<String, List<String>>();
private HashMap<String, HashMap<String, String>> hardcodedInputParametersString = new HashMap<String, HashMap<String, String>>(); private HashMap<String, HashMap<String, String>> hardcodedInputParametersString = new HashMap<String, HashMap<String, String>>();
private HashMap<String, HashMap<String, Long>> hardcodedInputParametersLong = new HashMap<String, HashMap<String, Long>>(); private HashMap<String, HashMap<String, Long>> hardcodedInputParametersLong = new HashMap<String, HashMap<String, Long>>();
private HashMap<String, HashMap<String, Boolean>> hardcodedInputParametersBoolean = new HashMap<String, HashMap<String, Boolean>>(); private HashMap<String, HashMap<String, Boolean>> hardcodedInputParametersBoolean = new HashMap<String, HashMap<String, Boolean>>();
...@@ -68,6 +76,89 @@ public class BPMNIOParameters { ...@@ -68,6 +76,89 @@ public class BPMNIOParameters {
variables.add(removeVariable); variables.add(removeVariable);
this.removeVariables.put(flowElementId, variables); this.removeVariables.put(flowElementId, variables);
} }
/**
* 20.12.2021
* addSetVariable add setVariable to HashMap setVariables to use it on BPMNIOParameters
* @param taskId
*/
public void addSetVariable(String flowElementId, String setVarName, Object setVarValue) {
try
{
// Check Variable Type and create Variable if needed
if(setVarValue instanceof Integer)
{
HashMap<String, Long> existingVariables = this.hardcodedInputParametersLong.get(flowElementId);
HashMap<String, Long> variables = existingVariables != null ? existingVariables : new HashMap<>();
if(!variables.containsKey(setVarName))
{
List<Integer> iValueList = new ArrayList<>();
iValueList.add((Integer) setVarValue);
TestgeneratorDSLObjectCreator.createIntVariable(setVarName, iValueList);
Long lvar = (Long) setVarValue;
variables.put(flowElementId, lvar);
}
this.hardcodedInputParametersLong.put(flowElementId, variables);
}
else if(setVarValue instanceof Boolean)
{
HashMap<String, Boolean> existingVariables = this.hardcodedInputParametersBoolean.get(flowElementId);
HashMap<String, Boolean> variables = existingVariables != null ? existingVariables : new HashMap<>();
if(!variables.containsKey(setVarName))
{
List<Boolean> bValueList = new ArrayList<>();
bValueList.add((Boolean) setVarValue);
TestgeneratorDSLObjectCreator.createBooleanVariable(setVarName, bValueList);
variables.put(setVarName, (Boolean) setVarValue);
}
this.hardcodedInputParametersBoolean.put(flowElementId, variables);
}
else if(setVarValue instanceof String)
{
List<String> existingVariables = this.outputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
if(!variables.contains(setVarName))
{
List<String> sList = new ArrayList<>();
sList.add((String) setVarValue);
TestgeneratorDSLObjectCreator.createStringVariable(setVarName, sList);
variables.add(setVarName);
}
this.outputVariables.put(flowElementId, variables);
}
}
catch(Exception e)
{
System.out.println("[DEBUG] " + e.getMessage());
}
}
/**
* 20.12.2021
* addGetVariable add getVariable to HashMap getVariables to use it on BPMNIOParameters
* @param taskId
*/
public void addGetVariable(String flowElementId, String getVarName) {
// setVartiable == readVariables/inputVariables
List<String> existingVariables = this.inputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
if(variables.contains(getVarName))
{
variables.add(getVarName);
this.inputVariables.put(flowElementId, variables);
}
}
public void addInputVariable(String flowElementId, String inputVariableName) { public void addInputVariable(String flowElementId, String inputVariableName) {
List<String> existingVariables = this.inputVariables.get(flowElementId); List<String> existingVariables = this.inputVariables.get(flowElementId);
......
...@@ -9,6 +9,7 @@ import java.util.regex.Matcher; ...@@ -9,6 +9,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.model.bpmn.instance.BaseElement; import org.camunda.bpm.model.bpmn.instance.BaseElement;
import org.camunda.bpm.model.bpmn.instance.FlowElement; import org.camunda.bpm.model.bpmn.instance.FlowElement;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaInputParameter; import org.camunda.bpm.model.bpmn.instance.camunda.CamundaInputParameter;
...@@ -28,6 +29,7 @@ public class BPMNVariableIOScanner { ...@@ -28,6 +29,7 @@ public class BPMNVariableIOScanner {
private static final String NAMESPACE_URI_BPMN = "http://camunda.org/schema/1.0/bpmn"; private static final String NAMESPACE_URI_BPMN = "http://camunda.org/schema/1.0/bpmn";
private static final String INPUT_OUTPUT_NAME = "inputOutput"; private static final String INPUT_OUTPUT_NAME = "inputOutput";
private static final String EXECUTION_LISTENER = "executionListener"; private static final String EXECUTION_LISTENER = "executionListener";
private static final String LISTENER_TYPE_EXPRESSION = "expression";
private BPMNFlowSet flowSet; private BPMNFlowSet flowSet;
private BPMNIOParameters bpmnIOParameters; private BPMNIOParameters bpmnIOParameters;
...@@ -53,7 +55,7 @@ public class BPMNVariableIOScanner { ...@@ -53,7 +55,7 @@ public class BPMNVariableIOScanner {
* added routine to scan in Camunda the removeExpressions * added routine to scan in Camunda the removeExpressions
*/ */
extensionElements extensionElements
.forEach(baseElement -> scanRemoveExpressions(baseElement)); // .forEach(baseElement -> scanExpressions(baseElement)); //
} }
...@@ -148,12 +150,32 @@ public class BPMNVariableIOScanner { ...@@ -148,12 +150,32 @@ public class BPMNVariableIOScanner {
bpmnIOParameters.addRemoveVariable(baseElement.getId(), removeVar); bpmnIOParameters.addRemoveVariable(baseElement.getId(), removeVar);
} }
/**
* 20.12.2021
* insert getVariables to BPMNIOParameters
* @param baseElement
*/
private void insertGetVariable(FlowElement baseElement, String getVarName)
{
bpmnIOParameters.addGetVariable(baseElement.getId(), getVarName);
}
/**
* 20.12.2021
* insert setVariables to BPMNIOParameters
* @param baseElement
*/
private void insertSetVariable(FlowElement baseElement, String setVarName, Object setVarValue)
{
bpmnIOParameters.addSetVariable(baseElement.getId(), setVarName, setVarValue);
}
/** /**
* 15.12.2021 * 15.12.2021
* Scan for removeExpressions * Scan for removeExpressions
* @param baseElement * @param baseElement
*/ */
private void scanRemoveExpressions(FlowElement baseElement) { private void scanExpressions(FlowElement baseElement) {
Collection<ModelElementInstance> elements = baseElement.getExtensionElements().getElements(); Collection<ModelElementInstance> elements = baseElement.getExtensionElements().getElements();
...@@ -168,19 +190,31 @@ public class BPMNVariableIOScanner { ...@@ -168,19 +190,31 @@ public class BPMNVariableIOScanner {
try try
{ {
List<String> removeVars = new ArrayList<String>(); List<String> removeVars = new ArrayList<String>();
List<String> getVars = new ArrayList<String>();
HashMap<String, Object> setVars = new HashMap<String, Object>();
switch(expression.getAttributeName()) switch(expression.getAttributeName())
{ {
case "delegateExpression": case LISTENER_TYPE_EXPRESSION:
String strExpression = expression.getValue(currentElement).toString(); String strExpression = expression.getValue(currentElement).toString();
if(strExpression.contains("execution.removeVariable")) // check the String for a removeVariable*s Expression
if(strExpression.contains("execution.removeVariable"))
{ {
Pattern pattern = Pattern.compile("\"(.*?)\"", Pattern.DOTALL); Pattern pattern = Pattern.compile("\"(.*?)\"", Pattern.DOTALL);
Matcher matcher = pattern.matcher(strExpression); Matcher matcher = pattern.matcher(strExpression);
while (matcher.find()) { while (matcher.find()) {
removeVars.add(matcher.group(1)); // Contains String with all variables from removeVar Expression removeVars.add(matcher.group(1));
} }
} }
if(strExpression.contains("execution.getVariable"))
{
getVars = this.buildGetVariableHashMap(strExpression);
}
if(strExpression.contains("execution.setVariable"))
{
setVars = this.buildSetVariableHashMap(strExpression);
}
break; break;
default: default:
break; break;
...@@ -191,17 +225,123 @@ public class BPMNVariableIOScanner { ...@@ -191,17 +225,123 @@ public class BPMNVariableIOScanner {
// add the removeVariables to BPMNIOParameters via. insertRemoveVariables // add the removeVariables to BPMNIOParameters via. insertRemoveVariables
removeVars.forEach(var -> this.insertRemoveVariable(baseElement, var)); removeVars.forEach(var -> this.insertRemoveVariable(baseElement, var));
} }
if(!getVars.isEmpty() && getVars!=null)
{
getVars.forEach((k) -> {
this.insertGetVariable(baseElement, k);
});
getVars.forEach((k) -> {
System.out.println("[GET] " + k);
});
}
if(!setVars.isEmpty() && setVars!=null)
{
setVars.forEach((k, v ) -> {
this.insertSetVariable(baseElement, k, v);
});
setVars.forEach((k, v) -> {
System.out.println("[SET] " + k + " value " + v);
});
}
} }
catch(Exception e) catch(Exception e)
{ {
System.out.println("[ERROR] " + e.getMessage()); System.out.println("[ERROR] " + e.getMessage());
} }
} }
}
}
}
/**
* Split all Variables in the expression string (without value)
* @param strExpression
* @return
*/
private List<String> buildGetVariableHashMap(String strExpression) {
int start, end;
start = strExpression.indexOf("(");
end = strExpression.indexOf(")");
strExpression = strExpression.substring(start+1, end);
String result [] = strExpression.split(",");
List<String> list = new ArrayList<String>();
try
{
for(String elem : result)
{
elem = elem.replace("\"", "");
elem = elem.replace(" ", "");
list.add(elem);
}
}
catch(Exception e)
{
System.out.println("[ERROR] getVariables Expression syntax error.");
}
return list;
}
/**
* Split the variables in the expression string (with value)
* @param strExpression
* @return
*/
private HashMap<String, Object> buildSetVariableHashMap(String strExpression) {
int start, end;
start = strExpression.indexOf("(");
end = strExpression.indexOf(")");
strExpression = strExpression.substring(start+1, end);
String result [] = strExpression.split(",");
HashMap<String, Object> hmap = new HashMap<String, Object>();
try
{
// Every second Element is the key
for(int i = 0; i < result.length; i+=2)
{
String key = result[i];
String val = result[i+1];
Object _val;
if(StringUtils.isNumericSpace(val))
{
val = val.replace(" ", "");
_val = Integer.parseInt(val);
}
else if(val.contains("true") || val.contains("false"))
{
_val = Boolean.valueOf(Boolean.parseBoolean(val));
}
else
{
val = val.replace("\"", "");
if(val.startsWith(" "))
val = val.substring(1, val.length());
_val = String.valueOf(val.toString());
}
key = key.replace("\"", "");
key = key.replace(" ", "");
hmap.put(key, _val);
} }
}
catch(Exception e)
{
System.out.println("[ERROR] setVariables Expression syntax error.");
} }
return hmap;
} }
} }
...@@ -20,6 +20,7 @@ import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElement; ...@@ -20,6 +20,7 @@ import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElement;
import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElementReference; import de.fhmuenster.masterthesis.testgeneratorDSL.FlowElementReference;
import de.fhmuenster.masterthesis.testgeneratorDSL.ManualTaskFlowElement; import de.fhmuenster.masterthesis.testgeneratorDSL.ManualTaskFlowElement;
import de.fhmuenster.masterthesis.testgeneratorDSL.ScriptTaskFlowElement; import de.fhmuenster.masterthesis.testgeneratorDSL.ScriptTaskFlowElement;
import de.fhmuenster.masterthesis.testgeneratorDSL.SequenceFlowElement;
import de.fhmuenster.masterthesis.testgeneratorDSL.UserTaskFlowElement; import de.fhmuenster.masterthesis.testgeneratorDSL.UserTaskFlowElement;
import de.fhmuenster.masterthesis.testgeneratorDSL.VariableReference; import de.fhmuenster.masterthesis.testgeneratorDSL.VariableReference;
...@@ -65,6 +66,7 @@ public class PrioritizationService { ...@@ -65,6 +66,7 @@ public class PrioritizationService {
HashMap<String, List<String>> differentRemoveVariables = this.checkDifferences(changesRemoveVariablesOLD, changesRemoveVariables); HashMap<String, List<String>> differentRemoveVariables = this.checkDifferences(changesRemoveVariablesOLD, changesRemoveVariables);
HashMap<String, Integer> dependenciesRead = this.checkFlowsWhereVariableExists(differentReadVariables); HashMap<String, Integer> dependenciesRead = this.checkFlowsWhereVariableExists(differentReadVariables);
HashMap<String, Integer> dependenciesWrite = this.checkFlowsWhereVariableExists(differentWriteVariables); HashMap<String, Integer> dependenciesWrite = this.checkFlowsWhereVariableExists(differentWriteVariables);
HashMap<String, Integer> dependenciesRemove = this.checkFlowsWhereVariableExists(differentRemoveVariables); HashMap<String, Integer> dependenciesRemove = this.checkFlowsWhereVariableExists(differentRemoveVariables);
...@@ -482,13 +484,18 @@ public class PrioritizationService { ...@@ -482,13 +484,18 @@ public class PrioritizationService {
List<VariableReference> readVariables = businessTask.getReadVariables(); List<VariableReference> readVariables = businessTask.getReadVariables();
mapFlowToReadVariables.put(flowElement.getName(), readVariables); mapFlowToReadVariables.put(flowElement.getName(), readVariables);
} }
else if(flowElementReference.getRef() instanceof SequenceFlowElement)
{
SequenceFlowElement sequenceTask = (SequenceFlowElement) flowElementReference.getRef();
List<VariableReference> readVariables = sequenceTask.getReadVariables();
mapFlowToReadVariables.put(flowElement.getName(), readVariables);
}
} }
} }
} }
catch(Exception e) { catch(Exception e) {
} }
return mapFlowToReadVariables; return mapFlowToReadVariables;
} }
......
...@@ -8,9 +8,12 @@ import java.util.HashMap; ...@@ -8,9 +8,12 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask; import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask;
import org.camunda.bpm.model.bpmn.instance.ConditionExpression;
import org.camunda.bpm.model.bpmn.instance.EndEvent; import org.camunda.bpm.model.bpmn.instance.EndEvent;
import org.camunda.bpm.model.bpmn.instance.Gateway; import org.camunda.bpm.model.bpmn.instance.Gateway;
import org.camunda.bpm.model.bpmn.instance.ManualTask; import org.camunda.bpm.model.bpmn.instance.ManualTask;
...@@ -766,7 +769,8 @@ public class TestService { ...@@ -766,7 +769,8 @@ public class TestService {
} }
} else if (flowElement instanceof SequenceFlow) { } else if (flowElement instanceof SequenceFlow) {
String expression = expressions.getSequenceFlowExpressionMap().get(flowElement.getId()); String expression = expressions.getSequenceFlowExpressionMap().get(flowElement.getId());
return TestgeneratorDSLObjectCreator.createSequenceFlowElement(flowElement.getId(), expression); List<Variable> inputVariables = mapExpressionToReadVariable(expression, variables);
return TestgeneratorDSLObjectCreator.createSequenceFlowElement(flowElement.getId(), expression, inputVariables);
} }
...@@ -774,6 +778,44 @@ public class TestService { ...@@ -774,6 +778,44 @@ public class TestService {
throw new UnsupportedFlowElementException(flowElement.getId()); throw new UnsupportedFlowElementException(flowElement.getId());
} }
private List<Variable> mapExpressionToReadVariable(String expression, List<Variable> variables) {
List<Variable> inputVariables = new ArrayList<Variable>();
if(expression != null) {
if(expression.contains("==")) {
Pattern pattern = Pattern.compile("\\{(.*?)\\=");
Matcher matcher = pattern.matcher(expression);
if (matcher.find()) {
for(Variable var: variables) {
if(matcher.group(1).equals(var.getName())) {
inputVariables.add(var);
}
}
}
pattern = Pattern.compile("\\{(.*?)\\ =");
matcher = pattern.matcher(expression);
if (matcher.find()) {
for(Variable var: variables) {
if(matcher.group(1).equals(var.getName())) {
inputVariables.add(var);
}
}
}
}
if(expression.contains("==") == false) {
Pattern pattern = Pattern.compile("\\{(.*?)\\}");
Matcher matcher = pattern.matcher(expression);
if (matcher.find()) {
for(Variable var: variables) {
if(matcher.group(1).equals(var.getName())) {
inputVariables.add(var);
}
}
}
}
}
return inputVariables;
}
private List<Variable> getReadVariables(String flowElementId, BPMNIOParameters bpmnIOParameters, List<Variable> variables, BPMNFormFields formFields) { private List<Variable> getReadVariables(String flowElementId, BPMNIOParameters bpmnIOParameters, List<Variable> variables, BPMNFormFields formFields) {
List<String> inputVariableNames = new ArrayList<>(); List<String> inputVariableNames = new ArrayList<>();
inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElementId)); inputVariableNames.addAll(bpmnIOParameters.getInputVariables(flowElementId));
......
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