gpt4 book ai didi

java - IBM SBT : Create a folder in a community

转载 作者:行者123 更新时间:2023-11-30 09:00:09 25 4
gpt4 key购买 nike

我正在使用 Java 获取 SBT 工具包。效果很好,但在处理文件夹时遇到一些困难:

我需要在社区中创建一个文件夹并将一些文件放入其中。不幸的是,CommunityService 类没有这样的方法。

我可以使用 FileService.createFolder(name, description, shareWith) 方法并与社区共享它,但实际上我只想要社区中的文件,否则它们在文件应用程序(公开的警告消息:“与公共(public)社区共享‘COMMUNITY NAME’将使该文件夹公开。”)

我怎样才能做到这一点?

我检查了社区/文件小部件中的按钮,发现它正在向社区提要发送 POST:

目标网址:https://connections.host.ch/files/form/api/communitycollection/{community-uuid}/feed

发布内容:

<entry xmlns="http://www.w3.org/2005/Atom">
<category term="collection" label="collection" scheme="tag:ibm.com,2006:td/type"></category>
<label xmlns="urn:ibm.com/td" makeUnique="true">TEST Folder</label>
<title>TEST Folder</title>
<summary type="text">teset set e</summary>
</entry>

那么,我可以使用 communityService.createData 方法来调用此 REST 服务吗?如果是,语法是什么?我还没有找到它的任何文档或示例。

此外,我需要在文件夹创建后获取它的 ID,但我可以从响应中解析它..

向新创建的文件夹中添加文件应该很容易(SBT 提供了相应的类和方法),但我还没有使用它:-)

最佳答案

我找到了一个解决方案..尽管我更愿意使用 JSON,而且 Xerces XML 文档的句柄可能不是很优雅,因为我没有使用它的经验......但它有效......

    public String createFolderInCommunity() {

String folderId = "";

try {

// this is the atom entry.. would be nices if it was JSON..
String entry = "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:app=\"http://www.w3.org/2007/app\" xmlns:snx=\"http://www.ibm.com/xmlns/prod/sn\">"
+ "<category term=\"collection\" label=\"collection\" scheme=\"tag:ibm.com,2006:td/type\"></category>"
+ "<label xmlns=\"urn:ibm.com/td\" makeUnique=\"true\">TESTssss4444</label>"
+ "<title>Test: "
+ (new Date()).toString()
+ "</title>"
+ "<summary type=\"text\">teset set e</summary>"
+ "</entry>";

// Request URI with the Community ID.. of course the community id
// will be given as a parameter
String requestUri = "/files/form/api/communitycollection/1802d0e8-f6b8-4d51-8db0-75997ed83489/feed";
String payload = entry;

// here would be the point of using APPLICATION_JSON, but did not
// find any documentation about the JSON Object format :-(
ClientService.ContentString cc = new ClientService.ContentString(
payload, CommonConstants.APPLICATION_ATOM_XML);

// create the service uppon the IBM Connections endpoint (in this
// case SSO)
Response response = getEndPoint().getClientService().post(
requestUri, cc);

// Getting the object as a apache xerces DeferredDocumentImpl, with
// which i have absolutely no experience..
DeferredDocumentImpl obj = (DeferredDocumentImpl) response
.getData();

NodeList lstNodes = obj.getFirstChild().getChildNodes();

// so getting the value this way might be clumsy, but it works...
for (int x = 0; x < lstNodes.getLength(); x++) {
String name = lstNodes.item(x).getNodeName();
if (name.equals("td:uuid")) {
folderId = lstNodes.item(x).getFirstChild()
.getTextContent();
break;
}
}
} catch (Exception e) {
Util.logError(e);
}

return folderId;
}

关于java - IBM SBT : Create a folder in a community,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26912475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com