<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
jBPM 4 - Deploy only if ProcessDefinition changed or new
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/rapa">rapa</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/570056#570056">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I successfully integrated jBPM 4.4 with Seam 2.2, running on JBoss 4.2. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In my overridden Jbpm class I deploy all process definitions, which are got from the components.xml </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml">
   <span class="jive-xml-tag"><bpm:jbpm></span>
        <span class="jive-xml-tag"><bpm:process-definitions></span>
            <span class="jive-xml-tag"><value></span>bpm/processdefinitions/process_1.jpdl.xml<span class="jive-xml-tag"></value></span>
            <span class="jive-xml-tag"><value></span>bpm/processdefinitions/process_2.jpdl.xml<span class="jive-xml-tag"></value></span>
            <span class="jive-xml-tag"><value></span>bpm/processdefinitions/process_3.jpdl.xml<span class="jive-xml-tag"></value></span>        <span class="jive-xml-tag"></bpm:process-definitions></span>
    <span class="jive-xml-tag"></bpm:jbpm></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">    <bpm:jbpm></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">        <bpm:process-definitions></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            <value>bpm/processdefinitions/partner_registration.jpdl.xml</value></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">        </bpm:process-definitions></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">    </bpm:jbpm></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The process definitions file paths (resource names) are automatically injected in the String[] processDefinitions array (see Jbpm class)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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</p><p>I restart my application server.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>There is a method in the repository service that allows to get the deployed process definition's xml content</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">repositoryService.getResourceAsStream(deploymentId, resourceName);
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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</p><p>a way to retrieve what I need.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Here is the code of my Jbpm class.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@Name(<font color="red">"jbpm"</font>)
@Scope(ScopeType.APPLICATION)
@AutoCreate
@Startup
@BypassInterceptors
@Install(precedence = Install.APPLICATION)
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> Jbpm <font color="navy"><b>extends</b></font> SeamComponent <font color="navy">{</font>
     
    @Getter
    <font color="navy"><b>private</b></font> ProcessEngine processEngine;
    @Getter @Setter
    <font color="navy"><b>private</b></font> String[] processDefinitions;
   
    @Create
    <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> init() <font color="navy">{</font>
       <font color="darkgreen">// ...</font>
 
       deployProcessDefinitions();
 
       <font color="darkgreen">// ...</font>
    <font color="navy">}</font>
 
   <font color="darkgreen">/**
     * Deploys all changed or new process definitions.
     */</font>
    <font color="navy"><b>private</b></font> <font color="navy"><b>void</b></font> deployProcessDefinitions() <font color="navy">{</font>
       
      RepositoryService repositoryService = this.processEngine.getRepositoryService();
      <font color="navy"><b>for</b></font> (String processDefinition : this.processDefinitions) <font color="navy">{</font>
 
           <font color="darkgreen">// deploy d only if new or it has changed</font>
           <font color="navy"><b>if</b></font>(isNewOrChanged(processDefinition)) <font color="navy">{</font>
              NewDeployment d = repositoryService.createDeployment()
                                    .addResourceFromClasspath(processDefinition);
              String newDeploymentId = d.deploy();
           <font color="navy">}</font>
 
      <font color="navy">}</font>
 
      <font color="navy"><b>private</b></font> String isNewOrChanged(processDefinition) <font color="navy">{</font>
 
          <font color="darkgreen">// how to get deploymentId???</font>
 
          InputStream is = repositoryService.getResourceAsStream(deploymentId, processDefinition);
          String xml = convertStreamToString(is);
 
          <font color="darkgreen">// ...</font>
      <font color="navy">}</font>
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Anyone has a solution for this?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks, cheers!</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/570056#570056">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>