7.2.2. Managing groups

This section shows you how to create, update, and remove groups from the portal via two ways:

You can follow the snippet below to list groups which are children of the platform group:

try {

      Group platformGroup = groupHandler.findGroupById("/platform");
      Collection<Group> groups = groupHandler.findGroups(platformGroup);
      for (Group group : groups) {
        writer.append("<dl class='dl-horizontal'>");
        writer.append("<dd>" + group.getId() + "</dd>");
        writer.append("<dd>" + group.getGroupName() + "</dd>");
        writer.append("<dd>" + group.getLabel() + "</dd>");

The groups list is displayed like this in your product:

Creating a group

Create a portlet action, then add the snippet below to it.

    Group group = groupHandler.createGroupInstance();

    group.setLabel("New Group");
    Group platformGroup = groupHandler.findGroupById("/platform");
    groupHandler.addChild(platformGroup, group, false);

Executing the portlet action allows creating a group called newgroup which is the child of the platform group.

Updating a group

After creating a group, you should update a label for it as its display name.

    Group newGroup = groupHandler.findGroupById("/platform/newgroup");

    newGroup.setLabel("New Group Updated");
    groupHandler.saveGroup(newGroup, false);

The snippet above allows setting the New Group Updated label for the newgroup group.

Removing a group

Create a portlet action which executes the snippet below to remove a group, for example newgroup:

Group newGroup = groupHandler.findGroupById("/platform/newgroup");

    groupHandler.removeGroup(newGroup, false);
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus