cancel
Showing results for 
Search instead for 
Did you mean: 

Custom management dosen't work when migrate to Activiti 5.15

galix
Champ in-the-making
Champ in-the-making
Hi devs,

I've custom management working great in version Activiti 5.12. Now we are migrating to 5.15 and I've some troubles to adapt code to it.
I notice there are some changes in internal API:
- In ManagementGroupManager, method findGroupById() no exist in GroupEntityManager anymore.
- In ManagementUserManager, we have to cast result of findUserById to (UserEntity)

This is my activiti-rest config in activiti-context.xml:
 
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="mailServerHost" value="localhost" />
      <property name="mailServerPort" value="5025" />
      <property name="jobExecutorActivate" value="true" />
        <property name="customFormTypes">
          <list>
            <bean class="org.activiti.rest.form.UserFormType"/>
            <bean class="org.activiti.rest.form.ProcessDefinitionFormType"/>
            <bean class="org.activiti.rest.form.MonthFormType"/>  
          </list>
        </property>
      <property name="customSessionFactories">
         <list>
            <bean class="activiti.management.ManagementUserManagerFactory">
               <constructor-arg ref="managementConnectionParams" />
            </bean>
            <bean class="activiti.management.ManagementGroupManagerFactory">
               <constructor-arg ref="managementConnectionParams" />
            </bean>
         </list>
      </property>
   </bean>

   <bean id="managementConnectionParams" class="activiti.management.ManagementConnectionParams">
      <property name="serviceUrl" value="https://XXX/Management/ManagementWebService.svc" />
      <property name="user" value="XXX" />
      <property name="password" value="XXX" />
      <property name="timeout" value="30000" />
   </bean>


Even seems like activiti dosen't use custom managment cause dosen't print any log of module when i'ts working in 5.15 and it does when is in 5.12.

Anybody can help me.
Thanks a lot

Cheers
7 REPLIES 7

galix
Champ in-the-making
Champ in-the-making
Is there any change to invoke "customSessionFactories" in activiti-context.xml on Activiti 5.15?

jbarrez
Star Contributor
Star Contributor
The xml look allright.

Is your impl returning the correct type, ie. it must return the interface:

<code>

  public Class< ? > getSessionType() {
    return GroupIdentityManager.class;
  }
</code>

galix
Champ in-the-making
Champ in-the-making
Hi Joram,
First of all thank to answer Smiley Happy

I had this implementation:
<code>

public Class<?> getSessionType() {
   return GroupEntityManager.class;
  }

</code>
I just change for this one as you told me

ManagementGroupManagerFactory.java
<code>
public class ManagementGroupManagerFactory implements SessionFactory {

        private ManagementConnectionParams connectionParams;
       
        public ManagementGroupManagerFactory(ManagementConnectionParams params) {
                this.connectionParams = params;
        }
  public Class<?> getSessionType() {
   return GroupIdentityManager.class;
  }

  public Session openSession() {
   return new ManagementGroupManager(connectionParams);
  }
}

</code>

ManagementGroupManager.java:
<code>
public class ManagementGroupManager extends GroupEntityManager {

private ManagementConnectionParams connectionParams;

public ManagementGroupManager(ManagementConnectionParams params) {
  this.connectionParams = params;
}

@Override
public Group createNewGroup(String groupId) {
  Logger.getLogger(this.getClass())
    .info(String.format("ManagementGroupManager::createNewGroup - Trying to create a group: %s", groupId));
  return doCreateNewGroup(groupId);
}

@Override
public void insertGroup(Group group) {
  if (group != null) {
   Logger.getLogger(this.getClass())
    .info(String.format("ManagementGroupManager::insertGroup - Trying to insert group: %s", group.toString()));
   super.insertGroup(group);
   // TODO: Implementar la inserción en Management
  }
}

@Override
public void deleteGroup(String groupId) {
  Logger.getLogger(this.getClass())
    .info(String.format("ManagementGroupManager::deleteGroup - Trying to delete group: %s", groupId));
  super.deleteGroup(groupId);
  // TODO: Implementar el borrado en Management
}

/**
  * Punt d'entrada
  */
@Override
public List<Group> findGroupByQueryCriteria(GroupQueryImpl query, Page page) {
  /*List<Group> matchedGroups = super.findGroupByQueryCriteria(query, page);
  matchedGroups.addAll(finGroupInLdapByQueryCriteria(query));
  return matchedGroups;*/
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::findGroupByQueryCriteria"));
  return finGroupInLdapByQueryCriteria(query);
}

/**
  * 2on pas
  */
private List<Group> finGroupInLdapByQueryCriteria(GroupQueryImpl query) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::finGroupInLdapByQueryCriteria"));
  List<Group> groupList = new ArrayList<Group>();
  ClientRestManagement management = ManagementConnectionUtil.openConnection(connectionParams);
  try {
   for (ObjManagementInfo entry : management.objects(
     ManagementConstants.MANAGEMENT_OBJECT_GROUP_TYPE,
     query.getId(), query.getName(), "", "", "")) {
   
    Group group = createGroupFromObjManagement(entry);
   
    groupList.add(group);
   }

  } catch (Exception e) {
   throw new ActivitiException("Management connection search failure", e);
  }

 
  return groupList;
}

