Skip to content

Commit

Permalink
AF-2811: Required Process Variable Tags shouldn't be accepted in form…
Browse files Browse the repository at this point in the history
…s when empty (#1486)

* Added tags to Display settings

(cherry picked from commit be825ab)
  • Loading branch information
akumar074 committed Apr 16, 2021
1 parent 8b5258f commit 1f1a923
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ProcessRenderingSettings implements RenderingSettings {

private ProcessDefinition process;
private Map<String, String> processData;
private Map<String, String[]> processVariableTags;
private String serverTemplateId;
private String formContent;
private ContentMarshallerContext marshallerContext;
Expand All @@ -41,6 +42,20 @@ public ProcessRenderingSettings(ProcessDefinition process,
this.marshallerContext = marshallerContext;
}

public ProcessRenderingSettings(ProcessDefinition process,
Map<String, String> processData,
Map<String, String[]> processVariableTags,
String serverTemplateId,
String formContent,
ContentMarshallerContext marshallerContext) {
this.process = process;
this.processData = processData;
this.processVariableTags = processVariableTags;
this.serverTemplateId = serverTemplateId;
this.formContent = formContent;
this.marshallerContext = marshallerContext;
}

public ProcessDefinition getProcess() {
return process;
}
Expand All @@ -57,6 +72,15 @@ public void setProcessData(Map<String, String> processData) {
this.processData = processData;
}

@Override
public Map<String, String[]> getProcessVariableTags() {
return processVariableTags;
}

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

@Override
public String getServerTemplateId() {
return serverTemplateId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jbpm.workbench.forms.service.providing;

import java.io.Serializable;
import java.util.Map;

import org.kie.internal.task.api.ContentMarshallerContext;

Expand Down Expand Up @@ -49,4 +50,9 @@ public interface RenderingSettings extends Serializable {
* Sets the ContentMarshallerContext
*/
void setMarshallerContext(ContentMarshallerContext marshallerContext);

/**
* Returns the ProcessVariables Tags info
*/
Map<String, String[]> getProcessVariableTags();
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ public ContentMarshallerContext getMarshallerContext() {
public void setMarshallerContext(ContentMarshallerContext marshallerContext) {
this.marshallerContext = marshallerContext;
}

@Override
public Map<String, String[]> getProcessVariableTags() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ protected FormRenderingSettings getEmbeddedFormDisplayProcess(String serverTempl
processId);
ProcessRenderingSettings settings = new ProcessRenderingSettings(processDesc,
processData,
processDefinition.getTagsByVariable(),
serverTemplateId,
formContent,
new ContentMarshallerContext(null,
Expand All @@ -306,6 +307,7 @@ protected FormRenderingSettings getEmbeddedFormDisplayProcess(String serverTempl
return renderDefaultProcessForm(serverTemplateId,
processDesc,
processData,
processDefinition.getTagsByVariable(),
kieServicesClient);
}

Expand All @@ -326,10 +328,12 @@ private FormRenderingSettings renderDefaultTaskForm(String serverTemplateId,
private FormRenderingSettings renderDefaultProcessForm(String serverTemplateId,
org.jbpm.workbench.forms.service.providing.model.ProcessDefinition processDesc,
Map<String, String> processData,
Map<String, String[]> tagsByVariable,
KieServicesClient kieServicesClient) {
try {
return defaultFormProvider.render(new ProcessRenderingSettings(processDesc,
processData,
tagsByVariable,
serverTemplateId,
"",
new ContentMarshallerContext(null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.jbpm.workbench.forms.display.backend.provider;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -98,6 +99,12 @@ protected Collection<FormDefinition> generateDefaultFormsForContext(ProcessRende
}

private ModelProperty generateModelProperty(String name, String type, ProcessRenderingSettings settings) {
Map<String, String[]> tags = settings.getProcessVariableTags();
if(tags != null) {
boolean required = Arrays.stream(tags.get(name)).anyMatch(tag -> tag.equals("required"));
boolean readonly = Arrays.stream(tags.get(name)).anyMatch(tag -> tag.equals("readonly"));
return BPMNVariableUtils.generateVariableProperty(name, type, required, readonly, settings.getMarshallerContext().getClassloader());
}
return BPMNVariableUtils.generateVariableProperty(name, type, settings.getMarshallerContext().getClassloader());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public void testGenerateRenderingContextWithoutForms() {
true);

checkGeneratedContext();
verifyProcessVariablesTags(renderingSettings,
kieWorkbenchFormRenderingSettings);
}

protected void checkGeneratedContext() {
Expand Down Expand Up @@ -292,4 +294,7 @@ protected Map<String, Object> getFormValues() {
abstract PROCESSOR getProcessorInstance(FormDefinitionSerializer serializer,
BackendFormRenderingContextManager backendFormRenderingContextManager,
DynamicBPMNFormGenerator dynamicBPMNFormGenerator);

abstract void verifyProcessVariablesTags(SETTINGS renderingSettings,
KieWorkbenchFormRenderingSettings kieWorkbenchFormRenderingSettings);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import java.util.HashMap;
import java.util.Map;

import org.jbpm.workbench.forms.display.api.KieWorkbenchFormRenderingSettings;
import org.jbpm.workbench.forms.display.backend.provider.model.Invoice;
import org.jbpm.workbench.forms.display.backend.provider.util.FormContentReader;
import org.jbpm.workbench.forms.service.providing.ProcessRenderingSettings;
import org.jbpm.workbench.forms.service.providing.model.ProcessDefinition;
import org.junit.Assert;
import org.junit.runner.RunWith;
import org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.BackendFormRenderingContextManager;
import org.kie.workbench.common.forms.fields.test.TestMetaDataEntryManager;
Expand Down Expand Up @@ -60,6 +62,17 @@ ProcessFormsValuesProcessor getProcessorInstance(FormDefinitionSerializer serial
dynamicBPMNFormGenerator);
}

@Override
void verifyProcessVariablesTags(ProcessRenderingSettings renderingSettings,
KieWorkbenchFormRenderingSettings kieWorkbenchFormRenderingSettings) {
Assert.assertTrue(kieWorkbenchFormRenderingSettings.getRenderingContext()
.getAvailableForms().get("invoices-taskform")
.getFieldByName("invoice").getRequired());
Assert.assertTrue(kieWorkbenchFormRenderingSettings.getRenderingContext()
.getAvailableForms().get("invoices-taskform")
.getFieldByName("invoice").getReadOnly());
}

@Override
ProcessRenderingSettings getFullRenderingSettings() {
return getRenderSettings(FormContentReader.getStartProcessForms());
Expand All @@ -72,12 +85,16 @@ ProcessRenderingSettings getRenderingSettingsWithoutForms() {

private ProcessRenderingSettings getRenderSettings(String formContent) {
Map<String, String> formData = new HashMap<>();
Map<String, String[]> processVariableTags = new HashMap<>();

formData.put("invoice",
Invoice.class.getName());
processVariableTags.put("invoice",
new String[]{"required", "readonly"});

return new ProcessRenderingSettings(process,
formData,
processVariableTags,
SERVER_TEMPLATE_ID,
formContent,
marshallerContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;

import org.jbpm.workbench.forms.display.api.KieWorkbenchFormRenderingSettings;
import org.jbpm.workbench.forms.display.backend.provider.model.Client;
import org.jbpm.workbench.forms.display.backend.provider.model.Invoice;
import org.jbpm.workbench.forms.display.backend.provider.model.InvoiceLine;
Expand Down Expand Up @@ -108,4 +109,10 @@ TaskFormValuesProcessor getProcessorInstance(FormDefinitionSerializer serializer
backendFormRenderingContextManager,
dynamicBPMNFormGenerator);
}

@Override
void verifyProcessVariablesTags(TaskRenderingSettings renderingSettings,
KieWorkbenchFormRenderingSettings kieWorkbenchFormRenderingSettings) {

}
}

0 comments on commit 1f1a923

Please sign in to comment.