cancel
Showing results for 
Search instead for 
Did you mean: 

policies to identify restore operations

hgindl
Champ in-the-making
Champ in-the-making
Hi all,

i have the following requirements
1) remove an aspect if the content of a document gets changed (because it is only valid for the actual document version)
2) reapply it if the document gets restored from the version history.

Part 1) works fine so far. I am using two policies ContentServicePolicies.OnContentUpdatePolicy and VersionServicePolicies.AfterCreateVersionPolicy. onContentUpdate gets called when a content property is changed - the nodeRef is then bound to the transaction. Sometimes later AfterCreateVersion gets called if the new version was created so i only need to check if the nodeRef i get as parameter was bound to the transaction which indicates that the content was modified and a new version was created - only then i can remove the aspect.

Part 2) is the problem. At first i thought that nothing else will be needed, because alfresco will automatically take care of restoring the aspect. But during a restore to a previous version, the content property of a node gets written too, so OnContentUpdatePolicy is triggered and the nodeRef is bound to the transaction. During the restore operation it also gets a new version, which triggers the aspect remove on the restored node. So thats not the outcome i want.

Regarding my requirements, has someone an idea how i could identify restore operations and distinguish them from normal versioning only by using policies?

Kind regards,
h.



2 REPLIES 2

rjohnson
Star Contributor
Star Contributor
Won't the version number be 1.0? In which case can't you just interrogate the version number and skip the remove aspect if its 1.0?

Bob Johnson

hgindl
Champ in-the-making
Champ in-the-making
Hi Bob,

thanks for your reply, i checked that but in the policy lifecycle methods the version label is alread the version it is supposed to be. But it was a good hint. If you upload a new version of content the content url is unique among the set of content urls in the updated documents version history. In contrary if the document gets reverted, the content url is copied from the version this document gets reverted from, so it is then not unique in the version history.



public void afterCreateVersion(NodeRef versionableNode, Version version) {

      VersionHistory versionHistory = versionService
            .getVersionHistory(versionableNode);

      Version ancestorVersion = version;
      ContentData curContentData = (ContentData) version
            .getVersionProperty(ContentModel.PROP_CONTENT.getLocalName());

      while ((ancestorVersion = versionHistory
            .getPredecessor(ancestorVersion)) != null) {
         ContentData ancestorContentData = (ContentData) ancestorVersion
               .getVersionProperty(ContentModel.PROP_CONTENT
                     .getLocalName());
         if (curContentData != null
               && ancestorContentData != null
               && curContentData.getContentUrl().equals(
                     ancestorContentData.getContentUrl())) {
            return; // this is a revert so no further action is needed

         }
      }
      
      //TODO - do the work here
   }


Kind regards
Hannes