@Override
public long findGroupCountByQueryCriteria(GroupQueryImpl query) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::findGroupCountByQueryCriteria"));
  return findGroupByQueryCriteria(query, null).size();
}

public GroupEntity findGroupById(String groupId) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::findGroupById"));
  GroupQueryImpl query = new GroupQueryImpl();
  query.groupId(groupId);
  List<Group> queryResults = findGroupByQueryCriteria(query, new Page(0,
    1));
  return (queryResults != null && queryResults.size() > 0) ? (GroupEntity) queryResults
    .get(0) : null;
}

/**
  * 5er pas
  */
@Override
public List<Group> findGroupsByUser(String userId) {
  userId = ManagementHelper.getImpersonatedUserIfExistsOrUserId(userId, ManagementConnectionUtil.openConnection(connectionParams));
  List<Group> matchedGroups = super.findGroupsByUser(userId);
  matchedGroups.addAll(findGroupsInManagementByUser(userId));
  Logger.getLogger(this.getClass()).info(String.format("ManagementGroupManager::findGroupsByUser - %s. Found: %s groups", userId, matchedGroups.size()));
  return matchedGroups;
}

/**
  * 3er pas
  */
private List<Group> findGroupsInManagementByUser(String userId) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::findGroupsInManagementByUser"));
  List<Group> groupList = new ArrayList<Group>();
  ClientRestManagement management = ManagementConnectionUtil.openConnection(connectionParams);
  try {
   ObjManagementInfo user = getUserInfoFromManagement(userId, management);
  
   if(user != null) {
    for (ObjManagementInfo entry : management.getObjectGroups(user.objManagement.uid)) {
     Group group = createGroupFromObjManagement(entry);
     groupList.add(group);
    }
   }
  } catch (Exception e) {
   throw new ActivitiException("Management connection search failure", e);
  }

  return groupList;
}

private ObjManagementInfo getUserInfoFromManagement(String userId,
   ClientRestManagement management) {
  ObjManagementInfoList aux = management.objects(ManagementConstants.MANAGEMENT_OBJECT_USER_TYPE, userId, "", "", "", "");
  ObjManagementInfo user = (aux != null && aux.size() > 0) ? aux.get(0) : null;
  return user;
}

/**
  * 4rt pas
  */
private Group createGroupFromObjManagement(ObjManagementInfo entry) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::createGroupFromObjManagement"));
  Group group = new GroupEntity();
  group.setId(entry.objManagement.name);
  group.setName(entry.objManagement.nameDisplay);
  group.setType(entry.objManagement.father);
  return group;
}

private Group doCreateNewGroup(String groupId) {
  return super.createNewGroup(groupId);
  // TODO: Obtener las propiedades del Management si existen
}
}

</code>

Do I need to change anything else from 5.12 implementation? Where I can find information about this issue?
I assume I've to change the same in UserManager and UserManagerFactory, isn't it?

Thanks.
Cheers

galix
Champ in-the-making
Champ in-the-making
Joram you're right, I solved the problem. This is what I did:

