java - IBM SBT : Create a folder in a community

标签 java ibm-connections ibm-sbt

我正在使用 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/

相关文章:

java - 在数据绑定(bind)中将另一个 View 作为参数传递

css - 如何将 IBM Connections 名片与外部应用程序集成并轻松定位样式?

lucene - 将其他来源集成到 IBM Connections 搜索中

ibm-connections - IBM 连接

java - 如何使用Abdera atom客户端发送内容和附件

java - 使用 SBT 将组作为成员添加到 Connections Activity 中?

java - 寻找一种用于对不同类型的对象进行排序的算法

java - 如何平滑地根据容器大小自动调整多个 JLabel 的字体大小?

java - 我不能使用 .properties "override"@NotEmpty 消息