cancel
Showing results for 
Search instead for 
Did you mean: 

Loss of ID when converting BpmnToJson

eee
Champ in-the-making
Champ in-the-making
Hello,
I'm trying to convert Bpmn model (bpmn20.xml) to Json format for a new editor. There are problems with conversion values in "formProperty".
Example source text:


<formProperty id="priority" name="уровень срочности:" required="false" type="enum" variable="priority" writable="false">
   <value id="3" name="на заказ (от 2 недель)"/>
   <value id="2" name="средний (до 2 недель)"/>
   <value id="1" name="высокий ( от 1 до 3 дней)"/>
</formProperty>



After converting using BpmnJsonConverter I get the following:


"id": "priority",
"name": "уровень срочности:",
"type": "enum",
"expression": null,
"variable": "priority",
"enumValues": [{
   "value": "на заказ (от 2 недель)"
   }, {
   "value": "средний (до 2 недель)"
   }, {
   "value": "высокий ( от 1 до 3 дней)"
}],
"required": false,
"readable": true,
"writable": false


It is evident that the ID information has not been converted.
Looking at the source code I found the place where this information is discarded (org.activiti.editor.language.json.converter.BaseBpmnJsonConverter.java:417)



if (CollectionUtils.isNotEmpty(property.getFormValues())) {
                ArrayNode valuesNode = objectMapper.createArrayNode();
                for (FormValue formValue : property.getFormValues()) {
                    ObjectNode valueNode = objectMapper.createObjectNode();
          valueNode.put("value", formValue.getName());
                    valuesNode.add(valueNode);
                }
                propertyItemNode.put(PROPERTY_FORM_ENUM_VALUES, valuesNode);
            }



In valuesNode only added the field "value".
The reverse converting Json to Bpmn in the field "id" and "name" of Bpmn model will copy one field value from Json (org.activiti.editor.language.json.converter.BaseBpmnJsonConverter.java:522):


FormValue formValue = new FormValue();
formValue.setId(enumNode.get("value").asText());
formValue.setName(enumNode.get("value").asText());
formValueList.add(formValue);


Is this a bug? How can I store the ID?

In our system, the id field is often used: to sort, to highlight the system values, etc.

thanks
7 REPLIES 7

jbarrez
Star Contributor
Star Contributor
You've pretty much have the whole bug analysed and already proposed a fix 🙂
Would you be willing to submit a pull request with these code changes?

kotslon
Champ in-the-making
Champ in-the-making

vasile_dirla
Star Contributor
Star Contributor
@kotslon, thanks for your contribution.
would be great if you could add also some tests for your changes.

Your PR will be reviewed and merged as soon as possible.

kotslon
Champ in-the-making
Champ in-the-making
It's strange: existing tests don't fail, because here: https://github.com/Activiti/Activiti/blob/master/modules/activiti-json-converter/src/test/java/org/a...   `userTask.getFormProperties()` always gives an empty list.

vasile_dirla
Star Contributor
Star Contributor
Hmm yes, as you said: userTask.getFormProperties() is always empty then the "for" block is skipped every time.
We have to review and fix this test, it must have a check for the formPropertyList length before iterating through the list.

Thanks for rising this flag, it seems the test must be improved.

kotslon
Champ in-the-making
Champ in-the-making
https://github.com/Activiti/Activiti/pull/703

1. Fix enum values in editor and converter:
    * `id` and `name` instead of single `value`.
2. Fix form properties test:
    * check the size of form properties list
    * use json instead of string for `formproperties` in test fixture file `test.formpropertiesmodel.json`
    * `id` and `name` of `enumValues` are changed to be different.

vasile_dirla
Star Contributor
Star Contributor
@kotslon,
Thanks, just had a look over your pull request, and it covers the issues I saw yesterday in this test. Smiley Wink
nicely done!

I also have some changes for the form properties test with XML data. (when these 2 will be merged the form properties test is complete)