cancel
Showing results for 
Search instead for 
Did you mean: 

create a group on domain creation

bledii_
Confirmed Champ
Confirmed Champ

Hi All i need to create a group on every domain creation, and assign some access rights to this group.

I am thinking of adding an operation and then using an event listener to call the operation on document creation.

I can not seem to find the right method to call for the creation of the group.

I am using version 5.6.

EDIT, rephrasing my question:

in this method call

DocumentModel createGroup(DocumentModel groupModel)
                      throws ClientException,
                             GroupAlreadyExistsException)

What should be the DocumentModel i should pass for a new group ?

3 REPLIES 3

bledii_
Confirmed Champ
Confirmed Champ

The answer was already in some other question, just needed to dig deeper.

Here for reference of others who might need it :

Link

Laurent_Doguin
Star Collaborator
Star Collaborator

Here's the complete code for the operation

  package org.nuxeo.sample;
  
  import org.nuxeo.ecm.automation.core.Constants;
  import org.nuxeo.ecm.automation.core.annotations.Context;
  import org.nuxeo.ecm.automation.core.annotations.Operation;
  import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
  import org.nuxeo.ecm.automation.core.annotations.Param;
  import org.nuxeo.ecm.core.api.ClientException;
  import org.nuxeo.ecm.core.api.DocumentModel;
  import org.nuxeo.ecm.platform.usermanager.UserManager;
  
  /**
   * @author ldoguin
   */
  @Operation(id = CreateGroup.ID, category = Constants.CAT_USERS_GROUPS, label = "Create Group", description = "This operation creates a new group using the given       group label and group id.", since = "5.7.3")
  public class CreateGroup {
  
      public static final String ID = "CreateGroup";
  
      @Context
      UserManager userManager;
  
      @Param(name = "Group Id", required = true)
      String groupId;
  
      @Param(name = "Group Label", required = true)
      String goupLabel;
  
      @Param(name = "Group Description", required = false, widget = Constants.W_MULTILINE_TEXT )
      String description;
  
      @OperationMethod
      public DocumentModel run() throws ClientException {
          DocumentModel groupModel = userManager.getBareGroupModel();
          groupModel.setProperty("group", "groupname", groupId);
          groupModel.setProperty("group", "grouplabel", goupLabel);
          groupModel.setProperty("group", "description", description);
          groupModel = userManager.createGroup(groupModel);
          return groupModel;
      }
  
  }

Hello Laurent

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.