首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >远程更新属性“cmis:creationDate和cmis:lastModificationDate”

远程更新属性“cmis:creationDate和cmis:lastModificationDate”
EN

Stack Overflow用户
提问于 2016-02-16 09:47:27
回答 1查看 540关注 0票数 0

我需要更新ReadOnly属性,比如'cm:creator或cm:created‘,所以我创建了一个java支持的webscript:

代码语言:javascript
复制
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);
    }

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

代码语言:javascript
复制
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;
    }

这个是可能的吗?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-16 10:36:28

您需要查看本教程来自JPotts才能熟悉Webscript开发

同时,正如在这里中所看到的,您可以使用以下方法获取参数:WebScriptRequest.getParameter(String),甚至从json有效负载中获取一个元素,如下所示:

代码语言:javascript
复制
    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
    }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35428992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档