Skip to content
Snippets Groups Projects
Commit 37d47889 authored by Henning's avatar Henning
Browse files

Added removeVariables to BPMNIOVariableScanner. New Function

getRemoveVariables, added removeVariables to TestService
parent 5102e40d
No related branches found
No related tags found
No related merge requests found
package de.fhmuenster.masterthesis.Testgenerator.bpmn.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class BPMNIOParameters {
private HashMap<String, List<String>> inputVariables = new HashMap<String, List<String>>();
private HashMap<String, List<String>> outputVariables = new HashMap<String, List<String>>();
private HashMap<String, List<String>> innerOutputVariables = new HashMap<String, List<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, Boolean>> hardcodedInputParametersBoolean = new HashMap<String, HashMap<String, Boolean>>();
public BPMNIOParameters() {
}
public HashMap<String, List<String>> getInputParameters() {
return inputVariables;
}
public List<String> getInputVariables(String taskId) {
return inputVariables.entrySet().stream() //
.filter(entry -> entry.getKey().equals(taskId)) //
.flatMap(entry -> entry.getValue().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<String> getOutputVariables(String taskId) {
return outputVariables.entrySet().stream() //
.filter(entry -> entry.getKey().equals(taskId)) //
.flatMap(entry -> entry.getValue().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public HashMap<String, List<String>> getOutputParameters() {
return outputVariables;
}
public void addInputVariable(String flowElementId, String inputVariableName) {
List<String> existingVariables = this.inputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.add(inputVariableName);
this.inputVariables.put(flowElementId, variables);
}
public void addInputVariables(String flowElementId, List<String> inputVariables) {
List<String> existingVariables = this.inputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.addAll(inputVariables);
this.inputVariables.put(flowElementId, variables);
}
public void addOutputVariable(String flowElementId, String outputVariable) {
List<String> existingVariables = this.outputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.add(outputVariable);
this.outputVariables.put(flowElementId, variables);
}
public void addInnerOutputVariable(String flowElementId, String outputVariable) {
List<String> existingVariables = this.innerOutputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.add(outputVariable);
this.innerOutputVariables.put(flowElementId, variables);
}
public void addOutputVariables(String flowElementId, List<String> outputVariables) {
List<String> existingVariables = this.outputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.addAll(outputVariables);
this.outputVariables.put(flowElementId, variables);
}
public void addHardcodedInputParameterString(String flowElementId, String inputVariable, String value) {
HashMap<String, String> existingVariables = this.hardcodedInputParametersString.get(flowElementId);
HashMap<String, String> variables = existingVariables != null ? existingVariables : new HashMap<>();
variables.put(inputVariable, value);
this.hardcodedInputParametersString.put(flowElementId, variables);
}
public void addHardcodedInputParameterLong(String flowElementId, String inputVariable, Long value) {
HashMap<String, Long> existingVariables = this.hardcodedInputParametersLong.get(flowElementId);
HashMap<String, Long> variables = existingVariables != null ? existingVariables : new HashMap<>();
variables.put(inputVariable, value);
this.hardcodedInputParametersLong.put(flowElementId, variables);
}
public void addHardcodedInputParameterBoolean(String flowElementId, String inputVariable, Boolean value) {
HashMap<String, Boolean> existingVariables = this.hardcodedInputParametersBoolean.get(flowElementId);
HashMap<String, Boolean> variables = existingVariables != null ? existingVariables : new HashMap<>();
variables.put(inputVariable, value);
this.hardcodedInputParametersBoolean.put(flowElementId, variables);
}
public List<String> getVariables() {
return Stream.concat(Stream.concat(inputVariables.values().stream(), outputVariables.values().stream()), innerOutputVariables.values().stream()) //
.flatMap(variableList -> variableList.stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public HashMap<String, String> getHardcodedInputParametersString(String flowElementId) {
return hardcodedInputParametersString.get(flowElementId);
}
public HashMap<String, Long> getHardcodedInputParametersLong(String flowElementId) {
return hardcodedInputParametersLong.get(flowElementId);
}
public HashMap<String, Boolean> getHardcodedInputParametersBoolean(String flowElementId) {
return hardcodedInputParametersBoolean.get(flowElementId);
}
public List<String> getHardcodedInputParametersString() {
return hardcodedInputParametersString.values().stream() //
.flatMap(parameterValueMap -> parameterValueMap.keySet().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<String> getHardcodedInputParametersLong() {
return hardcodedInputParametersLong.values().stream() //
.flatMap(parameterValueMap -> parameterValueMap.keySet().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<String> getHardcodedInputParametersBoolean() {
return hardcodedInputParametersBoolean.values().stream() //
.flatMap(parameterValueMap -> parameterValueMap.keySet().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<String> getHardcodedInputParameters() {
List<String> hardcodedInputParameters = new ArrayList<>();
hardcodedInputParameters.addAll(getHardcodedInputParametersString());
hardcodedInputParameters.addAll(getHardcodedInputParametersLong());
hardcodedInputParameters.addAll(getHardcodedInputParametersBoolean());
return hardcodedInputParameters;
}
public List<String> getHardcodedInputParameterValuesString(String parameter) {
return hardcodedInputParametersString.values().stream() //
.map(parameterValueMap -> parameterValueMap.get(parameter)) //
.filter(value -> value != null) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<Long> getHardcodedInputParameterValuesLong(String parameter) {
return hardcodedInputParametersLong.values().stream() //
.map(parameterValueMap -> parameterValueMap.get(parameter)) //
.distinct() //
.collect(Collectors.toList()); //
}
}
package de.fhmuenster.masterthesis.Testgenerator.bpmn.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class BPMNIOParameters {
private HashMap<String, List<String>> inputVariables = new HashMap<String, List<String>>();
private HashMap<String, List<String>> outputVariables = 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, 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, Boolean>> hardcodedInputParametersBoolean = new HashMap<String, HashMap<String, Boolean>>();
public BPMNIOParameters() {
}
public HashMap<String, List<String>> getInputParameters() {
return inputVariables;
}
public List<String> getInputVariables(String taskId) {
return inputVariables.entrySet().stream() //
.filter(entry -> entry.getKey().equals(taskId)) //
.flatMap(entry -> entry.getValue().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<String> getOutputVariables(String taskId) {
return outputVariables.entrySet().stream() //
.filter(entry -> entry.getKey().equals(taskId)) //
.flatMap(entry -> entry.getValue().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public HashMap<String, List<String>> getOutputParameters() {
return outputVariables;
}
/**
* 15.12.2021
* getRemoveVariables on BPMNIOParameters
* @param taskId
*/
public List<String> getRemoveVariables(String taskId) {
return removeVariables.entrySet().stream() //
.filter(entry -> entry.getKey().equals(taskId)) //
.flatMap(entry -> entry.getValue().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
/**
* 15.12.2021
* addRemoveVariable add removeVariable to HashMap removeVariables to use it on BPMNIOParameters
* @param taskId
*/
public void addRemoveVariable(String flowElementId, String removeVariable) {
List<String> existingVariables = this.removeVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.add(removeVariable);
this.removeVariables.put(flowElementId, variables);
}
public void addInputVariable(String flowElementId, String inputVariableName) {
List<String> existingVariables = this.inputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.add(inputVariableName);
this.inputVariables.put(flowElementId, variables);
}
public void addInputVariables(String flowElementId, List<String> inputVariables) {
List<String> existingVariables = this.inputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.addAll(inputVariables);
this.inputVariables.put(flowElementId, variables);
}
public void addOutputVariable(String flowElementId, String outputVariable) {
List<String> existingVariables = this.outputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.add(outputVariable);
this.outputVariables.put(flowElementId, variables);
}
public void addInnerOutputVariable(String flowElementId, String outputVariable) {
List<String> existingVariables = this.innerOutputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.add(outputVariable);
this.innerOutputVariables.put(flowElementId, variables);
}
public void addOutputVariables(String flowElementId, List<String> outputVariables) {
List<String> existingVariables = this.outputVariables.get(flowElementId);
List<String> variables = existingVariables != null ? existingVariables : new ArrayList<>();
variables.addAll(outputVariables);
this.outputVariables.put(flowElementId, variables);
}
public void addHardcodedInputParameterString(String flowElementId, String inputVariable, String value) {
HashMap<String, String> existingVariables = this.hardcodedInputParametersString.get(flowElementId);
HashMap<String, String> variables = existingVariables != null ? existingVariables : new HashMap<>();
variables.put(inputVariable, value);
this.hardcodedInputParametersString.put(flowElementId, variables);
}
public void addHardcodedInputParameterLong(String flowElementId, String inputVariable, Long value) {
HashMap<String, Long> existingVariables = this.hardcodedInputParametersLong.get(flowElementId);
HashMap<String, Long> variables = existingVariables != null ? existingVariables : new HashMap<>();
variables.put(inputVariable, value);
this.hardcodedInputParametersLong.put(flowElementId, variables);
}
public void addHardcodedInputParameterBoolean(String flowElementId, String inputVariable, Boolean value) {
HashMap<String, Boolean> existingVariables = this.hardcodedInputParametersBoolean.get(flowElementId);
HashMap<String, Boolean> variables = existingVariables != null ? existingVariables : new HashMap<>();
variables.put(inputVariable, value);
this.hardcodedInputParametersBoolean.put(flowElementId, variables);
}
public List<String> getVariables() {
return Stream.concat(Stream.concat(inputVariables.values().stream(), outputVariables.values().stream()), innerOutputVariables.values().stream()) //
.flatMap(variableList -> variableList.stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public HashMap<String, String> getHardcodedInputParametersString(String flowElementId) {
return hardcodedInputParametersString.get(flowElementId);
}
public HashMap<String, Long> getHardcodedInputParametersLong(String flowElementId) {
return hardcodedInputParametersLong.get(flowElementId);
}
public HashMap<String, Boolean> getHardcodedInputParametersBoolean(String flowElementId) {
return hardcodedInputParametersBoolean.get(flowElementId);
}
public List<String> getHardcodedInputParametersString() {
return hardcodedInputParametersString.values().stream() //
.flatMap(parameterValueMap -> parameterValueMap.keySet().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<String> getHardcodedInputParametersLong() {
return hardcodedInputParametersLong.values().stream() //
.flatMap(parameterValueMap -> parameterValueMap.keySet().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<String> getHardcodedInputParametersBoolean() {
return hardcodedInputParametersBoolean.values().stream() //
.flatMap(parameterValueMap -> parameterValueMap.keySet().stream()) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<String> getHardcodedInputParameters() {
List<String> hardcodedInputParameters = new ArrayList<>();
hardcodedInputParameters.addAll(getHardcodedInputParametersString());
hardcodedInputParameters.addAll(getHardcodedInputParametersLong());
hardcodedInputParameters.addAll(getHardcodedInputParametersBoolean());
return hardcodedInputParameters;
}
public List<String> getHardcodedInputParameterValuesString(String parameter) {
return hardcodedInputParametersString.values().stream() //
.map(parameterValueMap -> parameterValueMap.get(parameter)) //
.filter(value -> value != null) //
.distinct() //
.collect(Collectors.toList()); //
}
public List<Long> getHardcodedInputParameterValuesLong(String parameter) {
return hardcodedInputParametersLong.values().stream() //
.map(parameterValueMap -> parameterValueMap.get(parameter)) //
.distinct() //
.collect(Collectors.toList()); //
}
}
package de.fhmuenster.masterthesis.Testgenerator.bpmn.processfragmentation;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.camunda.bpm.model.bpmn.instance.BaseElement;
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.CamundaOutputParameter;
import de.fhmuenster.masterthesis.Testgenerator.bpmn.data.BPMNFlowSet;
import de.fhmuenster.masterthesis.Testgenerator.bpmn.data.BPMNIOParameters;
public class BPMNVariableIOScanner {
private static final String VARIABLE_MATCH_REGEX = "\\$\\{(.*?)\\}";
private static final String INT_MATCH_REGEX = "[0-9]+";
private static final String BOOLEAN_MATCH_REGEX = "true|false";
private static final String NAMESPACE_URI_BPMN = "http://camunda.org/schema/1.0/bpmn";
private static final String INPUT_OUTPUT_NAME = "inputOutput";
private BPMNFlowSet flowSet;
private BPMNIOParameters bpmnIOParameters;
public BPMNVariableIOScanner(BPMNFlowSet flowSet) {
this.flowSet = flowSet;
this.bpmnIOParameters = new BPMNIOParameters();
}
public void doScan() {
List<FlowElement> extensionElements = flowSet.getFlowElements().stream() //
.filter(baseElement -> ((BaseElement) baseElement).getExtensionElements() != null) //
.collect(Collectors.toList()); //
extensionElements
.forEach(baseElement -> scanInputs(baseElement)); //
extensionElements
.forEach(baseElement -> scanOutputs(baseElement)); //
}
private void scanInputs(FlowElement baseElement) {
baseElement.getExtensionElements().getElements().stream() //
.filter(extensionElement -> extensionElement.getElementType().getTypeName().equals(INPUT_OUTPUT_NAME)) //
.flatMap(formData -> formData.getChildElementsByType(CamundaInputParameter.class).stream()) //
.map(inputParameter -> ((CamundaInputParameter) inputParameter)) //
.forEach(inputParameter -> insertInputParameter(baseElement, inputParameter)); //
}
private void insertInputParameter(FlowElement baseElement, CamundaInputParameter inputParameter) {
//Input-Format --> Text muss verwendet werden
//<camunda:inputParameter name="ExternalServiceVariable">${ProcessVariable}</camunda:inputParameter>
String textContent = inputParameter.getTextContent();
List<String> variables = extractVariables(textContent);
if(!variables.isEmpty()) {
bpmnIOParameters.addInputVariables(baseElement.getId(), variables);
} else {
//If no variables extracted --> it seems to be a hard set value
//Examples for hardcoded values: ${5}, ${true}, Teststring
addHardcodedInputVariable(baseElement.getId(), inputParameter.getCamundaName(), textContent);
}
}
private void addHardcodedInputVariable(String flowElementId, String inputParameter, String textContent) {
Pattern patternVariableMatch = Pattern.compile(VARIABLE_MATCH_REGEX);
Matcher matcherValue = patternVariableMatch.matcher(textContent);
if(matcherValue.find()) {
String extractedValue = matcherValue.group(1);
if(extractedValue.matches(INT_MATCH_REGEX)) {
bpmnIOParameters.addHardcodedInputParameterLong(flowElementId, inputParameter, Long.valueOf(extractedValue));
} else if(extractedValue.matches(BOOLEAN_MATCH_REGEX)) {
bpmnIOParameters.addHardcodedInputParameterBoolean(flowElementId, inputParameter, Boolean.valueOf(extractedValue));
}
} else {
bpmnIOParameters.addHardcodedInputParameterString(flowElementId, inputParameter, textContent);
}
}
private void scanOutputs(FlowElement baseElement) {
baseElement.getExtensionElements().getElements().stream() //
.filter(extensionElement -> extensionElement.getElementType().getTypeName().equals(INPUT_OUTPUT_NAME)) //
.flatMap(formData -> formData.getChildElementsByType(CamundaOutputParameter.class).stream()) //
.map(outputParameter -> ((CamundaOutputParameter) outputParameter)) //
.forEach(outputParameter -> insertOutputParameter(baseElement, outputParameter)); //
}
private void insertOutputParameter(FlowElement baseElement, CamundaOutputParameter outputParameter) {
//Output-Format --> Name muss verwendet werden
//<camunda:outputParameter name="ProcessVariable">${ExternalServiceVariable}</camunda:outputParameter>
String textContent = outputParameter.getCamundaName();
bpmnIOParameters.addOutputVariable(baseElement.getId(), textContent);
//Auf API-Seite wird der TextContent genutzt - für die Mocks relevant
String innerAPIParameter = outputParameter.getTextContent();
List<String> innerAPIVariables = extractVariables(innerAPIParameter);
innerAPIVariables.forEach(innerAPIVariable -> bpmnIOParameters.addInnerOutputVariable(baseElement.getId(), innerAPIVariable));
}
public BPMNIOParameters getBpmnIOParameters() {
return bpmnIOParameters;
}
private List<String> extractVariables(String ioParameter) {
List<String> variableMatches = new ArrayList<>();
Pattern patternVariableMatch = Pattern.compile(VARIABLE_MATCH_REGEX);
Matcher matcherVariable = patternVariableMatch.matcher(ioParameter);
while (matcherVariable.find()) {
String extractedVariable = matcherVariable.group(1);
if(!extractedVariable.matches(INT_MATCH_REGEX) && !extractedVariable.matches(BOOLEAN_MATCH_REGEX)) {
variableMatches.add(extractedVariable);
}
}
return variableMatches;
}
}
package de.fhmuenster.masterthesis.Testgenerator.bpmn.processfragmentation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.camunda.bpm.model.bpmn.instance.BaseElement;
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.CamundaOutputParameter;
import org.camunda.bpm.model.xml.instance.ModelElementInstance;
import de.fhmuenster.masterthesis.Testgenerator.bpmn.data.BPMNFlowSet;
import de.fhmuenster.masterthesis.Testgenerator.bpmn.data.BPMNIOParameters;
import de.fhmuenster.masterthesis.testgeneratorDSL.Variable;
public class BPMNVariableIOScanner {
private static final String VARIABLE_MATCH_REGEX = "\\$\\{(.*?)\\}";
private static final String INT_MATCH_REGEX = "[0-9]+";
private static final String BOOLEAN_MATCH_REGEX = "true|false";
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 EXECUTION_LISTENER = "executionListener";
private BPMNFlowSet flowSet;
private BPMNIOParameters bpmnIOParameters;
public BPMNVariableIOScanner(BPMNFlowSet flowSet) {
this.flowSet = flowSet;
this.bpmnIOParameters = new BPMNIOParameters();
}
public void doScan() {
List<FlowElement> extensionElements = flowSet.getFlowElements().stream() //
.filter(baseElement -> ((BaseElement) baseElement).getExtensionElements() != null) //
.collect(Collectors.toList()); //
extensionElements
.forEach(baseElement -> scanInputs(baseElement)); //
extensionElements
.forEach(baseElement -> scanOutputs(baseElement)); //
/*
* @Tim @Henning
* added routine to scan in Camunda the removeExpressions
*/
extensionElements
.forEach(baseElement -> scanRemoveExpressions(baseElement)); //
}
private void scanInputs(FlowElement baseElement) {
baseElement.getExtensionElements().getElements().stream() //
.filter(extensionElement -> extensionElement.getElementType().getTypeName().equals(INPUT_OUTPUT_NAME)) //
.flatMap(formData -> formData.getChildElementsByType(CamundaInputParameter.class).stream()) //
.map(inputParameter -> ((CamundaInputParameter) inputParameter)) //
.forEach(inputParameter -> insertInputParameter(baseElement, inputParameter)); //
}
private void insertInputParameter(FlowElement baseElement, CamundaInputParameter inputParameter) {
//Input-Format --> Text muss verwendet werden
//<camunda:inputParameter name="ExternalServiceVariable">${ProcessVariable}</camunda:inputParameter>
String textContent = inputParameter.getTextContent();
List<String> variables = extractVariables(textContent);
if(!variables.isEmpty()) {
bpmnIOParameters.addInputVariables(baseElement.getId(), variables);
} else {
//If no variables extracted --> it seems to be a hard set value
//Examples for hardcoded values: ${5}, ${true}, Teststring
addHardcodedInputVariable(baseElement.getId(), inputParameter.getCamundaName(), textContent);
}
}
private void addHardcodedInputVariable(String flowElementId, String inputParameter, String textContent) {
Pattern patternVariableMatch = Pattern.compile(VARIABLE_MATCH_REGEX);
Matcher matcherValue = patternVariableMatch.matcher(textContent);
if(matcherValue.find()) {
String extractedValue = matcherValue.group(1);
if(extractedValue.matches(INT_MATCH_REGEX)) {
bpmnIOParameters.addHardcodedInputParameterLong(flowElementId, inputParameter, Long.valueOf(extractedValue));
} else if(extractedValue.matches(BOOLEAN_MATCH_REGEX)) {
bpmnIOParameters.addHardcodedInputParameterBoolean(flowElementId, inputParameter, Boolean.valueOf(extractedValue));
}
} else {
bpmnIOParameters.addHardcodedInputParameterString(flowElementId, inputParameter, textContent);
}
}
private void scanOutputs(FlowElement baseElement) {
baseElement.getExtensionElements().getElements().stream() //
.filter(extensionElement -> extensionElement.getElementType().getTypeName().equals(INPUT_OUTPUT_NAME)) //
.flatMap(formData -> formData.getChildElementsByType(CamundaOutputParameter.class).stream()) //
.map(outputParameter -> ((CamundaOutputParameter) outputParameter)) //
.forEach(outputParameter -> insertOutputParameter(baseElement, outputParameter)); //
}
private void insertOutputParameter(FlowElement baseElement, CamundaOutputParameter outputParameter) {
//Output-Format --> Name muss verwendet werden
//<camunda:outputParameter name="ProcessVariable">${ExternalServiceVariable}</camunda:outputParameter>
String textContent = outputParameter.getCamundaName();
bpmnIOParameters.addOutputVariable(baseElement.getId(), textContent);
//Auf API-Seite wird der TextContent genutzt - für die Mocks relevant
String innerAPIParameter = outputParameter.getTextContent();
List<String> innerAPIVariables = extractVariables(innerAPIParameter);
innerAPIVariables.forEach(innerAPIVariable -> bpmnIOParameters.addInnerOutputVariable(baseElement.getId(), innerAPIVariable));
}
public BPMNIOParameters getBpmnIOParameters() {
return bpmnIOParameters;
}
private List<String> extractVariables(String ioParameter) {
List<String> variableMatches = new ArrayList<>();
Pattern patternVariableMatch = Pattern.compile(VARIABLE_MATCH_REGEX);
Matcher matcherVariable = patternVariableMatch.matcher(ioParameter);
while (matcherVariable.find()) {
String extractedVariable = matcherVariable.group(1);
if(!extractedVariable.matches(INT_MATCH_REGEX) && !extractedVariable.matches(BOOLEAN_MATCH_REGEX)) {
variableMatches.add(extractedVariable);
}
}
return variableMatches;
}
/**
* 15.12.2021
* insert removeVariables to BPMNIOParameters
* @param baseElement
*/
private void insertRemoveVariable(FlowElement baseElement, String removeVar)
{
bpmnIOParameters.addRemoveVariable(baseElement.getId(), removeVar);
}
/**
* 15.12.2021
* Scan for removeExpressions
* @param baseElement
*/
private void scanRemoveExpressions(FlowElement baseElement) {
Collection<ModelElementInstance> elements = baseElement.getExtensionElements().getElements();
for(ModelElementInstance currentElement : elements)
{
if(currentElement.getElementType().getTypeName().equals(EXECUTION_LISTENER))
{
List<org.camunda.bpm.model.xml.type.attribute.Attribute<?>> expressionList = currentElement.getElementType().getAttributes();
for(org.camunda.bpm.model.xml.type.attribute.Attribute expression : expressionList)
{
try
{
List<String> removeVars = new ArrayList<String>();
switch(expression.getAttributeName())
{
case "delegateExpression":
String strExpression = expression.getValue(currentElement).toString();
Pattern pattern = Pattern.compile("\"(.*?)\"", Pattern.DOTALL);
Matcher matcher = pattern.matcher(strExpression);
while (matcher.find()) {
removeVars.add(matcher.group(1)); // Contains String with all variables from removeVar Expression
}
break;
default:
break;
}
if(!removeVars.isEmpty() && removeVars!=null)
{
// add the removeVariables to BPMNIOParameters via. insertRemoveVariables
removeVars.forEach(var -> this.insertRemoveVariable(baseElement, var));
}
}
catch(Exception e)
{
System.out.println("[ERROR] " + e.getMessage());
}
}
}
}
}
}
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