/**
   * See Interface for functional description.
   *
   * @see UserAccountDaoInterface #retrieveAttribute(java.lang.String, java.lang.String)
   */
  @Override
  public UserAttribute retrieveAttribute(final String userId, final String attributeId)
      throws SqlDatabaseSystemException {

    UserAttribute result = null;
    if (attributeId != null) {
      try {
        result = getHibernateTemplate().get(UserAttribute.class, attributeId);
        if (result == null || !result.getUserAccountByUserId().getId().equals(userId)) {
          result = null;
        }
      } catch (final DataAccessException e) {
        throw new SqlDatabaseSystemException(e);
      } catch (final IllegalStateException e) {
        throw new SqlDatabaseSystemException(e);
      } catch (final HibernateException e) {
        //noinspection ThrowableResultOfMethodCallIgnored
        throw new SqlDatabaseSystemException(convertHibernateAccessException(e)); // Ignore FindBugs
      }
    }
    return result;
  }
  /**
   * Fetches the value of the attribute {@code ATTR_USER_OU} for the provided user account.
   *
   * @param userAccount The user account to fetch the value from.
   * @param getChildren if also children of userAccountous are to be fetched.
   * @return Returns the attribute value in an {@code EvaluationResult}.
   * @throws de.escidoc.core.common.exceptions.system.SystemException
   */
  private EvaluationResult fetchUserAccountOus(
      final UserAccount userAccount, final boolean getChildren) throws SystemException {

    final String ouAttributeName =
        EscidocConfiguration.getInstance()
            .get(EscidocConfiguration.ESCIDOC_CORE_AA_OU_ATTRIBUTE_NAME);
    if (ouAttributeName == null || ouAttributeName.length() == 0) {
      return CustomEvaluationResultBuilder.createEmptyEvaluationResult();
    }
    final List<UserAttribute> attributes =
        userAccountDao.retrieveAttributes(userAccount, ouAttributeName);
    final EvaluationResult result;
    if (attributes == null || attributes.isEmpty()) {
      result = CustomEvaluationResultBuilder.createEmptyEvaluationResult();
    } else {
      final List<StringAttribute> results = new ArrayList<StringAttribute>();
      final Collection<String> ouIds = new ArrayList<String>();
      for (final UserAttribute attribute : attributes) {
        results.add(new StringAttribute(attribute.getValue()));
        if (getChildren) {
          ouIds.add(attribute.getValue());
        }
      }
      if (getChildren) {
        final List<String> childOus =
            tripleStoreUtility.getChildrenPath(ouIds, new ArrayList<String>());
        if (childOus != null) {
          for (final String childOu : childOus) {
            results.add(new StringAttribute(childOu));
          }
        }
      }

      result = new EvaluationResult(new BagAttribute(Constants.URI_XMLSCHEMA_STRING, results));
    }
    return result;
  }