示例#1
0
  private String fetchDefaultGroupNameForUser(final String username) {
    String defaultGroupName = null;
    if (allowsDefaultGroup()) {
      final CMQueryResult result =
          view.select(
                  attribute(userClass(), userNameAttribute()),
                  attribute(userGroupDomain(), UserRole.DEFAULT_GROUP),
                  attribute(roleClass(), roleClass().getCodeAttributeName())) //
              .from(userClass()) //
              .join(roleClass(), over(userGroupDomain())) //
              .where(
                  condition(
                      attribute(userClass(), userNameAttribute()), //
                      eq(username))) //
              .run();

      for (final CMQueryRow row : result) {
        final CMCard group = row.getCard(roleClass());
        final CMRelation relation = row.getRelation(userGroupDomain()).getRelation();
        final String groupName = (String) group.getCode();
        final Object isDefaultGroup = relation.get(UserRole.DEFAULT_GROUP);
        if (isDefaultGroup != null) {
          if ((Boolean) isDefaultGroup) {
            defaultGroupName = groupName;
          }
        }
      }
    }
    return defaultGroupName;
  }
示例#2
0
 private List<String> fetchGroupNamesForUser(final Long userId) {
   final List<String> groupNames = new ArrayList<String>();
   final Alias groupClassAlias = EntryTypeAlias.canonicalAlias(roleClass());
   final Alias userClassAlias = EntryTypeAlias.canonicalAlias(userClass());
   final CMQueryResult userGroupsRows =
       view.select(attribute(groupClassAlias, Role.CODE)) //
           .from(roleClass()) //
           .join(userClass(), as(userClassAlias), over(userGroupDomain())) //
           .where(
               and( //
                   condition(
                       attribute(roleClass(), Role.ACTIVE), //
                       eq(true)), //
                   condition(
                       attribute(userClass(), userIdAttribute()), //
                       eq(userId)))) //
           .run();
   for (final CMQueryRow row : userGroupsRows) {
     final CMCard groupCard = row.getCard(groupClassAlias);
     groupNames.add((String) groupCard.getCode());
   }
   return groupNames;
 }