6 Replies Latest reply on Dec 6, 2011 3:34 AM by jbpm2011
      • 1. Re: How to Save jBPM 5.1 Process Definition Created via API?
        victor.lewis

        Answering my own question.  What I found is that I can do this as the last line in the mentioned example from the User Guide and I will get the XML for the Process.

         

        System.out.println(XmlBPMNProcessDumper.INSTANCE.dump(process, XmlBPMNProcessDumper.NO_META_DATA));

        • 2. Re: How to Save jBPM 5.1 Process Definition Created via API?
          jbpm2011

          Hi,

           

          I have a problem of casting processdefinition to workflowprocess

            System.out.println(XmlBPMNProcessDumper.INSTANCE.dump((WorkflowProcess) processDefinition, XmlBPMNProcessDumper.NO_META_DATA));

           

          this is the erreur

          Exception in thread "main" java.lang.ClassCastException: org.jbpm.context.def.ContextDefinition cannot be cast to org.drools.process.core.Context

              at com.test.ProcessMain.main

           

          can you help me please?

          thank you

          • 3. Re: How to Save jBPM 5.1 Process Definition Created via API?
            victor.lewis

            Estelle,

             

            The exception you show isn't complaining about your cast to a WorkflowProcess but looks to be deeper in the call to dump (although I cannot tell because you cut off the stack trace).  It says you have an instance of org.jbpm.context.def.ContextDefinition that is trying to be cast to org.drools.process.core.Context.  I don't know where the org.jbpm.context.def.ContextDefinition is being created but it probably a part of processDefinition.  The stack trace with the exception should tell you where the cast is being done.

             

            Here is the code I use to get thet XML:

             

            {code:java}

            protected String xmlForProcess(ProcessDefinitionDTO procDef, List<WorkflowNode> nodes, RPCResult result) {

                 RuleFlowProcessFactory factory = processDefinitionService.createProcesFactory(procDef.getIdString());

                 factory.version("1");

                 factory.packageName("com.stuff.pbm");

                 factory.name(procDef.getName());

             

                 addNodesToProcess(nodes, factory);

             

                 addLinksToProcess(procDef, factory);

             

                 RuleFlowProcess process = factory.getProcess();

                 ProcessValidationError[] errors = RuleFlowProcessValidator.getInstance().validateProcess(process);

                   

                 for (ProcessValidationError e : errors) {

                      result.addMessage(new MessageDTO(MessageCategory.WARNING, e.getMessage()));

                 }

                   

                 String asXml = XmlBPMNProcessDumper.INSTANCE.dump(process, XmlBPMNProcessDumper.NO_META_DATA);

                 return asXml;

            }

            {code}

             

            where {code:java}processDefinitionService.createProcessFactory{code} returns a {code:java}org.jbpm.ruleflow.core.RuleFlowProcessFactory{code}.

             

            I hope this helps.

             

            -Victor

            • 4. Re: How to Save jBPM 5.1 Process Definition Created via API?
              jbpm2011

              Thank you for your answer

               

              My principal object is to save in the file processdefinition.xml i didn't use the same method of you here is my code :

               

              import org.jbpm.bpmn2.xml.XmlBPMNProcessDumper;

              import org.jbpm.graph.def.ProcessDefinition;

              import org.jbpm.workflow.core.impl.WorkflowProcessImpl;

               

               

              public class ProcessTest

              {

              public static void main(String[] args)

                

                 {

                    System.out.println("Start ");

               

               

               

                    ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("processdefinition.xml");

                  System.out.println("before modification");

                  System.out.println(processDefinition.getName());

                  processDefinition.setName("My second name");

                  System.out.println("before modification");

                  System.out.println(processDefinition.getName());

               

                 // now i try to persist this modification in my processdefinition.xml

               

                  WorkflowProcessImpl process= new WorkflowProcessImpl();

                  process.getMetaData();

                  //process.getMetaData("processdefinition.xml");

                         

                  System.out.println(XmlBPMNProcessDumper.INSTANCE.dump(process, XmlBPMNProcessDumper.NO_META_DATA));

                     

                  System.out.println(processDefinition.getName());

               

               

                 This is my class but i didnt knew why we are not using the same syntax, we have two different code but we are using the same API and i guess the same object.

               

                 I will explain to you: I have the processdefinition.xml file i want to save any changes related to the process in this file so do you have any ideas or any suggestion 

               

              Thanks

              • 5. Re: How to Save jBPM 5.1 Process Definition Created via API?
                jbpm2011

                I want to know also if you are using import from org.drools or org.jbpm

                 

                Thank you

                • 6. Re: How to Save jBPM 5.1 Process Definition Created via API?
                  jbpm2011

                  Sorry if i bother you but if it is possible you give to me your project

                    Thank you