5 Replies Latest reply: Apr 29, 2010 1:09 PM by smacdonald2008 RSS

    Add group with ES2 Java API

    Paul_Kuhn Community Member

      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. Re: Add group with ES2 Java API
          Jasmin Charbonneau techies

          Can you put the code?

           

          The link just goes to the main documentation page.

           

          Jasmin

          • 2. Re: Add group with ES2 Java API
            Chetan Mehrotra techies

            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;
                    }
                }
            • 3. Re: Add group with ES2 Java API
              Paul_Kuhn Community Member

              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#157 6978

               

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

               

              Thanks again.

              Paul

              • 4. Re: Add group with ES2 Java API
                Chetan Mehrotra techies

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

                • 5. Re: Add group with ES2 Java API
                  smacdonald2008 techies

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