cancel
Showing results for 
Search instead for 
Did you mean: 

How to change cm:created property of a node?

sebp
Champ in-the-making
Champ in-the-making
I have the following code to set the create date of a node:


Date d = importSet.simpleDateFormat.parse(extractedDateString);
Map<QName, Serializable> props = nodeService.getProperties(actionedUponNodeRef);
props.put(ContentModel.PROP_TITLE, "someNewName");
props.put(ContentModel.PROP_CREATED, d);
nodeService.setProperties(actionedUponNodeRef, props);


Using Alfresco Labs 2.9 I was able to set the create date. In 3.2 Community this code is not working. Only the title is set but not the create date. Is there another way of changing the created property? Did I miss something?
6 REPLIES 6

sebp
Champ in-the-making
Champ in-the-making
Ok, found the solution. Get hold of the policyBehaviourFilter first and disable cm:auditable behaviour for the current transaction.

ph_francois
Champ in-the-making
Champ in-the-making
Dear sebp,

I'm interested by the solution you found for this.

May I ask you to be more precice on how you "Get hold of the policyBehaviourFilter first and disable cm:auditable behaviour for the current transaction" and confirm that the solution you found is working on 3.2r2 Community version

Thanks in advance

Philippe

sebp
Champ in-the-making
Champ in-the-making
Hi Philippe,

I took these snippets out of my code and changed it a little bit. I hope it still works, but the important things should become clear now. When executing the action MyAction on a node it will replace the created-date of the node with the current date. Normally the auditable aspect prevents some node properties (create-date, created-by) from being changed. But the auditable aspect can be disabled for the current transaction. This is done by calling disableBehaviour(ContentModel.ASPECT_AUDITABLE) on the PolicyBehaviourFilter before the node is updated.


public class MyAction extends ActionExecuterAbstractBase {
   NodeService nodeService;
   BehaviourFilter behaviourFilter;

        @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
           Date d = Calendar.getInstance().getTime();
           Map<QName, Serializable> props = nodeService.getProperties(actionedUponNodeRef);
           props.put(ContentModel.PROP_CREATED, d);
           behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
           nodeService.setProperties(actionedUponNodeRef, props);
       }
}


    <bean name="myAction" class="de.hmedia.alfresco.actions.MyAction" parent="action-executer">
        <property name="nodeService" ref="nodeService"/>
        <property name="behaviourFilter">
         <ref bean="policyBehaviourFilter" />
        </property>
    </bean>

swardi
Champ in-the-making
Champ in-the-making
i am using the alfresco webservices API. i tried to find out how to set CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_AUDITABLE, null, predicate, null);
but i dont find it in constants class. i mean Constants.ASPECT_AUDITABLE.

gyro_gearless
Champ in-the-making
Champ in-the-making
Hi,

seems like Constants.java has some omissions, see for example http://issues.alfresco.com/jira/browse/ALF-2174 (which also means it is quite easy to make a workaround).

However, it is usually not necessary to manually add the "cm:auditable" aspect to new content, as this is done automagically by Alfresco!

Cheers
Gyro

swardi
Champ in-the-making
Champ in-the-making
Yes, there are added authomaticaly by alfresco. But i d like to set the document "modifier" property and the "created" and "modified" property how can i do that. do you have any examples?

Thanks a lot.