7 Replies Latest reply on May 10, 2011 3:29 AM by dhamaris

    IdentityService

    Tej jbpm Novice

      I am successfully able to create users, groups and memberships.

      But I dont find any api calls to update user-group relationship.
      So i tried to use the deletemembership and createmembership to reestablish the relationships.But the problem is the deleteMembership() method does not seem to work. Has anybody tried it? What am i doing wrong? The api says I can pass null for role

      identityService.deleteMembership(identityService.findUserById("testuser")),
      identityService.findGroupById("testgroup").getId(),null); // userid,groupid,roleid

      It returns the following error
      java.lang.IllegalArgumentException: attempt to create delete event with null entity
       at org.hibernate.event.DeleteEvent.<init>(DeleteEvent.java:47)
       at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:771)
       at org.jbpm.pvm.internal.identity.impl.IdentitySessionImpl.deleteMembership(IdentitySessionImpl.java:197)
       at org.jbpm.pvm.internal.identity.cmd.DeleteMembershipCmd.execute(DeleteMembershipCmd.java:48)
       at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
       at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:54)
       at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
       at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
       at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
       at org.jbpm.pvm.internal.svc.SkipInterceptor.execute(SkipInterceptor.java:43)
       at org.jbpm.pvm.internal.svc.IdentityServiceImpl.deleteMembership(IdentityServiceImpl.java:111)


        • 1. Re: IdentityService
          Tej jbpm Novice

          Sorry missed the get id in the code part while editing..

          identityService.deleteMembership(identityService.findUserById("testuser")).getId(),
          identityService.findGroupById("testgroup").getId(),null); // userid,groupid,roleid


          • 2. Re: IdentityService
            Ronald van Kuijk Master

            do you have a *small* unittest?

            • 3. Re: IdentityService
              Tej jbpm Novice

              has anybody used deletemembership at all? I tried passing the dbid or the groupname..neither seem to delete it..both gives the same error...

              I have to stick with plain JDBC?

              • 4. Re: IdentityService
                Tej jbpm Novice

                @kukeltje - I will try to post a small testcase soon...

                • 5. Re: IdentityService
                  jordi elies Newbie

                  Do you solved the problem? I'm getting the same error when I call deleteMembership(). How we have to use deleteMembership method?

                   

                   

                  Thanks!

                   

                  PS: I'm currently using jbpm 4.4

                  • 6. Re: IdentityService
                    dhamaris Newbie

                    How did you have configured your IdentityService? I cannot even initialize mine!

                     

                    I'm currently using jbpm 4.4 and I put this in my configuration:

                     

                    <?xml version="1.0" encoding="UTF-8"?>

                     

                     

                    <jbpm-configuration>

                     

                     

                              <!-- <import resource="jbpm.default.cfg.xml" /> -->

                              <import resource="jbpm.tx.spring.cfg.xml" />

                              <import resource="jbpm.jpdl.cfg.xml" />

                              <import resource="jbpm.identity.cfg.xml" />

                              <import resource="jbpm.businesscalendar.cfg.xml" />

                              <import resource="jbpm.console.cfg.xml" />

                              <import resource="jbpm.jobexecutor.cfg.xml" />

                     

                              <script-manager default-expression-language="juel"

                                        default-script-language="juel"

                                        read-contexts="execution, environment, process-engine, spring"

                                        write-context="">

                                        <script-language name="juel"

                                                  factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />

                              </script-manager>

                     

                              <transaction-context>

                                        <object class="identitySession" />

                              </transaction-context>

                              <hibernate-session current="true" />

                    </jbpm-configuration>

                     

                    And in my applicationContext-process.xml I added a IdentityService bean to try to make sure it initialized:

                     

                    <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />

                    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />

                     

                     

                     

                    Nevertheless, everytime I debug my IdentityService object is null...

                     

                    Any ideas?

                    Thanks!

                     


                    • 7. Re: IdentityService
                      dhamaris Newbie

                      Hello, I just found a way:

                       

                       

                      In my test class, I access IdentityService like this:

                       

                       

                          ProcessEngine processEngine = new Configuration().buildProcessEngine();

                          IdentityService id = processEngine.getIdentityService();

                       

                       

                      Having this in my applicationContext-process:

                       

                       

                          <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />

                       

                       

                      And having implemented a class IdentityServiceImpl that basically calls to IdentityService methods:

                       

                       

                       

                       

                          public class IdentityServiceImpl extends UserServiceImpl implements IdentityService{

                       

                       

                                    public IdentityServiceImpl()

                                {

                                          //Load users and groups from the DB

                                }

                       

                                public void createUser(String userId, String givenName, String familyName) {

                                          //throw new UnsupportedOperationException("Use method TODO name method");

                                          createUser(userId,givenName,familyName);

                                }

                       

                       

                                public void createUser(String userId, String givenName, String familyName,

                                                    String businessEmail) {

                                          throw new UnsupportedOperationException("Use method TODO name method");

                                }

                       

                       

                                public User findUserById(String userId) {

                                          try{

                                                    GenericUser gU = loadUser(userId);

                                                    UserImpl user = new UserImpl(gU.getUsername(),gU.getFirstname(), gU.getLastname());

                                                    return user;

                                          }

                                           catch (ValidationErrors e) {

                                                    e.printStackTrace();

                                          } catch (ServiceExecutionException e) {

                                                    e.printStackTrace();

                                          }

                       

                                          return null;

                                }

                       

                       

                                public List<User> findUsers() {

                                          try {

                                                    List<GenericUser> gUList = listUsers();

                                                    List<User> userList = new ArrayList<User>();

                       

                                                    for(GenericUser gU : gUList)

                                                    {

                                                              userList.add(new UserImpl(gU.getUsername(),gU.getFirstname(), gU.getLastname()));

                                                    }

                                                    //If there are no users return null, otherwise return the users

                                                    if(userList.size() == 0)

                                                              return null;

                                                    else

                                                              return userList;

                       

                                          } catch (ServiceExecutionException e) {

                                                    e.printStackTrace();

                                          }

                       

                                          return null;

                                }

                       

                       

                                public void deleteUser(String userId) {

                                          throw new UnsupportedOperationException("Use method TODO name method");

                                }

                       

                       

                                public String createGroup(String groupName) {

                                          return createGroup(groupName);

                                          //TODO UserService

                                }

                       

                       

                                public String createGroup(String groupName, String groupType) {

                                          return createGroup(groupName, groupType);

                                }

                       

                       

                                public String createGroup(String groupName, String groupType,

                                                    String parentGroupId) {

                                          return createGroup(groupName, groupType, parentGroupId);

                                }

                       

                       

                                public Group findGroupById(String groupId) {

                                          return findGroupById(groupId);

                                }

                       

                       

                                public List<Group> findGroupsByUserAndGroupType(String userId,

                                                    String groupType) {

                                          return findGroupsByUserAndGroupType(userId, groupType);

                                }

                       

                       

                                public List<Group> findGroupsByUser(String userId) {

                                          return findGroupsByUser(userId);

                                }

                       

                       

                                public List<String> findGroupIdsByUser(String userId) {

                                          return findGroupIdsByUser(userId);

                                }

                       

                       

                                public void deleteGroup(String groupId) {

                                          deleteGroup(groupId);

                                }

                       

                       

                                public void createMembership(String userId, String groupId) {

                                          createMembership(userId, groupId);

                                }

                       

                       

                                public void createMembership(String userId, String groupId, String role) {

                                          createMembership(userId, groupId, role);

                                }

                       

                       

                                public void deleteMembership(String userId, String groupId, String role) {

                                          deleteMembership(userId, groupId, role);

                                }

                       

                      }

                       

                       

                       

                       

                      In my cfg.jpdl.xml I just have this:

                       

                       

                          <?xml version="1.0" encoding="UTF-8"?>

                          <jbpm-configuration>

                            <import resource="jbpm.default.cfg.xml" />

                            <import resource="jbpm.tx.spring.cfg.xml" />

                            <import resource="jbpm.jpdl.cfg.xml" />

                             <import resource="jbpm.bpmn.cfg.xml" />

                           <import resource="jbpm.identity.cfg.xml" />

                              <import resource="jbpm.businesscalendar.cfg.xml" />

                            <import resource="jbpm.console.cfg.xml" />

                             <!-- Commented out for dev environment only. -->

                            <import resource="jbpm.jobexecutor.cfg.xml" />

                             <process-engine-context>

                            <repository-service />

                            <repository-cache />

                            <execution-service />

                            <history-service />

                            <management-service />

                            <identity-service />

                            <task-service />

                       

                             <command-service name="txRequiredCommandService">

                                <skip-interceptor />

                                <retry-interceptor />

                                <environment-interceptor />

                                <standard-transaction-interceptor />

                              </command-service>

                       

                       

                              <command-service name="newTxRequiredCommandService">

                                <retry-interceptor />

                                <environment-interceptor policy="requiresNew" />

                                <standard-transaction-interceptor />

                              </command-service>

                              </process-engine-context>

                       

                       

                              <transaction-context>

                              <!--<object class="com.playence.platform.services.impl.IdentityServiceImpl" /> -->

                              <hibernate-session current="true" />

                            </transaction-context>

                       

                       

                          </jbpm-configuration>

                       

                       

                      I hope it helps

                       

                       

                      Dámaris.