Deleting a Person or Group from 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

Deleting members of a group uses the deleteGroupMembership method of the GroupsApi.

For more information about this ReST API endpoint, see Delete a Person or Group from a Group.

import org.alfresco.core.handler.GroupsApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Component;

import java.io.IOException;

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

    @Autowired
    GroupsApi groupsApi;

    public void execute(String groupId, String groupMemberId) throws IOException {
        HttpEntity<Void> result = groupsApi.deleteGroupMembership(groupId, groupMemberId);
        LOGGER.info("Deleted group membership for group {} member {} result {}", groupId, groupMemberId, result);
    }
}

Executing this code will delete a person, or a group, from passed in group id, note that you have to prefix group ids with GROUP_:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar delete-group-membership GROUP_hr martin           

2021-05-06 14:09:25.825  INFO 27471 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.959 seconds (JVM running for 4.516)
2021-05-06 14:09:25.828  INFO 27471 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: delete-group-membership
2021-05-06 14:09:25.829  INFO 27471 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[1]: GROUP_hr
2021-05-06 14:09:25.829  INFO 27471 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[2]: martin
2021-05-06 14:09:26.112  INFO 27471 --- [           main] o.a.t.restapi.DeleteGroupMembershipCmd   : Deleted group membership for group GROUP_hr member martin result <204 NO_CONTENT No Content,[cache-control:"no-cache", connection:"keep-alive", content-type:"application/json;charset=UTF-8", date:"Thu, 06 May 2021 13:09:26 GMT", expires:"Thu, 01 Jan 1970 00:00:00 GMT", pragma:"no-cache", server:"nginx/1.18.0", x-frame-options:"SAMEORIGIN"]>

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar delete-group-membership GROUP_hr GROUP_engineering

2021-05-06 14:09:51.048  INFO 27472 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.964 seconds (JVM running for 4.493)
2021-05-06 14:09:51.050  INFO 27472 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: delete-group-membership
2021-05-06 14:09:51.051  INFO 27472 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[1]: GROUP_hr
2021-05-06 14:09:51.051  INFO 27472 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[2]: GROUP_engineering
2021-05-06 14:09:51.152  INFO 27472 --- [           main] o.a.t.restapi.DeleteGroupMembershipCmd   : Deleted group membership for group GROUP_hr member GROUP_engineering result <204 NO_CONTENT No Content,[cache-control:"no-cache", connection:"keep-alive", content-type:"application/json;charset=UTF-8", date:"Thu, 06 May 2021 13:09:51 GMT", expires:"Thu, 01 Jan 1970 00:00:00 GMT", pragma:"no-cache", server:"nginx/1.18.0", x-frame-options:"SAMEORIGIN"]>