jBPM 4 - Deploy only if ProcessDefinition changed or new
rapa Nov 8, 2010 6:20 AMHi,
I successfully integrated jBPM 4.4 with Seam 2.2, running on JBoss 4.2.
In my overridden Jbpm class I deploy all process definitions, which are got from the components.xml
<bpm:jbpm> <bpm:process-definitions> <value>bpm/processdefinitions/process_1.jpdl.xml</value> <value>bpm/processdefinitions/process_2.jpdl.xml</value> <value>bpm/processdefinitions/process_3.jpdl.xml</value> </bpm:process-definitions> </bpm:jbpm>
The process definitions file paths (resource names) are automatically injected in the String[] processDefinitions array (see Jbpm class)
By having all file paths it is easy to deploy the process definitions through the repository service, but I would like to avoid to deploy them each time
I restart my application server.
What I would like to do is to deploy my process definitions only if the xml file is new or has been modified since it's last deployment. The idea is simple: I just compare the last deployed process definition's xml content with the one of the current process definition.
There is a method in the repository service that allows to get the deployed process definition's xml content
repositoryService.getResourceAsStream(deploymentId, resourceName);
I see that the jbpm4_lob table is the one that contains all the required data (resource_names, deployment_ids, xml files contents), so there must be
a way to retrieve what I need.
The problem is that I looked into the jbpm 4.4 api and I don't see any way to retrieve the highest deploymentId for a given resource name. The only way is to use the process definition key or name, but I would have to map these manually somewhere to their resource name or parse the xml files, which would be very nasty and I absolutely want to avoid that.
Here is the code of my Jbpm class.
@Name("jbpm") @Scope(ScopeType.APPLICATION) @AutoCreate @Startup @BypassInterceptors @Install(precedence = Install.APPLICATION) public class Jbpm extends SeamComponent { @Getter private ProcessEngine processEngine; @Getter @Setter private String[] processDefinitions; @Create public void init() { // ... deployProcessDefinitions(); // ... } /** * Deploys all changed or new process definitions. */ private void deployProcessDefinitions() { RepositoryService repositoryService = this.processEngine.getRepositoryService(); for (String processDefinition : this.processDefinitions) { // deploy d only if new or it has changed if(isNewOrChanged(processDefinition)) { NewDeployment d = repositoryService.createDeployment() .addResourceFromClasspath(processDefinition); String newDeploymentId = d.deploy(); } } private String isNewOrChanged(processDefinition) { // how to get deploymentId??? InputStream is = repositoryService.getResourceAsStream(deploymentId, processDefinition); String xml = convertStreamToString(is); // ... }
Anyone has a solution for this?
Thanks, cheers!