Activiti-context.xml:
<code>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="dataSource" ref="dataSource" />
  <property name="transactionManager" ref="transactionManager" />
  <property name="databaseSchemaUpdate" value="true" />
  <property name="mailServerHost" value="localhost" />
  <property name="mailServerPort" value="5025" />
  <property name="jobExecutorActivate" value="true" />
        <property name="customFormTypes">
          <list>
            <bean class="org.activiti.rest.form.UserFormType"/>
            <bean class="org.activiti.rest.form.ProcessDefinitionFormType"/>
            <bean class="org.activiti.rest.form.MonthFormType"/>  
          </list>
        </property>
  <property name="customSessionFactories">
   <list>
    <bean class="activiti.management.ManagementUserManagerFactory">
     <constructor-arg ref="managementConnectionParams" />
    </bean>
    <bean class="activiti.management.ManagementGroupManagerFactory">
     <constructor-arg ref="managementConnectionParams" />
    </bean>
   </list>
  </property>
</bean>

<bean id="managementConnectionParams" class="activiti.management.ManagementConnectionParams">
  <property name="serviceUrl" value="https://XXX/Management/ManagementWebService.svc" />
  <property name="user" value="XXX" />
  <property name="password" value="XXX" />
  <property name="timeout" value="30000" />
</bean>
</code>

ManagementGroupManagerFactory:
<code>
public class ManagementGroupManagerFactory implements SessionFactory {

        private ManagementConnectionParams connectionParams;
       
        public ManagementGroupManagerFactory(ManagementConnectionParams params) {
                this.connectionParams = params;
        }

  public Class<?> getSessionType() {
   return GroupIdentityManager.class;
  }

  public Session openSession() {
   return new ManagementGroupManager(connectionParams);
  }

}
</code>

ManagementGroupManager:
<code>
public class ManagementGroupManager extends GroupEntityManager {

private ManagementConnectionParams connectionParams;

public ManagementGroupManager(ManagementConnectionParams params) {
  this.connectionParams = params;
}

@Override
public Group createNewGroup(String groupId) {
  Logger.getLogger(this.getClass())
    .info(String.format("ManagementGroupManager::createNewGroup - Trying to create a group: %s", groupId));
  return doCreateNewGroup(groupId);
}

@Override
public void insertGroup(Group group) {
  if (group != null) {
   Logger.getLogger(this.getClass())
    .info(String.format("ManagementGroupManager::insertGroup - Trying to insert group: %s", group.toString()));
   super.insertGroup(group);
   // TODO: Implementar la inserción en Management
  }
}

@Override
public void deleteGroup(String groupId) {
  Logger.getLogger(this.getClass())
    .info(String.format("ManagementGroupManager::deleteGroup - Trying to delete group: %s", groupId));
  super.deleteGroup(groupId);
  // TODO: Implementar el borrado en Management
}

/**
  * Punt d'entrada
  */
@Override
public List<Group> findGroupByQueryCriteria(GroupQueryImpl query, Page page) {
  /*List<Group> matchedGroups = super.findGroupByQueryCriteria(query, page);
  matchedGroups.addAll(finGroupInLdapByQueryCriteria(query));
  return matchedGroups;*/
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::findGroupByQueryCriteria"));
  return finGroupInLdapByQueryCriteria(query);
}

/**
  * 2on pas
  */
private List<Group> finGroupInLdapByQueryCriteria(GroupQueryImpl query) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::finGroupInLdapByQueryCriteria"));
  List<Group> groupList = new ArrayList<Group>();
  ClientRestManagement management = ManagementConnectionUtil.openConnection(connectionParams);
  try {
   for (ObjManagementInfo entry : management.objects(
     ManagementConstants.MANAGEMENT_OBJECT_GROUP_TYPE,
     query.getId(), query.getName(), "", "", "")) {

    Group group = createGroupFromObjManagement(entry);

    groupList.add(group);
   }

  } catch (Exception e) {
   throw new ActivitiException("Management connection search failure", e);
  }


  return groupList;
}

@Override
public long findGroupCountByQueryCriteria(GroupQueryImpl query) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::findGroupCountByQueryCriteria"));
  return findGroupByQueryCriteria(query, null).size();
}

