如何使用Social Business Toolkit Java API创建子社区?

时间:2013-10-17 21:35:39

标签: ibm-sbt

在SDK的Javadoc,社区类不具有“setParentCommunity”的方法,但CommunityList类确实有一个getSubCommunities方法,因此必须有设置父社区的UUID新社区创建一种编程方式。 REST API提到“rel =”http://www.ibm.com/xmlns/prod/sn/parentcommunity“元素”。在寻找线索的同时,我检查了现有Subcommunity的XmlDataHandler节点并找到了一个链接元素。我尝试为新创建的社区获取XmlDataHandler,并添加一个链接节点,其中href,rel和类型节点类似于现有社区中的节点,但在尝试更新或重新保存社区时,我收到了错误的请求错误。实际上即使我尝试调用dataHandler.setData(n),其中n被设置为Node n = dataHandler.getData();没有任何更改,然后调用updateCommunity或保存我得到了相同的错误,因此看起来操纵dataHandler XML无效。

在创建新社区时指定父社区的建议方法是什么,以便将其创建为子社区?

3 个答案:

答案 0 :(得分:0)

以编程方式创建子社区的正确方法是修改POST请求正文以进行社区创建 - 这是指向Connections 45信息中心的链接 - 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 我们在SBT SDK中没有使用CommunityService API来支持这一点。我们需要使用使用Endpoint和ClientService类的低级Java API直接使用适当的请求体调用REST API。

答案 1 :(得分:0)

我会继续扩展CommunityService类 然后继续添加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 605行 public String createCommunity(社区社区)抛出CommunityServiceException {                 if(null == community){                         抛出新的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);
            }
    }

您需要更改您的communityPostUrl以匹配... https://greenhouse.lotus.com/communities/service/atom/community/subcommunities?communityUuid=2fba29fd-adfa-4d28-98cc-05cab12a7c43

这里的Uuid是父uuid。

答案 2 :(得分:0)

我遵循@PaulBastide的建议并创建了一个SubCommunityService类,目前只包含一个创建方法。它包装社区服务而不是子类化,因为我发现它是可取的。以下是您想要重用它的代码:

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;
    }

}

相关问题