cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the modified date ?

lme
Champ in-the-making
Champ in-the-making
Hi,

Is it possible to define a date for the meta-data {http://www.alfresco.org/model/content/1.0}modified via webservice ? I'm using CML to set various meta-data (creation date, title, etc.), they are all set correctly except "modified".

Regards,
Laurent
4 REPLIES 4

rmills
Champ in-the-making
Champ in-the-making
Also interested.  We're trying to migrate a current system from Sharepoint and maintain the audit trail.  Trying to update the modified date and modifier via webscript doesn't work.  After setting the new property values, a node.save() is necessary to store them in Alfresco.  However, that node.save() updates the modifier to the account running the webscript and the modified date to the time the save was called.

rmills
Champ in-the-making
Champ in-the-making
So, we came up with a workaround that was really easy to implement.  Basically, you need to turn off the audit trail while updating the values.  After looking into it, we noticed that the AuditableAspect class has a method onUpdateAudit(NodeRef nodeRef) that is called every time the document is saved.  We wrote a class that extends the AuditableAspect and basically skips over the updating of the audit trail when you change properties:

package com.tsgrp.alfresco.repo.audit;

import org.alfresco.repo.audit.AuditableAspect;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CustomAuditableAspect extends AuditableAspect {

    // Logger
    private static final Log logger = LogFactory.getLog(CustomAuditableAspect.class);
   
   private boolean runSuper = true;
   public void setRunSuper(boolean value) { this.runSuper = value; }
   
   /**
     * Maintain audit properties on update of node
     *
     * @param nodeRef  the updated node
     */
    public void onUpdateAudit(NodeRef nodeRef)
    {      
        logger.debug("In CustomAuditableAspect.onUpdateAudit(NodeRef nodeRef)…>");
        if (this.runSuper) {
           logger.debug("…>");
           super.onUpdateAudit(nodeRef);
           logger.debug("…>");
        }
        logger.debug("…done.");
    }
   
}

We then updated the core-services-context.xml in [ALF_HOME]/tomcat/webapps/alfresco/WEB-INF/classes/alfresco to point to our CustomAuditableAspect instead of the OOTB one and spring inject a boolean:


<beans>

<!– Audit –>
    <bean id="auditableAspect" class="com.orbitz.alfresco.repo.audit.OrbitzAuditableAspect" init-method="init">
        <property name="nodeService">
            <ref bean="dbNodeService" />    <!– bypass loads of interceptor layers –>
        </property>
        <property name="policyComponent">
            <ref bean="policyComponent" />
        </property>
        <property name="authenticationService">
            <ref bean="authenticationService" />
        </property>
        <property name="tenantService">
            <ref bean="tenantService"/>
        </property>      
        <property name="runSuper" value="false">   
    </bean>

</beans>

In our case, we're doing a one time migration and only need to set this property once on the document.  After the migration, we'll flip the boolean back to true as we want the audit trail to continue and restart Alfresco.  Otherwise, the modified date and modifier properties will never update unless manually changed.

There's probably a better way to do this, but hopefully this gets some people going.

samuel_penn
Champ in-the-making
Champ in-the-making
The original post implies that it's possible to set the creation date (but not the modified date), but I can't seem to get this to work. I have a script which is creating files (as form data in WCM) from scratch (based on some legacy documents from another WCM system), and I need to set the creation date on these files so that they are the same as in the legacy system.

After setting cm:created to the required value (as a Javascript Date object), the file is saved but displays the current date.

Do we need to override the Audit aspect as above, or should setting the created date just work?

Thanks,
Sam.

samuel_penn
Champ in-the-making
Champ in-the-making
Okay, I've implemented the above[1] and it seems to allow created/modified dates to be sent within the DM space. However, documents in AVM still can't have their dates modified. I've had a look in the avm-services-context.xml file, to see if it has anything corresponding to the audit aspect configuration in core-services-context.xml and can't see anything obvious. Does AVM use a completely different method for setting the created date? Is it possible to override in a way similar to the method above?

Thanks,
Sam.