Удаленно обновлять свойства cmis:creationDate и cmis:lastModificationDate.

Мне нужно обновить свойства 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;
    }

Это возможно? Заранее спасибо.


person Sfayn    schedule 16.02.2016    source источник


Ответы (1)


Чтобы получить знаком с разработкой веб-скриптов.

Тем временем, как вы можете видеть в здесь вы можете получить параметры с помощью этого метода: 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
    }
person Younes Regaieg    schedule 16.02.2016
comment
большое спасибо, он отлично работает с webscirpt с поддержкой Java. - person Sfayn; 17.02.2016