是否可以使用OpenCMIS API在Alfresco站点上创建文件夹?

时间:2017-10-06 12:10:49

标签: alfresco cmis alfresco-webscripts opencmis

我有Presentation Web Scriptscript A)和Data Web Scriptscript B)。

script A我构建了与script B交互的对话框。

enter image description here

我在这里形成一些路径,其中某个文件将被上传(groupyearnumber参数定义此路径):

...
var submitHandler = function() {
    var dataWebScriptUrl = window.location.protocol + '//' + 
        window.location.host + "/alfresco/s/ms-ws/script-b?guest=true";

    var yearCombo = document.getElementById("year");
    var year = yearCombo.options[yearCombo.selectedIndex].value;

    var groupCombo = document.getElementById("group");
    var group = groupCombo.options[groupCombo.selectedIndex].value;

    var numberCombo = document.getElementById("number");
    var number = numberCombo.value;

    var uploadedFile = document.getElementById("uploadedFile");
    var file = uploadedFile.files[0];

    var formData = new FormData();
    formData.append("year", year);
    formData.append("group", group);
    formData.append("number", number);
    formData.append("uploadedFile", file);      

    var xhr = new XMLHttpRequest();
    xhr.open("POST", dataWebScriptUrl);
    xhr.send(formData);
};
...

script B中,我使用Apache Chemistry OpenCMIS APICMIS兼容的Alfresco存储库中创建路径:

public class CustomFileUploader extends DeclarativeWebScript implements OpenCmisConfig {
    ...
    private void retrievePostRequestParams(WebScriptRequest req) {
        String groupName = null, year = null, number = null;

        FormData formData = (FormData) req.parseContent();
        FormData.FormField[] fields = formData.getFields();
        for(FormData.FormField field : fields) {
            String fieldName = field.getName();
            String fieldValue = field.getValue();

            if(fieldName.equalsIgnoreCase("group")) {
                if(fieldValue.equalsIgnoreCase("services")) {
                    groupName = "Услуги";
                ...                         
        }

        firstLevelFolderName = "/" + groupName;
        secondLevelFolderName = groupName + " " + year; 
        thirdLevelFolderName = number;
    }

    ...

    Folder firstLevelFolder = 
                createFolderIfNotExists(cmisSession, docLibFolder, firstLevelFolderName);

    ...

    private Folder createFolderIfNotExists(Session cmisSession, 
            Folder parentFolder, String folderName) {
        Folder subFolder = null;
        for(CmisObject child : parentFolder.getChildren()) {
            if(folderName.equalsIgnoreCase(child.getName())) {
                subFolder = (Folder) child;
            }
        }

        if(subFolder == null) {
            Map<String, Object> props = new HashMap<>();
            props.put("cmis:objectTypeId", "cmis:folder");
            props.put("cmis:name", folderName);

            subFolder = parentFolder.createFolder(props);
        }
        return subFolder; 
    }

    private Folder getDocLibFolder(Session cmisSession, String siteName) {
        String path = "/Sites/" + siteName + "/documentLibrary";
        return (Folder) cmisSession.getObjectByPath(path);
    }

    private Session getCmisSession() {
        SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> conf = new HashMap<>();

        // http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom
        conf.put(SessionParameter.ATOMPUB_URL, ATOMPUB_URL);
        conf.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
        conf.put(SessionParameter.USER, USER_NAME);
        conf.put(SessionParameter.PASSWORD, PASSWORD);

        // "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"
        conf.put(SessionParameter.OBJECT_FACTORY_CLASS, OBJECT_FACTORY_CLASS);
        conf.put(SessionParameter.REPOSITORY_ID, "-default-");

        Session session = factory.createSession(conf);

        return session;
    }

    ...

一切运作良好......但我需要在特定网站上创建目录结构,例如“contract-site”,在这里:

/site/contracts-site/documentlibrary

当我指定以下内容时:

/Sites/contracts-site/documentLibrary/Услуги
/Sites/contracts-site/Услуги
/site/contracts-site/documentlibrary/Услуги

我得到以下异常(取决于路径):

org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException: Object not found: /Sites/contracts-site/Услуги

当我指定以下内容时:

"/Услуги"

一切正常,但目录结构是在网站外创建的......

如何使用OpenCMIS API在Alfresco网站上创建文件夹?

我将非常感谢这些信息。谢谢大家。

感谢所有人。

2 个答案:

答案 0 :(得分:2)

你错过了/company_home/吗?

这会导致

/company_home/Sites/contracts-site/documentLibrary/Услуги

答案 1 :(得分:1)

偶然发现了解决方案。如果指定以下路径,则可以正常工作:

// locate the document library
String path = "/Сайты/contracts-site/documentLibrary";

"Сайты"代替"Sites" ...(西里尔字母)

我使用ru_RU语言环境和UTF-8编码。然后this example也有效。