-
Bug Report
-
Resolution: Fixed
-
L3 - Default
-
7.16.0, 7.17.0-alpha1
Environment (Required on creation):
- Camunda Platform 7.16.0
- all distros
Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket):
Adjusting the formKey of a user task via TaskDefinition#setFormKey from a BpmnParseListener is not considered when retrieving the formKey to display the form in the web apps.
The app parseListener7-16.zip contains a parse listener that changes the form keys on deployment.
In the console of the IDE you find log output like
2021-11-05 12:14:39.760 INFO 19120 --- [nio-8082-exec-5] c.c.consulting.parser.FormKeyAdaptor : FormKey: embedded:deployment:/members-of-board.html 2021-11-05 12:14:39.761 INFO 19120 --- [nio-8082-exec-5] c.c.consulting.parser.FormKeyAdaptor : FormKey changed to: embedded:app:members-of-board.html 2021-11-05 12:14:39.761 INFO 19120 --- [nio-8082-exec-5] c.c.consulting.parser.FormKeyAdaptor : FormKey: embedded:app:members-of-board.html 2021-11-05 12:14:39.761 INFO 19120 --- [nio-8082-exec-5] c.c.consulting.parser.FormKeyAdaptor : FormKey changed to: embedded:app:members-of-board.html 2021-11-05 12:14:39.763 INFO 19120 --- [nio-8082-exec-5] c.c.consulting.parser.FormKeyAdaptor : FormKey: embedded:deployment:/sanction-search-result.html 2021-11-05 12:14:39.763 INFO 19120 --- [nio-8082-exec-5] c.c.consulting.parser.FormKeyAdaptor : FormKey changed to: embedded:app:sanction-search-result.html 2021-11-05 12:14:39.763 INFO 19120 --- [nio-8082-exec-5] c.c.consulting.parser.FormKeyAdaptor : FormKey: embedded:app:sanction-search-result.html
The parse listener seems to work correctly, but it shows no effect in the Tasklist.
If you switch back to 7.15.0, the parse listener works as expected.
Steps to reproduce (Required on creation):
- Unzip the attached spring boot application parseListener7-16.zip
- Start the application in your IDE
- Login to http://localhost:8082/
- Open Tasklist
- Start a process instance
- Enter values "a" and "b" on the generated start form and start the process instance.
- See a "Form failure: The form with the resource name '/members-of-board.html' cannot be found in deployment with id 64c8962c-3c20-11ec-ac20-3ce1a1c19785"
Observed Behavior (Required on creation):
Changing the UserTask's formKey property in a BpmnParseListener no longer works.
Expected behavior (Required on creation):
Changing the UserTask's formKey property in a BpmnParseListener via the TaskDefinition class is picked up by the web apps when displaying the form.
Root Cause (Required on prioritization):
With this commit, CP now saves parts of the model information in two spots:
- TaskDefinition - we have always had the information there, for example, the "formKey"
- DefaultFormHandler - the class is not new, saving the form information from the model there however is new. It is used when fetching the necessary form data to display a form now instead of the TaskDefinition.
Because of this, adjusting the TaskDefinition has no effect.
Solution Ideas (Optional):
- Store the formKey information in one location again (i.e. the attributes at https://github.com/camunda/camunda-bpm-platform/commit/0c1156b76b3967507a4c3f0aeb8cfa4b0437a415#diff-65209bb4a3cd039610a572acb1ad3511a3db894c22be2b4902f48565f04ff15bR71-R76 should be moved to the TaskDefinition)
- The formKey passed on via TaskDefinition#setFormKey is adjusted in that one location
Hints (optional):
Currently, you would have to do something like this in the parse listener:
package com.camunda.consulting.parser; import java.lang.reflect.Field; import org.camunda.bpm.engine.delegate.Expression; import org.camunda.bpm.engine.impl.bpmn.behavior.UserTaskActivityBehavior; import org.camunda.bpm.engine.impl.bpmn.parser.AbstractBpmnParseListener; import org.camunda.bpm.engine.impl.el.ExpressionManager; import org.camunda.bpm.engine.impl.form.handler.DefaultFormHandler; import org.camunda.bpm.engine.impl.form.handler.DefaultTaskFormHandler; import org.camunda.bpm.engine.impl.form.handler.DelegateTaskFormHandler; import org.camunda.bpm.engine.impl.pvm.process.ActivityImpl; import org.camunda.bpm.engine.impl.pvm.process.ScopeImpl; import org.camunda.bpm.engine.impl.util.xml.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class FormKeyAdaptor extends AbstractBpmnParseListener { private static final Logger LOG = LoggerFactory.getLogger(FormKeyAdaptor.class); @Override public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) { LOG.debug("Parsing user task {}", activity.getId()); UserTaskActivityBehavior activityBehavior = (UserTaskActivityBehavior) activity.getActivityBehavior(); DefaultTaskFormHandler formHandler = (DefaultTaskFormHandler) ((DelegateTaskFormHandler) activityBehavior.getTaskDefinition().getTaskFormHandler()).getFormHandler(); Expression formKeyExpression = formHandler.getFormKey(); if (formKeyExpression != null) { String formKeyExpressionText = formKeyExpression.getExpressionText(); LOG.info("FormKey: {}", formKeyExpressionText); String formKeyEmbeddedDeployment = formKeyExpressionText.replace("embedded:deployment:/", "embedded:app:"); ExpressionManager expressionManager = new ExpressionManager(); try { Field formKeyField = DefaultFormHandler.class.getDeclaredField("formKey"); formKeyField.setAccessible(true); formKeyField.set(formHandler, expressionManager.createExpression(formKeyEmbeddedDeployment)); LOG.info("FormKey changed to: {}", activityBehavior.getTaskDefinition().getFormKey().getExpressionText()); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { LOG.warn("Couldn't adjust the formKey in the form handler", e); } } else { LOG.info("Formkey ist null for user task {}", activity.getName()); } } }
Disclaimer:
- This is an internal API so we never guarantee we keep it compatible.
- The workaround code is very tightly coupled to default classes now, it won't work out of the box with custom form handler classes and such that you can configure in the model.