Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AF-2811: Required Process Variable Tags shouldn't be accepted in forms when empty #2450

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class ProcessDefinition {
private Collection<NodeDefinition> nodes;
@XmlElementWrapper(name = "timers")
private Collection<TimerDefinition> timers;
@XmlElementWrapper(name = "tags")
private Map<String, String[]> tagsByVariable;

@XmlElement(name = "dynamic")
private boolean dynamic;
Expand Down Expand Up @@ -132,6 +135,14 @@ public void setProcessVariables(Map<String, String> processVariables) {
this.processVariables = processVariables;
}

public Map<String, String[]> getTagsByVariable() {
return tagsByVariable;
}

public void setTagsByVariable(Map<String, String[]> tagsByVariable) {
this.tagsByVariable = tagsByVariable;
}

public Collection<String> getReusableSubProcesses() {
return reusableSubProcesses;
}
Expand Down Expand Up @@ -178,6 +189,7 @@ public String toString() {
", reusableSubProcesses=" + reusableSubProcesses +
", nodes=" + nodes +
", timers=" + timers +
", tagsByVariable=" + tagsByVariable +
", dynamic=" + dynamic +
'}';
}
Expand Down Expand Up @@ -247,6 +259,16 @@ public Builder subprocesses(Collection<String> subprocesses) {
return this;
}

public Builder tagsByVariables(Map<String, Set<String>> tagsByVariables) {
Map<String, String[]> data = new HashMap<String, String[]>();

for (Map.Entry<String, Set<String>> entry : tagsByVariables.entrySet()) {
data.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
}
definition.setTagsByVariable(data);
return this;
}

public Builder dynamic(boolean dynamic) {
definition.setDynamic(dynamic);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -260,6 +261,9 @@ protected FormInstance generateDefaultProcessForm(ProcessDefinition processDesc)
field.setName(entry.getKey());
field.setType(entry.getValue());
field.setTags(processDesc.getTagsForVariable(entry.getKey()));
Set<String> tags = processDesc.getTagsForVariable(entry.getKey());
field.setRequired(tags.contains("required"));
field.setReadOnly(tags.contains("readonly"));

form.getFields().add(field);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Optional;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -119,7 +120,7 @@ public void configure(String serverPath, String resources) {
}

public String renderCase(String containerId, CaseDefinition caseDefinition, FormInstance form) {
List<String> scriptDataList = new ArrayList<>();
List<String> scriptDataList = new ArrayList<>();


StringBuilder jsonTemplate = new StringBuilder();
Expand Down Expand Up @@ -449,9 +450,14 @@ protected void processFormLayout(FormInstance topLevelForm,
item.setValue((value != null) ? value.toString() : "");
break;
}

item.setReadOnly(field.isReadOnly());
item.setRequired(field.isRequired());
Set<String> tags = field.getTags();
if (tags != null) {
item.setRequired(tags.contains("required"));
item.setReadOnly(tags.contains("readonly"));
} else {
item.setRequired(field.isRequired());
item.setReadOnly(field.isReadOnly());
}

// generate column content
Map<String, Object> parameters = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function clearNotifications() {
}

function startProcess(button) {
if (validate()) {
if (validate('')) {
button.disabled = true;

console.log('Process started with data ' + JSON.stringify(getData()));
Expand Down Expand Up @@ -61,7 +61,7 @@ function startProcess(button) {
}

function startCase(button) {
if (validate()) {
if (validate('')) {
button.disabled = true;

$.ajax({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
import org.slf4j.LoggerFactory;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FormRendererBaseTest {

Expand Down Expand Up @@ -82,13 +87,22 @@ public void testGenerateDefaultFormWithVariables() {
ProcessDefinition processDefinition = mock(ProcessDefinition.class);
when(processDefinition.getId()).thenReturn("testprocess");
when(processDefinition.getName()).thenReturn("Test Process");

Map<String, String> variables = new HashMap<>();
variables.put("name", "java.lang.String");
variables.put("age", "java.lang.Integer");
variables.put("maried", "java.lang.Boolean");
when(processDefinition.getProcessVariables()).thenReturn(variables);

Map<String, Set<String>> tags = new HashMap<>();
Set<String> tags1 = new HashSet<>();
tags1.add("required");
Set<String> tags2 = new HashSet<>();
tags2.add("readonly");
tags.put("name", tags1);
tags.put("maried", tags2);
when(processDefinition.getTagsInfo()).thenReturn(tags);
when(processDefinition.getTagsForVariable(eq("name"))).thenReturn(tags1);
when(processDefinition.getTagsForVariable(eq("maried"))).thenReturn(tags2);
FormRendererBase rendererBase = new FormRendererBase(definitionService, userTaskService, formManagerService, caseRuntimeDataService, registry);

when(registry.getContainerId(any(), any())).thenReturn("test");
Expand All @@ -108,8 +122,12 @@ public void testGenerateDefaultFormWithVariables() {
assertThat(result).contains("<h3 class=\"panel-title\">Default form - Test Process</h3>");

// it has all three variables rendered
assertThat(result).contains("<input name=\"maried\" type=\"checkbox\" class=\"form-control\" ");
assertThat(result).contains("<input name=\"name\" type=\"text\" class=\"form-control\" ");
Pattern namePattern = Pattern.compile("<input name=\"name\" type=\"text\" class=\"form-control\".*required.*>");
Matcher nameMatcher = namePattern.matcher(result);
assertTrue(nameMatcher.find());
Pattern mariedPattern = Pattern.compile("<input name=\"maried\" type=\"checkbox\" class=\"form-control\".*readonly.*>");
Matcher mariedMatcher = mariedPattern.matcher(result);
assertTrue(mariedMatcher.find());
assertThat(result).contains("<input name=\"age\" type=\"text\" class=\"form-control\" ");
// it has start process button
assertThat(result).contains("<button type=\"button\" class=\"btn btn-primary\" onclick=\"startProcess(this);\">Submit</button>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public org.kie.server.api.model.definition.ProcessDefinition getProcessDefinitio
.serviceTasks(procDef.getServiceTasks())
.subprocesses(procDef.getReusableSubProcesses())
.variables(procDef.getProcessVariables())
.tagsByVariables(procDef.getTagsInfo())
.dynamic(procDef.isDynamic())
.nodes(procDef.getNodes().stream().map(node -> NodeDefinition.builder().id(node.getId()).name(node.getName()).type(node.getNodeType()).uniqueId(node.getUniqueId()).build()).collect(toSet()))
.timers(procDef.getTimers().stream().map(timer -> TimerDefinition.builder().id(timer.getId()).nodeId(timer.getNodeId()).nodeName(timer.getNodeName()).uniqueId(timer.getUniqueId()).build()).collect(toSet()))
Expand Down