Creating a Group - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

Creating a group uses the createGroup method of the GroupsApi.

For more information about this ReST API endpoint, see Create a Group.

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

import org.alfresco.core.handler.GroupsApi;
import org.alfresco.core.model.GroupBodyCreate;
import org.alfresco.core.model.GroupEntry;
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 CreateGroupCmd {
    static final Logger LOGGER = LoggerFactory.getLogger(CreateGroupCmd.class);

    @Autowired
    GroupsApi groupsApi;

    public void execute(String groupId, String name) throws IOException {
        List<String> fields = null;
        List<String> include = null;

        GroupBodyCreate groupBodyCreate = new GroupBodyCreate();
        groupBodyCreate.setId(groupId);
        groupBodyCreate.setDisplayName(name);
        GroupEntry groupEntry = groupsApi.createGroup(groupBodyCreate, include, fields).getBody();
        LOGGER.info("Created group  {}", groupEntry.getEntry());
    }
}

Executing this code will create a group, in this case we are creating an HR group:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar create-group hr "Human Resources"

2021-05-06 10:25:51.906  INFO 25139 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.477 seconds (JVM running for 3.956)
2021-05-06 10:25:51.908  INFO 25139 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: create-group
2021-05-06 10:25:51.909  INFO 25139 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[1]: hr
2021-05-06 10:25:51.909  INFO 25139 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[2]: Human Resources
2021-05-06 10:25:52.165  INFO 25139 --- [           main] o.a.tutorial.restapi.CreateGroupCmd      : Created group  class Group {
    id: GROUP_hr
    displayName: Human Resources
    isRoot: true
    parentIds: null
    zones: null
}