2013-10-17 32 views
1

在SDK Javadoc中,Community類沒有「setParentCommunity」方法,但CommunityList類確實有getSubCommunities方法,所以必須有一種編程方式來在創建新社區時設置父級社區的Uuid。 REST API提到了一個「rel =」http://www.ibm.com/xmlns/prod/sn/parentcommunity「元素」。在查找線索時,我查看了現有子社區的XmlDataHandler節點並找到了鏈接元素。我嘗試爲新創建的社區獲取XmlDataHandler,並添加一個帶有與現有社區中類似的href,rel和type節點的鏈接節點,但試圖更新或重新保存社區時,我收到了錯誤的請求錯誤。其實,即使當我嘗試調用dataHandler.setData(n),其中n被設置爲節點n = dataHandler.getData();沒有任何改變,然後調用updateCommunity或保存我得到了同樣的錯誤,所以看起來操縱dataHandler XML是無效的。如何使用Social Business Toolkit Java API創建子社區?

創建新社區時,建議指定父社區的建議方式是什麼,以便將其創建爲子社區?

+0

我不知道,但是我會問馬尼什迴應 –

+0

你應該讓GitHub上發佈請求 - https://開頭github.com/OpenNTF/SocialSDK/issues?state=open –

+0

https://github.com/OpenNTF/SocialSDK/issues/706 –

回答

0

以編程方式創建一個子社區的正確方法是修改POST請求主體的社區創建 - 這裏是鏈接到連接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支持,做到這一點使用社區服務API。我們需要使用Endpoint和ClientService類的低級別Java API,通過適當的請求體直接調用REST API。

+0

有沒有可用的代碼示例?該鏈接的文檔指出我「在正確的方向」,但是非常小。 –

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 公共字符串createCommunity(community社區)拋出CommunityServiceException { 如果(空==社區){ 拋出新的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。

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

}

+0

工作得很好!我做的唯一更改是: 1.在源代碼中保護了communityService.resolveCommunityUrl,創建了一個擴展了communityService並使該方法公開的「MyCommunityService」類,然後引用myCommunityService而不是communityService 2. clientService的響應。需要成爲Response對象/無法直接投射到字符串 –

+0

很高興聽到它的工作!我的這個實現是基於比較老的SBT版本,所以你可能會提到剛剛改變的東西。如果你不堅持使用公共API,這是一個折衷;在正式實施之前,仍然是一個很好的解決方法。 – BennyLau

相關問題