java - 远程更新属性 “cmis:creationDate and cmis:lastModificationDate”

标签 java alfresco alfresco-webscripts

我需要更新 alfresco 上的 ReadOnly 属性,例如“cm:creator 或 cm:created”,以便创建一个 Java 支持的网页脚本:

public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        Calendar cal = new GregorianCalendar();
        try {
            Date d = sdf.parse("21/12/2012");
            cal.setTime(d);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
        policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
        nodeService.setProperty(nodeRef, ContentModel.PROP_CREATED, cal);
        nodeService.setProperty(nodeRef, ContentModel.PROP_MODIFIED, cal);
        nodeService.setProperty(nodeRef, ContentModel.PROP_MODIFIER, "test");
        nodeService.setProperty(nodeRef, ContentModel.PROP_CREATOR, "test");
        policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
    }

一切正常,但我需要使用客户端发送的远程值设置属性,而不仅仅是本地值:

public Document createDocument(Folder folder,String name,String actId) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        Date d = sdf.parse("21/12/2012");
        Map<String, Object> properties = new HashMap<String, Object>();
        Calendar cal = new GregorianCalendar();
        cal.setTime(d);
        //properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled,P:cm:author");
        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.CREATED_BY, "createdBy");
        properties.put(PropertyIds.LAST_MODIFIED_BY, "modifiedBy");
        properties.put(PropertyIds.CREATION_DATE, cal);
        properties.put(PropertyIds.LAST_MODIFICATION_DATE, cal);
        properties.put("cm:title", "Title");
        properties.put("cm:description", "Description");
        properties.put("cm:author", "author");
        byte[] content = "Hello World!".getBytes();
        InputStream stream = new ByteArrayInputStream(content);
        ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(content.length), "text/plain", stream);
        Document newDoc = folder.createDocument(properties, contentStream, VersioningState.MAJOR);
        return newDoc;
    }

这可能吗?提前致谢。

最佳答案

您需要查看this tutorial from JPotts熟悉Webscript development .

同时,正如您在 here 中看到的那样您可以使用以下方法获取 get 参数:WebScriptRequest.getParameter(String),甚至可以从 json 负载中获取元素,如下所示:

    String params = "{}";
    String myVar;
    try {
        params = IOUtils.toString(req.getContent().getInputStream(),
                "UTF-8");
    } catch (IOException e1) {
        // Handle exception properly
    }
    JSONObject postParams;
    try {
        postParams = new JSONObject(params);
        if (postParams.has("some-attribute")){
            myVar = postParams.getString("some-attribute");
        }
    } catch (JSONException e1) {
        // Handle exception properly
    }

关于java - 远程更新属性 “cmis:creationDate and cmis:lastModificationDate”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35428992/

相关文章:

java - 如何将上下文模型值链接到露天的数据列表项?

java - 如何正确读取 Flux<DataBuffer> 并将其转换为单个 inputStream

java - 排序 LinkedHashMap

alfresco - 如何在登录后重定向网站成员

java - 用于上传文件的WebScript : during the first upload one extra version created

用于获取自定义元数据的 Alfresco Restful API

java - 通过 iCalendar vEvent 禁用 outlook "propose new time"按钮

java - 检查一个字符串是否包含另一个字符串的所有字符

javascript - 删除 Alfresco Share 中的文件夹

java - 如何使用 CMIS 在 Alfresco 中进行批量更新