Updating a group name uses the updateGroup method of the GroupsApi.
For more information about this ReST API endpoint, see Update 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.GroupBodyUpdate; 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 UpdateGroupCmd { static final Logger LOGGER = LoggerFactory.getLogger(UpdateGroupCmd.class); @Autowired GroupsApi groupsApi; public void execute(String groupId, String newName) throws IOException { List<String> fields = null; List<String> include = null; GroupBodyUpdate groupBodyUpdate = new GroupBodyUpdate(); groupBodyUpdate.setDisplayName(newName); GroupEntry group = groupsApi.updateGroup(groupId, groupBodyUpdate, include, fields).getBody(); LOGGER.info("Updated group {}", group); } }
Executing this code will update the name of the group with passed in id, in this case we are updating the name for a group with id hr, note that you have to prefix group ids with GROUP_:
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar update-group GROUP_hr "Human Resources updated" 2021-05-06 12:42:41.475 INFO 26302 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.285 seconds (JVM running for 3.742) 2021-05-06 12:42:41.477 INFO 26302 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: update-group 2021-05-06 12:42:41.478 INFO 26302 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[1]: GROUP_hr 2021-05-06 12:42:41.478 INFO 26302 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[2]: Human Resources updated 2021-05-06 12:42:41.673 INFO 26302 --- [ main] o.a.tutorial.restapi.UpdateGroupCmd : Updated group class GroupEntry { entry: class Group { id: GROUP_hr displayName: Human Resources updated isRoot: true parentIds: null zones: null } }