cancel
Showing results for 
Search instead for 
Did you mean: 

How to save CustomProperty with complex value to XML?

ajuszkiewicz
Champ in-the-making
Champ in-the-making
I have a "little" problem here in my code…

I have to save more complex value than String as custom property to process XML. So I found out that there is something like ComplexDataType, but it's only totally empty interface. So I implemented my version of it and I'm calling saving then. CustomProperty is added to process' custom properties list, but when I save process definition, nothing appears in XML file…

What am I missing here :?:
6 REPLIES 6

tiesebarrell
Champ in-the-making
Champ in-the-making
To do this, you'll need to tell Activiti Designer how to marshall / unmarshall your ComplexDataType - that also means modifying Designer. Take a look at how the DataGrid type is handled. It's broken at the moment, but the gist of it is in there.

ajuszkiewicz
Champ in-the-making
Champ in-the-making
To do this, you'll need to tell Activiti Designer how to marshall / unmarshall your ComplexDataType - that also means modifying Designer. Take a look at how the DataGrid type is handled. It's broken at the moment, but the gist of it is in there.

I am sorry but could you be more specific? I analyzed the code and didn't find ANY usage of DataGrid apart from 1 in CloneUtil… (I am looking in Activiti Designer 5.9.1). I also found something interesting. In class ServiceTaskExport (which is meant to marshall service task to XML if I', right), interesting stuff happens in lines 81-83:

if (customProperty.getSimpleValue() == null || customProperty.getSimpleValue().length() == 0) {
         continue;
        }

This means that even if I have complex value set in custom property, it's always ignored.

What can I do with this?

tiesebarrell
Champ in-the-making
Champ in-the-making
I'm sorry, I see how that's confusing. It's been such a long time we touched this, that I'd forgotten it myself. To use the DataGrid or any other ComplexDataType, you need to write your own ExportMarshaller. Since you're the only person who probably knows what you want to get from the grid, you're the only person who can write a sensible export for it. That was the thinking back then.

However, at the moment, with the 5.9 releases, ExportMarshallers are not invoked on save. There are plans to re-implement this, but at the moment there's little else to be done than adding your logic by hand. For instance, starting at the point in code that you found already. If you take the marshaller from there, you can write custom XML.

ajuszkiewicz
Champ in-the-making
Champ in-the-making
I hope that it will be fixed in one of next releases and described in user guide (how to write your own ExportMarshaller and where to register it to work) Smiley Happy

For now I 'invented' very dirty workaround - I use my complex object in section but when it comes to saving, I marshal it to String and save value as simple value. Then, when I want to read value from CustomProperty, I have to call unmarshalling manually to get complex object again. It is very ugly, but it works for now…

tiesebarrell
Champ in-the-making
Champ in-the-making
How to write your own ExportMarshaller is in part described in the userguide here http://activiti.org/userguide/index.html#N125AD but it will need to be updated because the API for ExportMarshallers will change. This is unfortunate, but is the only way that makes sense due to changes in the fundamental setup of Designer's model.

You workaround is actually not that far from the only way we could implement this in a generic sense. I think we should add a marshall() / unmarshall() method group to the ComplexDataType interface, so you can marshall and unmarshall to and and from a string format. The string would then be added to a CDATA element in the BPMN. If you need to do any custom processing for output, you should write your own ExportMarshaller anyway, but at least you would be able to get the data in a consistent manner.

tiesebarrell
Champ in-the-making
Champ in-the-making
BTW, this is the issue you can watch to follow along when stuff gets implemented. http://jira.codehaus.org/browse/ACT-1261