<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to detect that there was a metadata modification to automatically increment the version number? in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324398#M11399</link>
    <description>&lt;P&gt;I want to know how to detect when a metadata has been modified. I want to compare the last number of version of the document and the working copy before I do Check In.
When I modified some metadada (not a file) I want to increment minor version number automatically. And when I modified a file I want to increment major version number automatically.&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Kind regards.&lt;/P&gt;</description>
    <pubDate>Sun, 05 Oct 2014 23:27:34 GMT</pubDate>
    <dc:creator>Romina_Racca</dc:creator>
    <dc:date>2014-10-05T23:27:34Z</dc:date>
    <item>
      <title>How to detect that there was a metadata modification to automatically increment the version number?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324398#M11399</link>
      <description>&lt;P&gt;I want to know how to detect when a metadata has been modified. I want to compare the last number of version of the document and the working copy before I do Check In.
When I modified some metadada (not a file) I want to increment minor version number automatically. And when I modified a file I want to increment major version number automatically.&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Kind regards.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Oct 2014 23:27:34 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324398#M11399</guid>
      <dc:creator>Romina_Racca</dc:creator>
      <dc:date>2014-10-05T23:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect that there was a metadata modification to automatically increment the version number?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324399#M11400</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;You have to use a listener (http://doc.nuxeo.com/x/C4AO). You can create it under Studio (if you use it) or under Eclipse Nuxeo IDE plugin (wizard listener).&lt;/P&gt;
&lt;P&gt;Subscribe to the event ABOUT_TO_CREATE (about to create listener) to check metadata updates before any changes have been commited.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 07 Oct 2014 10:25:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324399#M11400</guid>
      <dc:creator>Vladimir_Pasqui</dc:creator>
      <dc:date>2014-10-07T10:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect that there was a metadata modification to automatically increment the version number?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324400#M11401</link>
      <description>&lt;P&gt;My solution as contribution to the community.&lt;/P&gt;
&lt;P&gt;Event: DOCUMENT_MODIFIED&lt;/P&gt;
&lt;P&gt;public class ModificationListener implements EventListener {&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;private static final Log log = LogFactory.getLog(ModificationListener.class);

public void handleEvent(Event event) throws ClientException {

	EventContext ctx = event.getContext();
	if (!(ctx instanceof DocumentEventContext)) {
		// event is not tied to a document, we should not be here
		return;
	}

	// Fetch the document from the event context
	DocumentModel doc = ((DocumentEventContext) ctx).getSourceDocument();

	if (doc == null)
		return;

	if (!doc.isVersionable())
		return;

	try {
		BlobProperty currentBlob = (BlobProperty) doc.getProperty("file:content");
		BlobProperty lastBlob = getLastBlob(ctx, doc.getRef());

		 //If currentDoc hasn't a file...
		if(currentBlob.getValue() == null){
			//... and never had a file ...
			if(lastBlob.getValue() == null){
				doc.checkIn(VersioningOption.MINOR, "Metadata modification.");	
			}else{
			//... or file delete	
				doc.checkIn(VersioningOption.MAJOR, "File delete");
			}
			return;
		}
		
		//If currentDoc has a file but lastDoc hasn't a file 	
		if(lastBlob.getValue() == null){
			doc.checkIn(VersioningOption.MAJOR, "File creation");
			return;
		}	

		//If currentDoc has a file and lastDoc has a file ==&amp;gt; compare the digesto
		if(currentBlob.getValue("digest").equals(lastBlob.getValue("digest"))){
			doc.checkIn(VersioningOption.MINOR, "Metadata modification.");
		}else{
			doc.checkIn(VersioningOption.MAJOR, "File modification.");
		}

	} catch (PropertyException e) {
		//If currentDoc hasn't a file:contenct Ej: Nota
		doc.checkIn(VersioningOption.MINOR, "Metadata modification.");
		log.warn("[ERROR_1 Automatizacion de versionado]: "+e.getMessage());
	}

}


/**
 * 
 * @param ctx Contexto
 * @param ref Referencia al documento
 * @return la propiedad Blob del ultimo documento
 */
public BlobProperty getLastBlob(EventContext ctx, DocumentRef ref){
	DocumentModel lastDocVersion;
	try {
		lastDocVersion = ctx.getCoreSession().getVersions(ref).get(
				ctx.getCoreSession().getVersions(ref).size()-1);

		BlobProperty lastBlob = (BlobProperty) lastDocVersion.getProperty("file:content");	

		return lastBlob;

	} catch (PropertyException e) {
		log.warn("[ERROR_2 Automatizacion de versionado]: "+e.getMessage());
	} catch (ClientException e1) {
		log.warn("[ERROR_3 Automatizacion de versionado]: "+e1.getMessage());
	}
	return null;

}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 11 Feb 2015 13:52:22 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324400#M11401</guid>
      <dc:creator>Romina_Racca</dc:creator>
      <dc:date>2015-02-11T13:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect that there was a metadata modification to automatically increment the version number?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324401#M11402</link>
      <description>&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Feb 2015 14:22:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-detect-that-there-was-a-metadata-modification-to/m-p/324401#M11402</guid>
      <dc:creator>Vladimir_Pasqui</dc:creator>
      <dc:date>2015-02-11T14:22:08Z</dc:date>
    </item>
  </channel>
</rss>

