class AttributesServiceImpl implements AttributesService {

    @SuppressWarnings("unchecked")
    public AttributesSearchResult<ClientAttribute>
    getAttributes(AttributesSearchCriteria searchCriteria, boolean includeEffectivePermissionsInResult) throws ErrorDescriptorException {
        String attributeHolder = searchCriteria.getHolder() == null ||
                searchCriteria.getHolder().equals(ROOT_HOLDER) ? ROOT_HOLDER.concat(TenantService.ORGANIZATIONS) : searchCriteria.getHolder();
        Object recipient;

        try {
            recipient = recipientIdentityResolver.resolveRecipientObject(attributeHolder);
        } catch (Exception ex) {
            return new AttributesSearchResultImpl<ClientAttribute>();
        }

        AttributesSearchResult<ProfileAttribute> serverSearchResult = profileAttributeService.
                getProfileAttributesForPrincipal(null, recipient, searchCriteria);

        AttributesSearchResult<ClientAttribute> clientAttributes = new AttributesSearchResultImpl<ClientAttribute>();
        clientAttributes.setList(new ArrayList<ClientAttribute>());

        for (ProfileAttribute serverAttr : serverSearchResult.getList()) {
            ClientAttribute clientAttr = attributesConverter.toClient(serverAttr, null);
            if (includeEffectivePermissionsInResult) {
                clientAttr = new HypermediaAttribute(clientAttr);
                HypermediaAttributeEmbeddedContainer embeddedContainer = new HypermediaAttributeEmbeddedContainer();
                embeddedContainer.setRepositoryPermissions(getEffectivePermissions(serverAttr));
                ((HypermediaAttribute)clientAttr).setEmbedded(embeddedContainer);
            }
            clientAttributes.getList().add(clientAttr);
        }
        clientAttributes.setTotalCount(serverSearchResult.getTotalCount());

        return clientAttributes;
    }

}