10 Replies Latest reply on Jan 27, 2011 3:36 AM by ly km

    adding a custom service to jbpm.cfg.xml

    Marco Baroetto Newbie

      Hi all, i'm a newbie into jbpm. I'm trying to add a service similar to IdentityService which provides me a list of all groups. I found other topics about the method to select all of them using hibernate but i want to add it to a new service.

       

      Is it possible to ad my own service class to jbpm.cfg.xml ? Or, if not, is it possible to add new methods to the identity service?

      thank you

        • 1. Re: adding a custom service to jbpm.cfg.xml
          Michael Wohlfart Expert

          You should be able to override the IdentityService with your own Implementation like this:

          • extend org.jbpm.pvm.internal.svc.IdentityServiceImpl and add whatever methods you need
          • instead of <identity-service /> in jbpm.cfg.xml use this:
            <object class="your.custom.identityServiceImpl">

                     <field name="commandService"><ref object="txRequiredCommandService" /></field>
                  </object>

          1 of 1 people found this helpful
          • 2. Re: adding a custom service to jbpm.cfg.xml
            Marco Baroetto Newbie

            doesn't seem to work in that way..

            • 3. Re: adding a custom service to jbpm.cfg.xml
              Michael Wohlfart Expert

              I am overriding RepositoryService and IdentityService this way.

              1 of 1 people found this helpful
              • 4. Re: adding a custom service to jbpm.cfg.xml
                HuiSheng Xu Master

                Hi Macro,

                 

                Michael's way is right.  Whenever you put a <object> tag into jbpm.cfg.xml.  Then you could get this service by processEngine.get(ClassName.class).  You said it is not work.  could you show us more information?  Thank you very much.

                • 5. Re: adding a custom service to jbpm.cfg.xml
                  Marco Baroetto Newbie

                  Sorry I must have mispelled something before... I am now able to add some methods to MyCustomIdentityService.

                   

                  I added a command for my new operation which calls MyCustomIdentitySession (extends IdentitySessionImpl) but i still get a nullpointer exception on hibernate session when calling a method of the parent (ie. findUsers() ).

                  any hint?

                  • 6. Re: adding a custom service to jbpm.cfg.xml
                    HuiSheng Xu Master

                    Hi Macro,

                     

                    If you want to use Session, Transaction which need open an Environment.  You could create a custom Command to achieve that.

                     

                    processEngine.execute(new Command() {

                        public Object execute(Environment env) {

                            //

                            return null;
                        }

                    });

                    • 7. Re: adding a custom service to jbpm.cfg.xml
                      kelum_sv N Newbie

                      HI

                       

                      Using jbpm 4.4. WITH jboss-5.1.0.GA

                       

                      1 :I am also having this kind of issue at the moment . What i have done was extended  IdentitySessionImpl and created my own MyIdentitySession .and i have over right few methods createUser,createGroup what was already there in IdentitySessionImpl.

                       

                      public class MyIdentitySession extends IdentitySessionImpl
                      {
                          /*
                         * This method will create or update a user
                         *
                         * */

                          public String createUser(String userName, String givenName, String familyName, String businessEmail)
                          {

                              User user = null;
                              try
                              {
                                  user = findUserById(userName);
                              }
                              catch (Exception ex)
                              {

                              }

                              if (user == null)
                              {
                                  user = new UserImpl(userName, givenName, familyName);
                                  long dbid = EnvironmentImpl.getFromCurrent(DbidGenerator.class).getNextId();
                                  ((UserImpl) user).setDbid(dbid);
                              }

                              UserImpl userimpl = (UserImpl) user;
                              userimpl.setBusinessEmail(businessEmail);
                              userimpl.setFamilyName(familyName);
                              userimpl.setGivenName(givenName);
                              userimpl.setId(userName);
                              session.save(user);

                              return user.getId();
                          }

                          /*
                         *  This method will create or modify Group
                         *
                         * */

                          public String createGroup(String groupName, String groupType, String parentGroupId)
                          {
                                    

                              GroupImpl group = null;

                              try
                              {
                                  group = findGroupById(groupName);
                              }
                              catch (Exception ex)
                              {

                              }

                              if (group == null)
                              {
                                  group = new GroupImpl();
                                  String groupId = groupType != null ? groupType + "." + groupName : groupName;
                                  group.setId(groupId);

                                  long dbid = EnvironmentImpl.getFromCurrent(DbidGenerator.class).getNextId();
                                  group.setDbid(dbid);
                              }

                              group.setName(groupName);
                              group.setType(groupType);

                              if (parentGroupId != null)
                              {
                                  GroupImpl parentGroup = findGroupById(parentGroupId);
                                  group.setParent(parentGroup);
                              }

                              session.save(group);

                              return group.getId();
                          }

                          public void setSession(Session session)
                          {
                              super.setSession(session);
                              Configuration.getProcessEngine().get()
                          }

                      }

                       

                       

                       

                       

                      2: Then i created new MyIdentitySessionBinding by extending WireDescriptorBinding

                       

                      public class MyIdentitySessionBinding extends WireDescriptorBinding
                      {
                          public MyIdentitySessionBinding()
                          {
                              super("identity-session");
                          }

                          public Object parse(Element element, Parse parse, Parser parser)
                          {
                              ObjectDescriptor objectDescriptor = new ObjectDescriptor(MyIdentitySession.class);
                              objectDescriptor.addTypedInjection("session", Session.class);
                              return objectDescriptor;
                          }
                      }

                       

                      3: Then this MyIdentitySessionBinding was registered using jbpm.user.wire.bindings.xml

                      <wire-bindings>
                        <!-- sessions -->
                      <binding class ="dd.ss.ss.MyIdentitySessionBinding" />

                      </wire-bindings>

                       

                      4: Added this file inside that jbpm-service.sar which inside JBoss deploy directory .

                       

                      5 : Customised jbpm.cfg.xml as bellow

                       

                      <jbpm-configuration jndi-name="java:/ProcessEngine">

                        <import resource="jbpm.default.cfg.xml" />
                        <import resource="jbpm.businesscalendar.cfg.xml" />
                        <import resource="jbpm.tx.jta.cfg.xml" />
                        <import resource="jbpm.jpdl.cfg.xml" />
                        <import resource="jbpm.bpmn.cfg.xml" /> 
                        <import resource="jbpm.jobexecutor.cfg.xml" />
                        <import resource="jbpm.console.cfg.xml" />
                        <transaction-context>
                          <object class ="aa.bb.cc.MyIdentitySession" />
                        </transaction-context>

                      </jbpm-configuration>

                       

                       

                      Whwn i try to use createUser,createGroup methods inside MyIdentitySession, it gives me NullPointer exception when accessing session[Hybranate ].

                       

                      Hope there should be a configuration issue. Please assist me on this regards

                       

                      Thank you

                      • 8. Re: adding a custom service to jbpm.cfg.xml
                        kelum_sv N Newbie

                        HI

                         

                        Using jbpm 4.4. WITH jboss-5.1.0.GA

                         

                        1 :I am also having this kind of issue at the moment . What i have done was extended  IdentitySessionImpl and created my own MyIdentitySession .and i have over right few methods createUser,createGroup what was already there in IdentitySessionImpl.

                         

                        public class MyIdentitySession extends IdentitySessionImpl
                        {
                            /*
                           * This method will create or update a user
                           *
                           * */

                            public String createUser(String userName, String givenName, String familyName, String businessEmail)
                            {

                                User user = null;
                                try
                                {
                                    user = findUserById(userName);
                                }
                                catch (Exception ex)
                                {

                                }

                                if (user == null)
                                {
                                    user = new UserImpl(userName, givenName, familyName);
                                    long dbid = EnvironmentImpl.getFromCurrent(DbidGenerator.class).getNextId();
                                    ((UserImpl) user).setDbid(dbid);
                                }

                                UserImpl userimpl = (UserImpl) user;
                                userimpl.setBusinessEmail(businessEmail);
                                userimpl.setFamilyName(familyName);
                                userimpl.setGivenName(givenName);
                                userimpl.setId(userName);
                                session.save(user);

                                return user.getId();
                            }

                            /*
                           *  This method will create or modify Group
                           *
                           * */

                            public String createGroup(String groupName, String groupType, String parentGroupId)
                            {
                                     

                                GroupImpl group = null;

                                try
                                {
                                    group = findGroupById(groupName);
                                }
                                catch (Exception ex)
                                {

                                }

                                if (group == null)
                                {
                                    group = new GroupImpl();
                                    String groupId = groupType != null ? groupType + "." + groupName : groupName;
                                    group.setId(groupId);

                                    long dbid = EnvironmentImpl.getFromCurrent(DbidGenerator.class).getNextId();
                                    group.setDbid(dbid);
                                }

                                group.setName(groupName);
                                group.setType(groupType);

                                if (parentGroupId != null)
                                {
                                    GroupImpl parentGroup = findGroupById(parentGroupId);
                                    group.setParent(parentGroup);
                                }

                                session.save(group);

                                return group.getId();
                            }

                            public void setSession(Session session)
                            {
                                super.setSession(session);
                                Configuration.getProcessEngine().get()
                            }

                        }

                         

                         

                         

                         

                        2: Then i created new MyIdentitySessionBinding by extending WireDescriptorBinding

                         

                        public class MyIdentitySessionBinding extends WireDescriptorBinding
                        {
                            public MyIdentitySessionBinding()
                            {
                                super("identity-session");
                            }

                            public Object parse(Element element, Parse parse, Parser parser)
                            {
                                ObjectDescriptor objectDescriptor = new ObjectDescriptor(MyIdentitySession.class);
                                objectDescriptor.addTypedInjection("session", Session.class);
                                return objectDescriptor;
                            }
                        }

                         

                        3: Then this MyIdentitySessionBinding was registered using jbpm.user.wire.bindings.xml

                        <wire-bindings>
                          <!-- sessions -->
                        <binding class ="dd.ss.ss.MyIdentitySessionBinding" />

                        </wire-bindings>

                         

                        4: Added this file inside that jbpm-service.sar which inside JBoss deploy directory .

                         

                        5 : Customised jbpm.cfg.xml as bellow

                         

                        <jbpm-configuration jndi-name="java:/ProcessEngine">

                          <import resource="jbpm.default.cfg.xml" />
                          <import resource="jbpm.businesscalendar.cfg.xml" />
                          <import resource="jbpm.tx.jta.cfg.xml" />
                          <import resource="jbpm.jpdl.cfg.xml" />
                          <import resource="jbpm.bpmn.cfg.xml" /> 
                          <import resource="jbpm.jobexecutor.cfg.xml" />
                          <import resource="jbpm.console.cfg.xml" />
                          <transaction-context>
                            <object class ="aa.bb.cc.MyIdentitySession" />
                          </transaction-context>

                        </jbpm-configuration>

                         

                         

                        Whwn i try to use createUser,createGroup methods inside MyIdentitySession, it gives me NullPointer exception when accessing session[Hybranate ].

                         

                        Hope there should be a configuration issue. Please assist me on this regards

                         

                        Thank you

                        • 9. Re: adding a custom service to jbpm.cfg.xml
                          Michael Wohlfart Expert

                          You try to override the binding for the "identity-session" tag, I don't know if this works that way, but even if it does, you are still using the object tag to configure your identity session so the binding is for sure not used and the setSession method probably never called.

                          • 10. adding a custom service to jbpm.cfg.xml
                            ly km Newbie

                            Hi, doesn't the config like this:

                            <identity-service>

                                    <object class="your.custom.identityServiceImpl">

                                       <field name="commandService"><ref object="txRequiredCommandService" /></field>
                                    </object>

                            </identity-service>