Skip to content

Commit fd7b575

Browse files
committed
BZ-1069747: returning empty for null variables to not break forms
1 parent cee6883 commit fd7b575

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

jbpm-human-task/jbpm-human-task-core/src/main/java/org/jbpm/services/task/impl/TaskContentServiceImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public long addContent(long taskId, Map<String, Object> params) {
5454
Content outputContent = persistenceContext.findContent(outputContentId);
5555

5656
long contentId = -1;
57-
if (outputContent == null) {
58-
ContentData outputContentData = ContentMarshallerHelper.marshal(params, null);
57+
if (outputContent == null) {
58+
ContentMarshallerContext context = getMarshallerContext(task);
59+
ContentData outputContentData = ContentMarshallerHelper.marshal(params, context.getEnvironment());
5960
Content content = TaskModelProvider.getFactory().newContent();
6061
((InternalContent) content).setContent(outputContentData.getContent());
6162
persistenceContext.persistContent(content);

jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/form/FormProviderServiceImpl.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public int compare(FormProvider o1, FormProvider o2) {
7676
}
7777
}
7878

79-
8079
@Override
8180
public String getFormDisplayProcess(String deploymentId, String processId) {
8281
ProcessAssetDesc processDesc = dataService.getProcessesByDeploymentIdProcessId(deploymentId, processId);
@@ -93,7 +92,9 @@ public String getFormDisplayProcess(String deploymentId, String processId) {
9392

9493
for (FormProvider provider : providers) {
9594
String template = provider.render(processDesc.getName(), processDesc, renderContext);
96-
if (!StringUtils.isEmpty(template)) return template;
95+
if (!StringUtils.isEmpty(template)) {
96+
return template;
97+
}
9798
}
9899

99100
logger.warn("Unable to find form to render for process '{}'", processDesc.getName());
@@ -105,7 +106,7 @@ public String getFormDisplayProcess(String deploymentId, String processId) {
105106
public String getFormDisplayTask(long taskId) {
106107
Task task = taskService.getTaskById(taskId);
107108
if (task == null) {
108-
return "";
109+
return "";
109110
}
110111
String name = task.getNames().get(0).getText();
111112
ProcessAssetDesc processDesc = dataService.getProcessesByDeploymentIdProcessId(task.getTaskData().getDeploymentId(), task.getTaskData().getProcessId());
@@ -152,38 +153,44 @@ public String getFormDisplayTask(long taskId) {
152153

153154
Object value = ((Map<String, Object>) output).get(key);
154155
if (value == null) {
155-
// WM value = "";
156+
value = "";
156157
}
157158
finalOutput.put(key, value);
158159
}
159160

160161

161162
// merge template with process variables
162163
renderContext.put("task", task);
163-
renderContext.put("outputs", finalOutput);
164164
renderContext.put("marshallerContext", marshallerContext);
165165

166166
// add all inputs as direct entries
167167
if (input instanceof Map) {
168168
renderContext.put("inputs", input);
169-
for (Map.Entry<String, Object> inputVar : ((Map<String, Object>)input).entrySet()) {
169+
for (Map.Entry<String, Object> inputVar : ((Map<String, Object>) input).entrySet()) {
170170
renderContext.put(inputVar.getKey(), inputVar.getValue());
171171
}
172172
} else {
173173
renderContext.put("input", input);
174174
}
175175

176+
// add all outputs as direct entries
177+
renderContext.put("outputs", finalOutput);
178+
for (Map.Entry<String, Object> outputVar : ((Map<String, Object>) finalOutput).entrySet()) {
179+
renderContext.put(outputVar.getKey(), outputVar.getValue());
180+
}
181+
176182
// find form
177183
for (FormProvider provider : providers) {
178184
String template = provider.render(name, task, processDesc, renderContext);
179-
if (!StringUtils.isEmpty(template)) return template;
185+
if (!StringUtils.isEmpty(template)) {
186+
return template;
187+
}
180188
}
181189

182190
logger.warn("Unable to find form to render for task '{}' on process '{}'", name, processDesc.getName());
183191
return "";
184192
}
185193

186-
187194
protected ContentMarshallerContext getMarshallerContext(String deploymentId, String processId) {
188195
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
189196
if (deployedUnit == null) {
@@ -192,13 +199,13 @@ protected ContentMarshallerContext getMarshallerContext(String deploymentId, Str
192199
InternalRuntimeManager manager = (InternalRuntimeManager) deployedUnit.getRuntimeManager();
193200
return new ContentMarshallerContext(manager.getEnvironment().getEnvironment(), manager.getEnvironment().getClassLoader());
194201
}
195-
202+
196203
protected ContentMarshallerContext getMarshallerContext(Task task) {
197-
204+
198205
if (task == null) {
199206
return new ContentMarshallerContext();
200207
}
201-
208+
202209
return TaskContentRegistry.get().getMarshallerContext(task);
203210
}
204211
}

jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/form/provider/FreemakerFormProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public abstract class FreemakerFormProvider implements FormProvider {
1414

1515
protected String render(String name, InputStream src, Map<String, Object> renderContext) {
16-
16+
1717
String str = null;
1818
try {
1919
freemarker.template.Configuration cfg = new freemarker.template.Configuration();

0 commit comments

Comments
 (0)