Alfresco can I Change properties "cmis:creationDate and cmis:lastModificationDate" Updatablity?

2k views Asked by At

Hi and thanks in advance for the help

I have a problem with insertion and update documents in alfresco, So when I set a property like "cmis:creationDate or cmis:lastModificationDate", the document is created successfully but the properties that has Updatability=ReadOnly doesn't set to the new value given it's set automatically by alfresco. Is there any solution to set Updatibility of these properties to "ReadWrite"? I'm using Aalfresco 5.0 and openCmis 0.13 this is my code :

public void createDocument(Folder folder) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date d = sdf.parse("21/12/2012");
    String name = "myNewDocument.txt";
    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.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");
    properties.put("cmis:creationDate ", cal);
    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);
}
1

There are 1 answers

3
DocWatson On BEST ANSWER

Updating the read only fields requires work on the Alfresco side. There are policies in place that prevent properties of the aspect cm:auditable from being changed.

You can update the fields in Alfresco using the NodeService API after you've disabled that policy behavior. Here's an example:

policyBehaviourFilter.disableBehaviour(node, ContentModel.ASPECT_AUDITABLE); 
// Update CreatedDate
nodeService.setProperty(node, ContentModel.PROP_CREATED, dateTime);
//Enable policy
policyBehaviourFilter.enableBehaviour(node, ContentModel.ASPECT_AUDITABLE);

You could package this into a custom webscript to allow the properties to be changed remotely.