1

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);
}
Sfayn
  • 190
  • 1
  • 2
  • 13

1 Answers1

5

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.

DocWatson
  • 692
  • 5
  • 13
  • Shouldn't he re-enable behaviour for that aspect once he played with those props ? – Younes Regaieg Feb 10 '16 at 14:56
  • Thanks a lot for your answer, but i'm really new in alfresco, would you please give me more details about how to do this on alfresco side, are you talking about Alfresco source code ? which files should I modify? – Sfayn Feb 10 '16 at 15:43
  • 2
    That question is a bit beyond the scope of a single thread. You will want to look at some tutorials on extending Alfresco. Here are a couple of resources to get you started: https://wiki.alfresco.com/wiki/Developer_Guide & http://ecmarchitect.com/alfresco-developer-series-tutorials/ – DocWatson Feb 10 '16 at 17:32