cancel
Showing results for 
Search instead for 
Did you mean: 

Java API-find parent group

redbull
Champ in-the-making
Champ in-the-making
Hi,
in my system I have some groups and each group has a sub-group.
How I can get the parent of a specific sub-group?
thank you.
2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
You can refer the AuthorityService APIs to achieve this

swanands
Champ in-the-making
Champ in-the-making
You might want to check these out:
<a href="http://docs.alfresco.com/4.2/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPI-JS-Au...">Alfresco - Javascript API - Authority Service</a>

getGroups() & searchGroups() should do the trick in your case.

Copying sample code from <a href="http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/remote-api/source/jav...">Here</a>


/**
     * Detailed test of get Parents
     */
    public void testGetParents() throws Exception
    {
        createTestTree();
       
       /**
        * Get all parents for the root group ALFRESCO_ADMINISTRATORS groups which has no parents
        */
       {
          Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP + "/parents"), Status.STATUS_OK);
          JSONObject top = new JSONObject(response.getContentAsString());
          logger.debug(response.getContentAsString());
          JSONArray data = top.getJSONArray("data");
          // Top level group has no parents
          assertTrue("top level group has no parents", data.length() == 0);
       }
       
       /**
        * Get GROUP B   Which should be a child of TESTROOT
        */
       {
          Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/parents"), Status.STATUS_OK);
          JSONObject top = new JSONObject(response.getContentAsString());
          logger.debug(response.getContentAsString());
          JSONArray data = top.getJSONArray("data");
          assertTrue(data.length() > 0);
       }
       
          /**
        * Get GROUP D   Which should be a child of GROUPB child of TESTROOT
        */
       {
          Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"), Status.STATUS_OK);
          JSONObject top = new JSONObject(response.getContentAsString());
          logger.debug(response.getContentAsString());
          JSONArray data = top.getJSONArray("data");
          assertTrue(data.length() >= 2);
       }