/** Constructor to initialize filter-names with RoleFilter-Class. */
 public HibernateUserAccountDao() {
   try {
     final UserAccountFilter userAccountFilter = new UserAccountFilter(null);
     final RoleGrantFilter roleGrantFilter = new RoleGrantFilter(null);
     this.criteriaMap = userAccountFilter.getCriteriaMap();
     this.propertiesNamesMap = userAccountFilter.getPropertyMap();
     this.grantPropertiesNamesMap = roleGrantFilter.getPropertyMap();
   } catch (final InvalidSearchQueryException e) {
     // Dont do anything because null-query is given
     if (LOGGER.isWarnEnabled()) {
       LOGGER.warn("Exception for null-query");
     }
     if (LOGGER.isDebugEnabled()) {
       LOGGER.debug("Exception for null-query", e);
     }
   }
 }
  /**
   * See Interface for functional description.
   *
   * @see UserAccountDaoInterface #retrieveGrants(java.lang.String, int, int,
   *     UserGroupHandlerInterface)
   */
  @Override
  public List<RoleGrant> retrieveGrants(
      final String criterias,
      final int offset,
      final int maxResults,
      final UserGroupHandlerInterface userGroupHandler)
      throws InvalidSearchQueryException, SystemException {
    final List<RoleGrant> result;

    if (criterias != null && criterias.length() > 0) {
      final RoleGrantFilter filter = new RoleGrantFilter(criterias);
      final Set<String> userIds = filter.getUserIds();
      final Set<String> groupIds = filter.getGroupIds();

      // check if userId and groupId was provided
      if (userIds != null && !userIds.isEmpty() && groupIds != null && !groupIds.isEmpty()) {
        throw new InvalidSearchQueryException(
            "you may not provide a userId and a groupId at the same " + "time");
      }

      // if userIds or groupIds are provided,
      // get all groups the given users/groups belong to
      if (userIds != null && !userIds.isEmpty()) {
        for (final String userId : userIds) {
          try {
            groupIds.addAll(userGroupHandler.retrieveGroupsForUser(userId));
          } catch (final UserAccountNotFoundException e) {
            // Dont do anything because null-query is given
            if (LOGGER.isWarnEnabled()) {
              LOGGER.warn("Error on retrieving groups for user.");
            }
            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug("Error on retrieving groups for user.", e);
            }
          }
        }
        filter.setGroupIds(groupIds);

      } else if (groupIds != null && !groupIds.isEmpty()) {
        for (final String groupId : groupIds) {
          groupIds.addAll(userGroupHandler.retrieveGroupsForGroup(groupId));
        }
        filter.setGroupIds(groupIds);
      }
      result = getHibernateTemplate().findByCriteria(filter.toSql(), offset, maxResults);
    } else {
      try {
        final DetachedCriteria detachedCriteria =
            DetachedCriteria.forClass(RoleGrant.class, "roleGrant");

        result = getHibernateTemplate().findByCriteria(detachedCriteria, offset, maxResults);
      } catch (final DataAccessException e) {
        throw new SqlDatabaseSystemException(e);
      }
    }
    return result;
  }