@Override
  public long[] getPooledActorsIds(long companyId, long workflowTaskInstanceId)
      throws WorkflowException {

    try {
      KaleoTaskInstanceToken kaleoTaskInstanceToken =
          KaleoTaskInstanceTokenLocalServiceUtil.getKaleoTaskInstanceToken(workflowTaskInstanceId);

      List<KaleoTaskAssignment> calculatedKaleoTaskAssignments =
          getCalculatedKaleoTaskAssignments(kaleoTaskInstanceToken);

      Map<String, Long> pooledActors = new TreeMap<>(new NaturalOrderStringComparator());

      for (KaleoTaskAssignment calculatedKaleoTaskAssignment : calculatedKaleoTaskAssignments) {

        String assigneeClassName = calculatedKaleoTaskAssignment.getAssigneeClassName();
        long assigneeClassPK = calculatedKaleoTaskAssignment.getAssigneeClassPK();

        if (assigneeClassName.equals(User.class.getName())) {
          User user = UserLocalServiceUtil.fetchUser(assigneeClassPK);

          if (user != null) {
            pooledActors.put(user.getFullName(), user.getUserId());
          }

          continue;
        }

        Role role =
            RoleLocalServiceUtil.getRole(calculatedKaleoTaskAssignment.getAssigneeClassPK());

        if ((role.getType() == RoleConstants.TYPE_SITE)
            || (role.getType() == RoleConstants.TYPE_ORGANIZATION)) {

          List<UserGroupRole> userGroupRoles =
              UserGroupRoleLocalServiceUtil.getUserGroupRolesByGroupAndRole(
                  kaleoTaskInstanceToken.getGroupId(), assigneeClassPK);

          for (UserGroupRole userGroupRole : userGroupRoles) {
            User user = userGroupRole.getUser();

            pooledActors.put(user.getFullName(), user.getUserId());
          }

          List<UserGroupGroupRole> userGroupGroupRoles =
              UserGroupGroupRoleLocalServiceUtil.getUserGroupGroupRolesByGroupAndRole(
                  kaleoTaskInstanceToken.getGroupId(), assigneeClassPK);

          for (UserGroupGroupRole userGroupGroupRole : userGroupGroupRoles) {

            List<User> userGroupUsers =
                UserLocalServiceUtil.getUserGroupUsers(userGroupGroupRole.getUserGroupId());

            for (User user : userGroupUsers) {
              pooledActors.put(user.getFullName(), user.getUserId());
            }
          }
        } else {
          List<User> inheritedRoleUsers =
              UserLocalServiceUtil.getInheritedRoleUsers(
                  assigneeClassPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

          for (User user : inheritedRoleUsers) {
            pooledActors.put(user.getFullName(), user.getUserId());
          }
        }
      }

      return ArrayUtil.toLongArray(pooledActors.values());
    } catch (Exception e) {
      throw new WorkflowException(e);
    }
  }
  protected void importUsers(
      long ldapServerId,
      long companyId,
      LdapContext ldapContext,
      Properties userMappings,
      Properties userExpandoMappings,
      Properties contactMappings,
      Properties contactExpandoMappings,
      long userGroupId,
      Attribute attribute)
      throws Exception {

    List<Long> newUserIds = new ArrayList<Long>(attribute.size());

    for (int i = 0; i < attribute.size(); i++) {
      String fullUserDN = (String) attribute.get(i);

      Attributes userAttributes = null;

      try {
        userAttributes =
            PortalLDAPUtil.getUserAttributes(ldapServerId, companyId, ldapContext, fullUserDN);
      } catch (NameNotFoundException nnfe) {
        _log.error("LDAP user not found with fullUserDN " + fullUserDN, nnfe);

        continue;
      }

      try {
        User user =
            importUser(
                companyId,
                userAttributes,
                userMappings,
                userExpandoMappings,
                contactMappings,
                contactExpandoMappings,
                StringPool.BLANK);

        if (user != null) {
          if (_log.isDebugEnabled()) {
            _log.debug("Adding " + user.getUserId() + " to group " + userGroupId);
          }

          UserLocalServiceUtil.addUserGroupUsers(userGroupId, new long[] {user.getUserId()});

          newUserIds.add(user.getUserId());
        }
      } catch (Exception e) {
        _log.error("Unable to load user " + userAttributes, e);
      }
    }

    List<User> userGroupUsers = UserLocalServiceUtil.getUserGroupUsers(userGroupId);

    for (User user : userGroupUsers) {
      if (!newUserIds.contains(user.getUserId())) {
        UserLocalServiceUtil.deleteUserGroupUser(userGroupId, user.getUserId());
      }
    }
  }