1

In the SDK Javadoc, the Community class does not have a "setParentCommunity" method but the CommunityList class does have a getSubCommunities method so there must be a programmatic way to set a parent Community's Uuid on new Community creation. The REST API mentions a "rel="http://www.ibm.com/xmlns/prod/sn/parentcommunity" element". While looking for clues I check an existing Subcommunity's XmlDataHandler's nodes and found a link element. I tried getting the XmlDataHandler for a newly-created Community and adding a link node with href, rel and type nodes similar to those in the existing Community but when trying to update or re-save the Community I got a bad request error. Actually even when I tried calling dataHandler.setData(n) where n was set as Node n=dataHandler.getData(); without any changes, then calling updateCommunity or save I got the same error, so it appears that manipulating the dataHandler XML is not valid.

What is the recommended way to specify a parent Community when creating a new Community so that it is created as a SubCommunity ?

3 Answers3

0

The correct way to create a sub-community programatically is to modify the POST request body for community creation - here is the link to the Connections 45 infocenter - http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Creating_subcommunities_programmatically_ic45&content=pdcontent We do not have support in the SBT SDK to do this using CommunityService APIs. We need to use low level Java APIs using Endpoint and ClientService classes to directly call the REST APIs with the appropriate request body.

0

I'd go ahead and extend the class CommunityService then go ahead and add CommunityService

https://github.com/OpenNTF/SocialSDK/blob/master/src/eclipse/plugins/com.ibm.sbt.core/src/com/ibm/sbt/services/client/connections/communities/CommunityService.java Line 605 public String createCommunity(Community community) throws CommunityServiceException { if (null == community){ throw new CommunityServiceException(null, Messages.NullCommunityObjectException); }

            try {
                    Object communityPayload;
                    try {
                            communityPayload = community.constructCreateRequestBody();
                    } catch (TransformerException e) {
                            throw new CommunityServiceException(e, Messages.CreateCommunityPayloadException);
                    }
                    String communityPostUrl = resolveCommunityUrl(CommunityEntity.COMMUNITIES.getCommunityEntityType(),CommunityType.MY.getCommunityType());
                    Response requestData = createData(communityPostUrl, null, communityPayload,ClientService.FORMAT_CONNECTIONS_OUTPUT);
                    community.clearFieldsMap();
                    return extractCommunityIdFromHeaders(requestData);
            } catch (ClientServicesException e) {
                    throw new CommunityServiceException(e, Messages.CreateCommunityException);
            } catch (IOException e) {
                    throw new CommunityServiceException(e, Messages.CreateCommunityException);
            }
    }

You'll want to change your communityPostUrl to match... https://greenhouse.lotus.com/communities/service/atom/community/subcommunities?communityUuid=2fba29fd-adfa-4d28-98cc-05cab12a7c43

and where the Uuid here is the parent uuid.

Paul Bastide
  • 1,505
  • 4
  • 17
  • 22
0

I followed @PaulBastide 's recommendation and created a SubCommunityService class, currently only containing a method for creation. It wraps the CommunityService rather than subclassing it, since I found that preferrable. Here's the code in case you want to reuse it:

public class SubCommunityService {

    private final CommunityService communityService;

    public SubCommunityService(CommunityService communityService) {
         this.communityService = communityService;
    }

    public Community createCommunity(Community community, String superCommunityId) throws ClientServicesException {
        Object constructCreateRequestBody = community.constructCreateRequestBody();
        ClientService clientService = communityService.getEndpoint().getClientService();

        String entityType = CommunityEntity.COMMUNITY.getCommunityEntityType();
        Map<String, String> params = new HashMap<>();
        params.put("communityUuid", superCommunityId);

        String postUrl = communityService.resolveCommunityUrl(entityType,
        CommunityType.SUBCOMMUNITIES.getCommunityType(), params);

        String newCommunityUrl = (String) clientService.post(postUrl, null,  constructCreateRequestBody,
            ClientService.FORMAT_CONNECTIONS_OUTPUT);
        String communityId = newCommunityUrl.substring(newCommunityUrl.indexOf("communityUuid=")
            + "communityUuid=".length());

        community.setCommunityUuid(communityId);
        return community;
    }

}

BennyLau
  • 107
  • 8
  • Worked well ! .. the only changes I made were: 1. communityService.resolveCommunityUrl is protected in the source code so created a "MyCommunityService" class which extended communityService and made the method public, then referenced myCommunityService instead of communityService 2. response from clientService.post needed to be a Response object/ could not cast to a String directly – Bill McNaughton Dec 05 '13 at 17:01
  • Glad to hear it worked! I had this implemented based on a somewhat older version of the SBT, so it might be that the things you mentioned just changed in the meantime. That's the tradeoff if you don't stick to public API; still a good workaround until it's officially implemented. – BennyLau Dec 06 '13 at 18:27