5 Replies Latest reply on Dec 3, 2007 8:51 AM by chawax

    Dynamic creation of JBPM processes

    chawax

      Hi,

      I need to start a JBPM process, but in some cases I can't use the @CreateProcess annotation since the process I need to start depends on an runtime value. I also need to outject variables to the business process. But I can't find how to do this ...

      What I did :

      - I injected businessProcess component in my class :

      @org.jboss.seam.annotations.In(create = true)
      protected org.jboss.seam.bpm.BusinessProcess businessProcess;


      - I used @Out annotation to outject the variables in my business process :

      @org.jboss.seam.annotations.Out(required = false, scope = org.jboss.seam.ScopeType.BUSINESS_PROCESS)
      protected java.lang.Long idDemandeAbsence;
      
      @org.jboss.seam.annotations.Out(required = false, scope = org.jboss.seam.ScopeType.BUSINESS_PROCESS)
      protected java.lang.String codeMotifAbsence;


      - Then I set these variables and call BusinessProcess.createProcess method :

      protected void handleValider() throws java.lang.Exception {
       this.idDemandeAbsence = this.demandeAbsence.getId();
       this.codeMotifAbsence = this.ligneDemandeAbsence.getMotif();
       this.businessProcess.createProcess("validationDemandeAbsence");
      }


      It looks like the business process starts, but the outjection of variables in the business process does not seem to work ... What I understand is that the outjection is made by Seam after the handleValider() method is called. But the business process starts on the createProcess() method call, so it looks obvious that variables have not been injected yet ...

      Any idea how I should do this ?

        • 1. Re: Dynamic creation of JBPM processes
          pmuir

          @CreateProcess will call businessProcess.createProcess when the method is complete, not before it so you have a slightly different order of events. How about outjecting programatically in the same order seam does it?

          • 2. Re: Dynamic creation of JBPM processes
            chawax

            Yes, that's what I try to do. But I don't really know the order Seam does it ... Where could I find this informations ? I hoped to see it in the source code for @CreateProcess annotation, but I couldn't find it ...

            • 3. Re: Dynamic creation of JBPM processes
              chawax

              No need to answer, I just found how to do :)
              I did it this way :

              Contexts.getBusinessProcessContext().set("idDemandeAbsence", this.demandeAbsence.getId());
              Contexts.getBusinessProcessContext().set("codeMotifAbsence", this.ligneDemandeAbsence.getMotif());
              this.businessProcess.createProcess("validationDemandeAbsence");
              


              According to you, is it the state-of-the-art way to do it ?

              • 4. Re: Dynamic creation of JBPM processes
                pmuir

                Order is determined the order in which the BijectionInterceptor and BusinessProcessInterceptor (bpm interceptor wraps the bijection - so bijection occurs before, as I said/you implemented). This is a correct way to do it, yes.

                • 5. Re: Dynamic creation of JBPM processes
                  chawax

                  So that's perfect. Thanks a lot for your help.