cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing the process definition

frauke
Champ in-the-making
Champ in-the-making
Hello everybody,

is it possible to parse the process definition before the process has been started?
We like to get some information about the tasks before starting the process.

Frauke
13 REPLIES 13

jbarrez
Star Contributor
Star Contributor
That's currently not possible (at least not without casting: you could do it by obtaining a ProcessDefinition through the processDefinitionQuery),
but we have had several request for this so we are currently thinking about incorporating this in the API.

frauke
Champ in-the-making
Champ in-the-making
Ok, can get the process definition:

ProcessDefinition p = processEngine.getRepositoryService()
            .createProcessDefinitionQuery()
            .key(processName).singleResult()
Correct? But what should I cast to? And then how can I get to the definition itself?
Even with the debugger I could not see something helpful in the ProcessDefinition.
Please, could you give me some hints how to proceed, so I don't have to wait for the next release?

jbarrez
Star Contributor
Star Contributor
It;s very low-level PVM code, but this should do it:

cast to ProcessDefinitionImpl. This has an getInitial() method which returns an ActivityImpl.
This ActivityImpl has outgoingTransitions that can be followed to its destinatiins (again ActivityImpl).

But as you would agree, this isnt very pretty to look at 😉

frauke
Champ in-the-making
Champ in-the-making
Oh, it looks pretty enough to me … if it would work like that.
But the getInitial() returns null. :cry:

iravanchi
Champ in-the-making
Champ in-the-making
This issue is what I ran into several days ago, and there's another thread about it:
http://forums.activiti.org/en/viewtopic.php?f=3&t=288

It is null because the process definition is not parsed at that point.
When you start a process, Activiti looks up the cache, and if the process is not in the cache it loads it, parses it (from the bytes of deployment) and puts it into the cache.

Your issue comes up because the definition is not parsed until it is needed for execution by PVM. There will be API for loading it, see here:
http://jira.codehaus.org/browse/ACT-172

Meanwhile, here's a very ugly hack:
If you start the process once, it should be placed in the cache alright. So if you can somehow start a fake instance of the process, that should work for you (I guess).

I'm waiting for my access to be granted on Activiti source code. I can fix this issue quickly if so, and let you know.

-Hamed

falko_menge
Champ in-the-making
Champ in-the-making
To elaborate a bit more on that ugly hack:
The ProcessInstance returned by the startProcessInstanceBy* methods of the RuntimeService contains an introspectable ProcessDefinitionEntity. So either you keep that ProcessDefinitionEntity in memory or you start a fake instance every time you need it.

frauke
Champ in-the-making
Champ in-the-making
Is is possible to start the fake process instance without the process doing something?
Usually if I start the process it starts modifying my system right away and I can't do that.

tombaeyens
Champ in-the-making
Champ in-the-making
method to inspect the process was added http://jira.codehaus.org/browse/ACT-242

iravanchi
Champ in-the-making
Champ in-the-making
ACT-172 is a related issue. You might want to mark it as resolved too.