cancel
Showing results for 
Search instead for 
Did you mean: 

BPMN model transformation and back

norberts
Champ in-the-making
Champ in-the-making
I'm working on a plugin for Activiti where I can model limited BPMN processes in Activiti and then transform them via my plugin to an internally used workflow graph representation. On that workflow graph I want to run analyses and small further transformations (combination of elements to new ones, splitting up elements or introducing new elements in the graph) via source code. This of course has to be displayed again as BPMN process in the Editor afterwards so the user gets some feedback on how it looks.
This work is meant for educational use in a university, so not really meant for the business world outside yet.

I'm aware of that I have to change Activiti itself for it.
So here's my idea so far: Create a new extension point (or miss/reuse the validator extension point reactivated) on save in the Activiti Editor. I give the BPMN model to the plugin and then I can transform it to whatever I define there. I'm aware of the fact that you want to reintroduce the validation extension point and if you do, I can adapt my solution to it. It's just for now.
Where I'm struggling is on how to give it back to Activiti to display it in the Editor. I first thought of the setEditorInput method but I guess that is reading from the bpmn-file if I understand that correctly?
And I can't just export it into the bpmn file and then reread it, since I want to give the opportunity of rewind automatic changes and I don't want to change the file all the time. So I would need to just adapt the visual model of Activiti.

So my questions are: Is it a good idea to do call the plugin on the save action? Through that I already have the BPMN model and can work on this and hand it over to the plugin. Secondly, do I need to adapt only the BPMN memory model or also the Graphiti diagram manually? Or is the conversion from Activiti to Graphiti somehow magically done inside of Activiti?
And most importantly: How would I be able to give a BPMN model back to Activiti so it is displayed in the Editor? Set the model in the ModelHandler and let the Editor read it out somehow?

Thanks for the time and your patience. Smiley Happy
5 REPLIES 5

tiesebarrell
Champ in-the-making
Champ in-the-making
I would re-enable the ExportMarshaller extension point rather than the validation one, but that doesn't really matter as long as you have a hook to get the model somewhere.

Are you sure you want to show it in the same editor? That would quickly become a mess because you're changing the underlying model and hotswapping the display. This is not typically how Eclipse editors work. Another way to approach this would be to simply enrich the model and then export to a separate BPMN file (which you overwrite each time), living alongside the BPMN file you've opened in the editor. To show that enriched diagram, you simply open the new file with the diagram editor. Then you get all of the editor functionality straight out of the box.

norberts
Champ in-the-making
Champ in-the-making
So, you suggest that you have two files open in the end? But then the same problem happens again, that the second editor should respond to internal changes of the model..
I thought you can change the underlying model and the UI changes to this. Just the normal Model-View pattern. 😕 But I have a hard time to even see how the model is displayed in the Activiti Editor so I get the feeling I am totally wrong here. Not to mention the creation of my own BPMN model or process, that is marshalled correctly into a file using the provided BPMN marshaller.

tiesebarrell
Champ in-the-making
Champ in-the-making
Well, the idea would be that you edit the one, and the second results from that. That avoids having the recursive behavior you mention.

I don't see the problem with generating the BPMN. Aren't you creating something that's BPMN anyway in the enrichment? Then you can simply use the default marshalling from the model, because that's all provided if it's valid BPMN.

norberts
Champ in-the-making
Champ in-the-making
Alright, I'm not sure if you got my idea correct or I don't get yours completely. Smiley Very Happy

Anyway, I kind of succeeded on what I want as a first try. I changed the existing model by just adding a user task. For that I created a new UserTask object and added a new pictogram element surrounded by a new RecordingCommand in the editingDomain of the editor. The addFeature is of type AddTaskFeature from Activiti and is handling the look on it's own. Thanks for that. Smiley Happy
activeEditor.getEditingDomain().getCommandStack()
  .execute(new RecordingCommand(activeEditor.getEditingDomain()) {
    @Override
    protected void doExecute() {
       final AddContext context = new AddContext(new AreaContext(), userTask);
       final IAddFeature addFeature = featureProvider.getAddFeature(context);
       context.setNewObject(userTask);
       context.setLocation(x, y);
       context.setTargetContainer(diagram);
       if (addFeature.canAdd(context)) {
              final PictogramElement add = addFeature.add(context);
              featureProvider.link(add, new Object[] { userTask });
       }
    }
});
The userTask object is also added to the flowElement list of the process in the model.
In the end I call activeEditor.updateDirtyState(); on the editor and it is displayed.
The marshaller also exports it correctly to the xml file.

tiesebarrell
Champ in-the-making
Champ in-the-making
OK, cool looks like you got started.