Unicity Service

Table of Contents

59.1. How does it works ?
59.2. What you need:
59.3. Configuration
59.4. Snippets

The Unicity service sends a new Message on the JMS bus every time you upload a file already on the server.

59.1. How does it works ?

When creating or updating a file, a digest is computed using the whole file and an encoding algorithm. Next step is an nxql query wich gets every Document with the same Digest. If such documents exist, there references will be forwarded on JMS bus.

59.2. What you need:

The message's eventID is duplicatedFile. You need it to catch the event. The documentLocation list is available in the info map of the CoreEvent using duplicatedDocLocation key.

59.3. Configuration

How to configure unicity extension point. TODO: needs to be made clearer.

<enabled>
Default value is false. Use true if you want to enable this service.
</enabled>
<algo>
Default encoding algorithm is sha-256. You can choose every algorithm supported by java.security.MessageDigest.
</algo>
<field>
A field is an xpath expression giving a particular field of your schema.
It's the reference of a file on the server.
The type's field must be nxs:content.
You can use as many field as you want. 
</field>     

59.4. Snippets

Some code to get you started.

<?xml version="1.0"?>
<component name="org.nuxeo.ecm.platform.filemanager.service.FileManagerService.Plugins">
  <extension
      target="org.nuxeo.ecm.platform.filemanager.service.FileManagerService"
      point="unicity">
    <unicitySettings>
      <enabled>true</enabled>
      <algo>sha-256</algo>
      <field>content</field>
    </unicitySettings>
  </extension>
</component>

Example 59.1. Sample unicity extension point contribution to the FileManager service.


public void onMessage(Message message) {
    try {
        Serializable obj = ((ObjectMessage) message).getObject();
        if (!(obj instanceof DocumentMessage)) {
            return;
        }
        DocumentMessage doc = (DocumentMessage) obj;

        String eventId = doc.getEventId();

        if ("duplicatedFile".equals(eventId)){
            Object[] documentLocations = (Object[]) doc.getEventInfo().get("duplicatedDocLocation");
            for (Object documentLocation: documentLocations) {
                log.debug(((DocumentLocation)documentLocation).getDocRef());
            }
        }   
    }
}

Example 59.2. Sample code to retrieve DocumentLocations.