在SDK Javadoc中,Community类没有"setParentCommunity“方法,但是CommunityList类有getSubCommunities方法,所以必须有一种编程方式来设置父社区的Uuid来创建新的社区。REST API提到了一个“rel=”元素“http://www.ibm.com/xmlns/prod/sn/parentcommunity”。在寻找线索时,我检查了一个现有的子社区的XmlDataHandler的节点,发现了一个link元素。我尝试获取一个新创建的社区的XmlDataHandler,并添加一个带有href、rel和类型节点的链接节点,这些节点与现有社区中的节点类似,但在尝试更新或重新保存社区时,我收到了一个错误的请求错误。实际上,即使我尝试调用dataHandler.setData(n) (其中n被设置为Node ();)而不做任何更改,然后调用updateCommunity或save,我也得到了相同的错误,因此似乎操作dataHandler XML是无效的。
在创建新社区以便将其创建为SubCommunity时,指定父社区的推荐方式是什么?
发布于 2013-10-18 21:07:36
以编程方式创建子社区的正确方法是修改POST请求正文以创建社区-这里是到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的链接。我们在SBT SDK中不支持使用CommunityService API执行此操作。我们需要使用低级Java,使用Endpoint和ClientService类来直接调用具有适当请求主体的REST。
发布于 2013-10-22 00:06:46
我将继续扩展CommunityService类,然后添加CommunityService
第605行公共字符串createCommunity(社区社区)抛出CommunityServiceException { if (空==社区){抛出新的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。
发布于 2013-10-23 20:43:42
我按照@PaulBastide的建议创建了一个SubCommunityService类,目前只包含一个用于创建的方法。它包装了CommunityService而不是子类化它,因为我发现这样做更可取。如果你想重用它,下面是代码:
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;
}}
https://stackoverflow.com/questions/19437763
复制相似问题