public GroupEntity findGroupById(String groupId) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::findGroupById"));
  GroupQueryImpl query = new GroupQueryImpl();
  query.groupId(groupId);
  List<Group> queryResults = findGroupByQueryCriteria(query, new Page(0,
    1));
  return (queryResults != null && queryResults.size() > 0) ? (GroupEntity) queryResults
    .get(0) : null;
}

/**
  * 5er pas
  */
@Override
public List<Group> findGroupsByUser(String userId) {
  userId = ManagementHelper.getImpersonatedUserIfExistsOrUserId(userId, ManagementConnectionUtil.openConnection(connectionParams));
  List<Group> matchedGroups = super.findGroupsByUser(userId);
  matchedGroups.addAll(findGroupsInManagementByUser(userId));
  Logger.getLogger(this.getClass()).info(String.format("ManagementGroupManager::findGroupsByUser - %s. Found: %s groups", userId, matchedGroups.size()));
  return matchedGroups;
}

/**
  * 3er pas
  */
private List<Group> findGroupsInManagementByUser(String userId) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::findGroupsInManagementByUser"));
  List<Group> groupList = new ArrayList<Group>();
  ClientRestManagement management = ManagementConnectionUtil.openConnection(connectionParams);
  try {
   ObjManagementInfo user = getUserInfoFromManagement(userId, management);

   if(user != null) {
    for (ObjManagementInfo entry : management.getObjectGroups(user.objManagement.uid)) {
     Group group = createGroupFromObjManagement(entry);
     groupList.add(group);
    }
   }
  } catch (Exception e) {
   throw new ActivitiException("Management connection search failure", e);
  }

  return groupList;
}

private ObjManagementInfo getUserInfoFromManagement(String userId,
   ClientRestManagement management) {
  ObjManagementInfoList aux = management.objects(ManagementConstants.MANAGEMENT_OBJECT_USER_TYPE, userId, "", "", "", "");
  ObjManagementInfo user = (aux != null && aux.size() > 0) ? aux.get(0) : null;
  return user;
}

/**
  * 4rt pas
  */
private Group createGroupFromObjManagement(ObjManagementInfo entry) {
  Logger.getLogger(this.getClass())
  .info(String.format("ManagementGroupManager::createGroupFromObjManagement"));
  Group group = new GroupEntity();
  group.setId(entry.objManagement.name);
  group.setName(entry.objManagement.nameDisplay);
  group.setType(entry.objManagement.father);
  return group;
}

}
</code>

You've to implement the same way User context.
I hope I can help anyone because there are no documentation about this in "Guide" neither in "Activiti In Action".

jbarrez
Star Contributor
Star Contributor
Great! Thanks for posting back.

Indeed - this area is not well documented (it is also quite 'new')

jsalmon
Champ in-the-making
Champ in-the-making
For those using the Spring Boot integration with Java configuration, here's an example of how to do this via an InitializingBean (I'm using Activiti 5.17)

<java>
@Configuration
public class ActivitiConfig {

  @Bean
  InitializingBean processEngineConfigurationInitializer(final SpringProcessEngineConfiguration configuration) {

    return new InitializingBean() {
      public void afterPropertiesSet() {
        configuration.getSessionFactories().put(UserIdentityManager.class, new CustomUserEntityManagerFactory());
        configuration.getSessionFactories().put(GroupIdentityManager.class, new CustomGroupEntityManagerFactory());
      }
    };
  }
}
</java>

Note that the session factory map key is UserIdentityManager, NOT UserEntityManager (was stuck on that for a while). You also need to return UserIdentityManager.class in the getSessionType() method of the factory class:

<java>
  class CustomUserEntityManagerFactory implements SessionFactory {

    @Override
    public Class<?> getSessionType() {
      return UserIdentityManager.class;
    }

    @Override
    public Session openSession() {
      return new CustomUserEntityManager();
    }
  }
</java>

Then you just need to extend UserEntityManager as you need:

<java>
public class CustomUserEntityManager extends UserEntityManager {
    // implement necessary methods
}
</java>

Hope this helps someone in 2015 and beyond.

jbarrez
Star Contributor
Star Contributor
Thanks for posting this. Awesome! Im sure many people will find it helpful.