IdentityService jbpm:验证时无法创建组,错误

时间:2011-04-21 10:37:41

标签: jbpm

这是我在IdentityService变量ident:

上调试时得到的
ident    -> commandService = null
         -> commandService = RetryInterceptor(id=68)

在我的jbpm.cfg.xml中我有:

<jbpm-configuration>
...
 <import resource="jbpm.identity.cfg.xml" /> 
 ...
</jbpm-configuration>
//I tried using my own IdentityService class, but it didn't work...

然后我有一个使用IdentityService的类,名为simpleProcessService,带有getter和setter。

public class SimpleProcessServiceImpl implements SimpleProcessService{
...
private IdentityService identityService;
...
public IdentityService getIdentityService()
    {

        return identityService;
    }
    public void setIdentityService(IdentityService identityService)
    {

        this.identityService = identityService;
    }

...
}

在我的applicationContext-process中,我有:

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

<beans xmlns="http://www.springframework.org/schema/beans"
   ...>


    <bean id="transactionManagerJbpm"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactoryJbpm" />
        <property name="dataSource" ref="dataSourceJbpm" />
    </bean>



    <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
       <property name="jbpmCfg" value="jbpm.cfg.xml"/>
  </bean>
    <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
<!--    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />-->
<!--    <bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />-->
<!--    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />-->

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

....

    <bean id="simpleProcessService"
        class="com.playence.platform.services.jbpm.impl.SimpleProcessServiceImpl">
        <property name="repositoryService"  value="#{processEngine.repositoryService}"/>
        <property name="executionService"  value="#{processEngine.executionService}"/>
        <property name="taskService"  value="#{processEngine.taskService}"/>
    <property name="identityService"  value="#{processEngine.IdentityService}"/>
    </bean>
   ...

</beans>

在我的测试文件中,我有:

public void testGroups()
    {
         SimpleProcessService simpleProcessService =(SimpleProcessService)ctx.getBean("simpleProcessService");
         TaskService taskService = simpleProcessService.getTaskService();

         IdentityService ident = simpleProcessService.getIdentityService();

         final int nTasks = 1;
         List<Map<String, Object>> vars= new ArrayList<Map<String, Object>>(nTasks);

         System.out.println("executing process");

         String processKey = "";
         String internalURI = "";
         Map<String,Object> x = new HashMap<String,Object>();
         ProcessInstance processInstance =null;
         List<String> processInstanceIds = new ArrayList<String>();

         //Create nTasks for annotation
         for(int i = 0; i <nTasks ; i++)
         {
                 processKey = Long.toString(System.currentTimeMillis());
                 internalURI = "/videos/test"+i+".flv_" + processKey;

                 x = new HashMap<String,Object>();
                 x.put("internalURI", internalURI);
                 x.put("content", "good");
                 vars.add(i,x);

                 processInstance = simpleProcessService.startProcess("groups", vars.get(i), processKey);
                 processInstanceIds.add(processInstance.getId());

         }


         ident.createGroup("anotacion");

         ident.createUser("silver", "johndoe", "John", "Doe");
         ident.createMembership("silver", "anotacion");

         ident.createUser("david", "joesmoe", "Joe", "Smoe");
         ident.createMembership("david", "anotacion");

         ident.createUser("blanca", "joesmoe", "Joe", "Smoe");
         ident.createMembership("blanca", "anotacion");

....

}

当我尝试创建一个组时抛出异常,似乎虽然ident不为null,但它包含空对象......

有什么想法吗?

达玛里斯。

1 个答案:

答案 0 :(得分:1)

在我的测试类中,我像这样访问IdentityService:

ProcessEngine processEngine = new Configuration().buildProcessEngine();
IdentityService id = processEngine.getIdentityService();

在我的applicationContext-process中有这个:

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

实现了一个基本调用IdentityService方法的类IdentityServiceImpl:

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);        
}

}

在我的cfg.jpdl.xml中,我就是这样:

<?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>

我希望它有所帮助

达玛里斯。