Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Add group with ES2 Java API

Avatar

Level 2

Hi all,

there is an example that shows how to create a new group using the ES2 API here:

http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm

However, if you execute the code to create a group, the code works fine and a new OID is returned. But if you then go into the ES2 AdminUI and list all groups, you can not see the created Group "AdobeGroup" there! Also if you search in the AdminUI for the group "AdobeGroup" it can not be found.

So either the code is not working or the Admin UI does not show the newly created group!

What goes wrong here?

Thanks.
Paul.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Following code snippet should work for you

public String createSampleGroup() throws UMException{
        String groupOid = checkGroupExist(groupName);
       
        if(groupOid != null){
            return groupOid;
        }
        String groupCanonicalName = groupName;

        GroupImpl group = new GroupImpl();
        group.setCanonicalName(groupCanonicalName);
        group.setDomainName(domainName);
        group.setGroupType(Group.GROUPTYPE_PRINCIPALS);
        group.setLocal(true);
        group.setPrincipalType(Principal.PRINCIPALTYPE_GROUP);
       
        groupOid = directoryManager.createLocalGroup(group);
        log("Sample group created with name %s",groupName);
       
        return groupOid;
    }
   
    /**
     * Search the groupwith the given name in the sample domain
     */
    private String checkGroupExist(String groupName) throws UMException{
        PrincipalSearchFilter psf = new PrincipalSearchFilter();
        psf.setCommonName(groupName);
        psf.setSpecificDomainName(domainName);
       
        //By default the filter causes like search unless you are using the absolute version
        //Setting this ensures that search is exact
        psf.setMatchExactCriteria(true);
       
        //By default search returns obsolete users also. Set this to ensure that
        //only active users are returned
        psf.setRetrieveOnlyActive();
       
        //PrincipalReference are lightweight user objects and searching for them would be more performant
        //compared to the User search. If you do not require any other user attribute then prefer this
        //mode of search
        List<PrincipalReference> result = directoryManager.findPrincipalReferences(psf);
        if(result.isEmpty()){
            log("Sample group with name [%s] does not exist",groupName);
            return null;
        }else{
            String oid = result.get(0).getOid();
            log("Sample group with name [%s] already exist",groupName);
            return oid;
        }
    }

View solution in original post

5 Replies

Avatar

Level 10

Can you put the code?

The link just goes to the main documentation page.

Jasmin

Avatar

Correct answer by
Level 4

Following code snippet should work for you

public String createSampleGroup() throws UMException{
        String groupOid = checkGroupExist(groupName);
       
        if(groupOid != null){
            return groupOid;
        }
        String groupCanonicalName = groupName;

        GroupImpl group = new GroupImpl();
        group.setCanonicalName(groupCanonicalName);
        group.setDomainName(domainName);
        group.setGroupType(Group.GROUPTYPE_PRINCIPALS);
        group.setLocal(true);
        group.setPrincipalType(Principal.PRINCIPALTYPE_GROUP);
       
        groupOid = directoryManager.createLocalGroup(group);
        log("Sample group created with name %s",groupName);
       
        return groupOid;
    }
   
    /**
     * Search the groupwith the given name in the sample domain
     */
    private String checkGroupExist(String groupName) throws UMException{
        PrincipalSearchFilter psf = new PrincipalSearchFilter();
        psf.setCommonName(groupName);
        psf.setSpecificDomainName(domainName);
       
        //By default the filter causes like search unless you are using the absolute version
        //Setting this ensures that search is exact
        psf.setMatchExactCriteria(true);
       
        //By default search returns obsolete users also. Set this to ensure that
        //only active users are returned
        psf.setRetrieveOnlyActive();
       
        //PrincipalReference are lightweight user objects and searching for them would be more performant
        //compared to the User search. If you do not require any other user attribute then prefer this
        //mode of search
        List<PrincipalReference> result = directoryManager.findPrincipalReferences(psf);
        if(result.isEmpty()){
            log("Sample group with name [%s] does not exist",groupName);
            return null;
        }else{
            String oid = result.get(0).getOid();
            log("Sample group with name [%s] already exist",groupName);
            return oid;
        }
    }

Avatar

Level 2

Thanks a lot for the code, Chetan. It works great!

In my initial post I meant the Java class provided here:

http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm?content=002477.html#1576978

This code does not work, so it should be replaced by your working code ;-)

Thanks again.

Paul

Avatar

Level 4

I would be following up with the doc team to get that corrected

Avatar

Level 10

The Quick Start in Programming with LiveCycle ES2 has been updated to use this application logic