Listing Groups - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

Listing the groups available in the repository uses the listGroups method of the GroupsApi.

For more information about this ReST API endpoint, see List Groups.

For a description of the common parameters, such as fields, see Common Parameters.

import org.alfresco.core.handler.GroupsApi;
import org.alfresco.core.model.GroupEntry;
import org.alfresco.core.model.GroupPaging;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

@Component
public class ListGroupsCmd {
    static final Logger LOGGER = LoggerFactory.getLogger(ListGroupsCmd.class);

    @Autowired
    GroupsApi groupsApi;

    public void execute() throws IOException {
        Integer skipCount = 0;
        Integer maxItems = 100;
        String where = null;
        List<String> orderBy = null;
        List<String> include = null;
        List<String> fields = null;

        LOGGER.info("Listing group in the repo:");
        GroupPaging groups = groupsApi.listGroups(skipCount, maxItems, orderBy, include, where, fields).getBody();
        for (GroupEntry groupEntry: groups.getList().getEntries()) {
            LOGGER.info("  {}", groupEntry.getEntry().getDisplayName());
        }
    }
}

Executing this code will list the groups available in the repository, note that this can be a lot of groups if there are loads of Share sites and the system is connected to a directory server:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar list-groups                        

2021-05-06 09:50:39.416  INFO 24665 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.637 seconds (JVM running for 4.131)
2021-05-06 09:50:39.419  INFO 24665 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: list-groups
2021-05-06 09:50:39.420  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       : Listing group in the repo:
2021-05-06 09:50:39.807  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   Engineering
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   ALFRESCO_ADMINISTRATORS
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   ALFRESCO_MODEL_ADMINISTRATORS
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   ALFRESCO_SEARCH_ADMINISTRATORS
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   EMAIL_CONTRIBUTORS
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   SITE_ADMINISTRATORS
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_swsdp
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_swsdp_SiteCollaborator
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_swsdp_SiteConsumer
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_swsdp_SiteContributor
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_swsdp_SiteManager
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_test
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_test_SiteCollaborator
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_test_SiteConsumer
2021-05-06 09:50:39.808  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_test_SiteContributor
2021-05-06 09:50:39.809  INFO 24665 --- [           main] o.a.tutorial.restapi.ListGroupsCmd       :   site_test_SiteManager