IBM SBT:在社区中创建文件夹 [英] IBM SBT: Create a folder in a community

查看:110
本文介绍了IBM SBT:在社区中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java的SBT工具包.效果很好,但是在使用文件夹时遇到了一些困难:

I'm getting my hands on the SBT Toolkit with Java. Works great but having some difficulties with folders:

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

I need to create a folder in a community and put some files into it. Unfortunately, the class CommunityService has no such method.

我可以使用FileService.createFolder(name, description, shareWith)方法并与社区共享,但实际上我只希望社区中的文件,因为否则它们在文件应用程序中可见(公开,警告消息:与公众共享社区社区名称"将此文件夹公开.")

I could use the FileService.createFolder(name, description, shareWith) method and share it with the community, but actually i only want the files in the community, because otherwise they're visible in the files application (public, warning message: "Sharing with the public community 'COMMUNITY NAME' will make this folder public.")

我该如何实现?

我检查了社区/文件小部件中的按钮,发现它正在对社区feed进行POST:

I checked out the button in the community / files widget and found out that it is doing a POST to the communities feed:

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

POST内容:

<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服务吗?如果是,语法是什么?我还没有找到任何文档或示例.

So, could I use the communityService.createData method to invoke this REST service? If yes, whats the syntax? I haven't found any documentation or examples for it.

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

Also, I need to get the ID of the folder after it is created, but I this i can parse from the response..

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

Adding files to the newly created folder should be easy (SBT provides corresponding classes and methods), but i didn't work with this yet :-)

推荐答案

我找到了解决方案.. 虽然我宁愿使用JSON,也许Xerces XML Document的句柄并不是很优雅,因为我没有使用它的经验..但是它可以工作..

I've found a solution .. altough i would rather use JSON, and maybe the handle of the Xerces XML Document is not really elegant since i have not experience with it.. but it works..

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

这篇关于IBM SBT:在社区中创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