Search in sources :

Example 1 with GroupMember

use of org.alfresco.rest.api.model.GroupMember in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroupMember.

private GroupMember getGroupMember(AuthorityInfo authorityInfo) {
    if (authorityInfo == null) {
        return null;
    }
    GroupMember groupMember = new GroupMember();
    groupMember.setId(authorityInfo.getAuthorityName());
    String authorityDisplayName = authorityInfo.getAuthorityDisplayName();
    if (authorityDisplayName == null || authorityDisplayName.isEmpty()) {
        authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName());
    }
    groupMember.setDisplayName(authorityDisplayName);
    String memberType = null;
    AuthorityType authorityType = AuthorityType.getAuthorityType(authorityInfo.getAuthorityName());
    switch(authorityType) {
        case GROUP:
            memberType = PARAM_MEMBER_TYPE_GROUP;
            break;
        case USER:
            memberType = PARAM_MEMBER_TYPE_PERSON;
            break;
        default:
    }
    groupMember.setMemberType(memberType);
    return groupMember;
}
Also used : GroupMember(org.alfresco.rest.api.model.GroupMember) AuthorityType(org.alfresco.service.cmr.security.AuthorityType)

Example 2 with GroupMember

use of org.alfresco.rest.api.model.GroupMember in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroupMembers.

public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters) {
    validateGroupId(groupId, false);
    // Not allowed to list all members.
    if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
        throw new UnsupportedResourceOperationException();
    }
    Paging paging = parameters.getPaging();
    // Retrieve sort column. This is limited for now to sort column due to
    // v0 api implementation. Should be improved in the future.
    Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
    AuthorityType authorityType = null;
    // Parse where clause properties.
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_GROUP_MEMBERS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);
        String memberTypeStr = propertyWalker.getProperty(PARAM_MEMBER_TYPE, WhereClauseParser.EQUALS, String.class);
        authorityType = getAuthorityType(memberTypeStr);
    }
    PagingResults<AuthorityInfo> pagingResult = getAuthoritiesInfo(authorityType, groupId, sortProp, paging);
    // Create response.
    final List<AuthorityInfo> page = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    List<GroupMember> groupMembers = new AbstractList<GroupMember>() {

        @Override
        public GroupMember get(int index) {
            AuthorityInfo authorityInfo = page.get(index);
            return getGroupMember(authorityInfo);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    return CollectionWithPagingInfo.asPaged(paging, groupMembers, pagingResult.hasMoreItems(), totalItems);
}
Also used : AbstractList(java.util.AbstractList) GroupMember(org.alfresco.rest.api.model.GroupMember) Query(org.alfresco.rest.framework.resource.parameters.where.Query) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported)

Example 3 with GroupMember

use of org.alfresco.rest.api.model.GroupMember in project alfresco-remote-api by Alfresco.

the class GroupsFilter method getGroupMembers.

public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters) {
    validateGroupId(groupId, false);
    // Not allowed to list all members.
    if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
        throw new UnsupportedResourceOperationException();
    }
    Paging paging = parameters.getPaging();
    // Retrieve sort column. This is limited for now to sort column due to
    // v0 api implementation. Should be improved in the future.
    Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
    AuthorityType authorityType = null;
    // Parse where clause properties.
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_GROUP_MEMBERS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);
        String memberTypeStr = propertyWalker.getProperty(PARAM_MEMBER_TYPE, WhereClauseParser.EQUALS, String.class);
        authorityType = getAuthorityType(memberTypeStr);
    }
    PagingResults<AuthorityInfo> pagingResult = getAuthoritiesInfo(authorityType, groupId, sortProp, paging);
    // Create response.
    final List<AuthorityInfo> page = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    List<GroupMember> groupMembers = new AbstractList<GroupMember>() {

        @Override
        public GroupMember get(int index) {
            AuthorityInfo authorityInfo = page.get(index);
            return getGroupMember(authorityInfo);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    return CollectionWithPagingInfo.asPaged(paging, groupMembers, pagingResult.hasMoreItems(), totalItems);
}
Also used : AbstractList(java.util.AbstractList) GroupMember(org.alfresco.rest.api.model.GroupMember) Query(org.alfresco.rest.framework.resource.parameters.where.Query) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported)

Example 4 with GroupMember

use of org.alfresco.rest.api.model.GroupMember in project alfresco-remote-api by Alfresco.

the class GroupsFilter method getGroupMember.

private GroupMember getGroupMember(AuthorityInfo authorityInfo) {
    if (authorityInfo == null) {
        return null;
    }
    GroupMember groupMember = new GroupMember();
    groupMember.setId(authorityInfo.getAuthorityName());
    String authorityDisplayName = authorityInfo.getAuthorityDisplayName();
    if (authorityDisplayName == null || authorityDisplayName.isEmpty()) {
        authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName());
    }
    groupMember.setDisplayName(authorityDisplayName);
    String memberType = null;
    AuthorityType authorityType = AuthorityType.getAuthorityType(authorityInfo.getAuthorityName());
    switch(authorityType) {
        case GROUP:
            memberType = PARAM_MEMBER_TYPE_GROUP;
            break;
        case USER:
            memberType = PARAM_MEMBER_TYPE_PERSON;
            break;
        default:
    }
    groupMember.setMemberType(memberType);
    return groupMember;
}
Also used : GroupMember(org.alfresco.rest.api.model.GroupMember) AuthorityType(org.alfresco.service.cmr.security.AuthorityType)

Aggregations

GroupMember (org.alfresco.rest.api.model.GroupMember)4 AuthorityType (org.alfresco.service.cmr.security.AuthorityType)4 AbstractList (java.util.AbstractList)2 AuthorityInfo (org.alfresco.repo.security.authority.AuthorityInfo)2 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)2 Paging (org.alfresco.rest.framework.resource.parameters.Paging)2 Query (org.alfresco.rest.framework.resource.parameters.where.Query)2 MapBasedQueryWalkerOrSupported (org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported)2