Fork me on GitHub

Tutorial - Clean Hippo String Docbase Property Values

The code snippets are excerpts (or slightly simplififed ones) from Example_Clean_Hippo_String_Docbase_Property_Values_Having_Paths.

Introduction

Since Hippo CMS 10, a document may contains a Docbase string property, which may contain a UUID string value or multiple UUID string values of the referenced document handle node(s).

As explained in Tutorial: Exporting Document Content, the UUIDs might have been replaced by the node paths of the referenced document handle nodes during exporting process.

In this case, you can create a simple Groovy Updater script like explained in this page to update the docbase node paths by docbase UUIDs in those Docbase string properties.

Select Nodes Having String Docbase Properties in Groovy Updater

Unlike traditional mirror link nodes, a Docbase string property can be named to anything. So, the query should specify the property names like the following to select nodes having Docbase string properties. In the following example, it supposes contenteximdemo:relatedarticle property is a Docbase string property.

/jcr:root/content/documents//element(*)[@contenteximdemo:relatedarticle]
          
          

If you want to select nodes having Docbase properties by multiple property names, then you add more constraints like the following:

/jcr:root/content/documents//element(*)[@contenteximdemo:relatedarticle or @contenteximdemo:author]
          
          

So, in the example above, it will select all the nodes having either contenteximdemo:relatedarticle or contenteximdemo:author property. The two are assumed to be Docbase string properties.

Updating String Docbase Properties

      // 0. Suppose contenteximdemo:relatedarticle is multiple string type property in this example.
      //    If the property is not multiple, you can simply read the single value without having to iterate each value.

      def docbasePropName = "contenteximdemo:relatedarticle"
      def valuesUpdated = false

      // 1. Read multiple string property values into array.
      String [] docbaseValues = JcrUtils.getMultipleStringProperty(node, docbasePropName, ArrayUtils.EMPTY_STRING_ARRAY)

      // 2. Iterate for each docbase string value.
      docbaseValues.eachWithIndex { docbaseValue, j ->
        // 2.1. If the docbase string value starts with '/' and there exists a node at the path,
        //      then replace the value by the UUID.
        if (StringUtils.startsWith(docbaseValue, "/") && node.session.nodeExists(docbaseValue)) {
          def docbase = node.session.getNode(docbaseValue).getIdentifier()
          docbaseValues[j] = docbase
          valuesUpdated = true
        }
      }

      // 3. Reset the docbase property value
      if (valuesUpdated) {
        node.setProperty(docbasePropName, docbaseValues)
      }