Пример #1
0
  private CMUser buildUserFromCard(final CMCard _userCard) {
    final CMCard userCard = NullOnErrorOfGetCard.of(_userCard);
    final Long userId = userCard.getId();
    final String username = userCard.get(userNameAttribute(), String.class);
    final String email = userCard.get(userEmailAttribute(), String.class);
    final String userDescription = userCard.get(userDescriptionAttribute(), String.class);
    final String defaultGroupName = fetchDefaultGroupNameForUser(username);
    final UserImplBuilder userBuilder =
        UserImpl.newInstanceBuilder() //
            .withId(userId) //
            .withUsername(defaultString(username)) //
            .withEmail(defaultString(email)) //
            .withDescription(defaultString(userDescription)) //
            .withDefaultGroupName(defaultGroupName); //

    final List<String> userGroups = fetchGroupNamesForUser(userId);
    for (final String groupName : userGroups) {
      userBuilder.withGroupName(groupName);
      addGroupDescription(userBuilder, groupName);
    }
    userBuilder.withActiveStatus(isActive(userCard));
    return userBuilder.build();
  }
Пример #2
0
  /**
   * @param userBuilder
   * @param groupName
   */
  private void addGroupDescription( //
      final UserImplBuilder userBuilder, //
      final String groupName //
      ) {
    try {
      final CMCard roleCard =
          view.select(anyAttribute(roleClass())) //
              .from(roleClass()) //
              .where(condition(attribute(roleClass(), ROLE_NAME_COLUMN), eq(groupName))) //
              .run() //
              .getOnlyRow() //
              .getCard(roleClass());

      final Object roleDescription = roleCard.getDescription();
      if (roleDescription != null) {
        userBuilder.withGroupDescription(roleDescription.toString());
      }
    } catch (final Exception e) {
      logger.debug("Error reading description of group " + groupName);
    }
  }