<?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 Can i intercept the &amp;quot;Versioning On Update Properties&amp;quot; and set a description for that version on java in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/can-i-intercept-the-quot-versioning-on-update-properties-quot/m-p/123586#M33807</link>
    <description>&lt;P&gt;I enabled for one document the property "cm:enableAutoVersionOnUpdateProps=true" and everything works as it should, but is there an "elegant" way to intercept the default versioning call and set a description on the version with a text like "Property X has been changed" ?&lt;/P&gt;&lt;P&gt;I had considered a behavior, but I'm having trouble retrieving the property in edit on the "OnCreateVersion" event.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2022 11:23:12 GMT</pubDate>
    <dc:creator>AlfrescoZZZ</dc:creator>
    <dc:date>2022-11-22T11:23:12Z</dc:date>
    <item>
      <title>Can i intercept the "Versioning On Update Properties" and set a description for that version on java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/can-i-intercept-the-quot-versioning-on-update-properties-quot/m-p/123586#M33807</link>
      <description>&lt;P&gt;I enabled for one document the property "cm:enableAutoVersionOnUpdateProps=true" and everything works as it should, but is there an "elegant" way to intercept the default versioning call and set a description on the version with a text like "Property X has been changed" ?&lt;/P&gt;&lt;P&gt;I had considered a behavior, but I'm having trouble retrieving the property in edit on the "OnCreateVersion" event.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 11:23:12 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/can-i-intercept-the-quot-versioning-on-update-properties-quot/m-p/123586#M33807</guid>
      <dc:creator>AlfrescoZZZ</dc:creator>
      <dc:date>2022-11-22T11:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can i intercept the "Versioning On Update Properties" and set a description for that v</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/can-i-intercept-the-quot-versioning-on-update-properties-quot/m-p/123587#M33808</link>
      <description>&lt;P&gt;My own solution, but is not pretty...&lt;/P&gt;&lt;PRE&gt;	public void onCreateVersionVersionableAspectBehavior(QName classRef, NodeRef versionableNode, Map&amp;lt;String, Serializable&amp;gt; versionProperties, PolicyScope nodeDetails) {
		if(this.enable) {
			//logger.debug("START BEHAVIOUR METHOD '" + this.getClass().getSimpleName()+"' '"+new Object(){}.getClass().getEnclosingMethod().getName()+"'");
			String currentusername = AuthenticationServiceUtilities.getCurrentLoginUsername(serviceRegistry);
			try {
    			// Disable auditable aspect
    			behaviourFilter.disableBehaviour();
			  	// Disable rules
			  	ruleService.disableRules();
				AuthenticationUtil.pushAuthentication();
				AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork&amp;lt;Void&amp;gt;() {
					@Override
					public Void doWork() throws Exception {
						return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork&amp;lt;Void&amp;gt;()
						{
							public Void doWork() throws Exception
							{
								try {
					    			// Disable auditable aspect
					    			behaviourFilter.disableBehaviour();
								  	// Disable rules
								  	ruleService.disableRules();
								  	
							  		// INIZIO CONTROLLI PRECHECK
    						        
    						        // tx commit, node might have been already removed...
    						        if (versionableNode == null || !nodeService.exists(versionableNode)) {
    						            logger.debug("Node '"+versionableNode+"' doesn't exist yet");
    						            //throw new AlfrescoRuntimeException("Node '"+versionableNode+"' doesn't exist yet");
    						            return null;
    						        }
    						        logger.debug("Noderef to check : "+versionableNode+", " + nodeService.getProperty(versionableNode, ContentModel.PROP_NAME));
    						        
    						        if(nodeService.hasAspect(versionableNode, ContentModel.ASPECT_HIDDEN)) {
    						            logger.debug("Node '"+versionableNode+"' is hidden do nothing");
    						            return null;
    						        }

    						        if(nodeService.hasAspect(versionableNode, RenditionModel.ASPECT_HIDDEN_RENDITION) || 
    						        		nodeService.hasAspect(versionableNode, RenditionModel.ASPECT_RENDITION2)){
    						            logger.debug("Node '"+versionableNode+"' is a rendition do nothing");
    						            return null;
    						        }
    						        
    						        if(AlfrescoLib.isThumbnail(versionableNode, nodeService, dictionaryService)) {
    						            logger.debug("Node '"+versionableNode+"' is thumbnail do nothing");
    						            return null;
    						        }
    						        
    						        if(AlfrescoLib.isLink(versionableNode, nodeService, dictionaryService)) {
    						            logger.debug("Node '"+versionableNode+"' is link do nothing");
    						            return null;
    						        }
    						        
    						        if(AlfrescoLib.isSite(versionableNode, nodeService, dictionaryService)) {
    						            logger.debug("Node '"+versionableNode+"' is site do nothing");
    						            return null;
    						        }
									//VersionServiceUtilities.checkForCorruptedVersions(nodeRef, serviceRegistry);
								  	// CONTROLLA CLASSE {@link Version2ServiceImpl}	PER DUBBI
								  	String versionComment = (String) versionProperties.get(Version.PROP_DESCRIPTION);
								  	if(StringUtils.isBlank((versionComment)) {
								  		//Map&amp;lt;QName,Serializable&amp;gt; before = nodeService.getProperties(versionableNode);
								  		//Map&amp;lt;QName,Serializable&amp;gt; after = nodeDetails.getProperties();
								  		NodeRef old = VersionServiceUtilities.getUltimaVersione(versionableNode, serviceRegistry);
								  		Map&amp;lt;QName,Serializable&amp;gt; before = nodeService.getProperties(old);
								  		Map&amp;lt;QName,Serializable&amp;gt; after = nodeService.getProperties(versionableNode);
								  		
										// Mappa si supporto perche' la libreria di google fa una mappa "unmodifiable"
										Set&amp;lt;QName&amp;gt; qnameInModifica = new HashSet&amp;lt;QName&amp;gt;();
										
										MapDifference&amp;lt;QName, Serializable&amp;gt; diff = Maps.difference(before, after);
										// Returns an unmodifiable map describing keys that appear in both maps, but with different values.
										Map&amp;lt;QName, ValueDifference&amp;lt;Serializable&amp;gt;&amp;gt; mapDiff = diff.entriesDiffering();
										// Non basta per qualche strano motivo se i campi sono nulli alfresco non mi passa le proprieta'
										// devo fare un merge per quelli presenti dopo (after) , ma non presenti prima (before)
										Map&amp;lt;QName, Serializable&amp;gt; mapOnlyOnRight = diff.entriesOnlyOnRight();

										qnameInModifica.addAll(mapDiff.keySet());
										
										for(Map.Entry&amp;lt;QName,Serializable&amp;gt; entryDif : mapOnlyOnRight.entrySet()) {
											if(StringUtils.isNotBlank((String.valueOf(entryDif.getValue()))
													// Caso particolare per i valori booleani...
													&amp;amp;&amp;amp; !String.valueOf(entryDif.getValue()).equalsIgnoreCase("false")) {
												qnameInModifica.add(entryDif.getKey());
											}
										}
										
										//logger.debug("Proprieta' in modifica " + System.lineSeparator() + Arrays.toString(qnameInModifica.toArray()));
										Set&amp;lt;QName&amp;gt; proprietaNonDiAlfrescoInModifica = new HashSet&amp;lt;QName&amp;gt;();
										// Filtiramo per tutte le proprieta' non di default di alfresco
										// e che hanno un namespace collegato in qualche modo alla conservazione
										// gli aspetti della classificazioni sono compresi
										for(QName q : qnameInModifica) {
											if(q != null) { // PER SICUREZZA MA NON DOVREBBE MAI SUCCEDERE
												QName qNameWithPrefix = q.getPrefixedQName(nameSpaceService);
												String prefix = QName.splitPrefixedQName(qNameWithPrefix.toPrefixString())[0];
												if(prefix != null &amp;amp;&amp;amp;
													//!NamespaceServiceUtilities.isAlfrescoDefaultPrefix(prefix) &amp;amp;&amp;amp;
													!qNameWithPrefix.equals(Version2Model.PROP_QNAME_VERSION_DESCRIPTION) &amp;amp;&amp;amp;
													!qNameWithPrefix.equals(Version2Model.PROP_QNAME_VERSION_NUMBER) &amp;amp;&amp;amp;
													!qNameWithPrefix.equals(Version2Model.PROP_QNAME_VERSION_LABEL) &amp;amp;&amp;amp;
													!qNameWithPrefix.equals(ContentModel.PROP_MODIFIED)
												) {
													proprietaNonDiAlfrescoInModifica.add(q);
												}												
											}
										}
										
										//if(proprietaNonDiAlfrescoInModifica.isEmpty()) {
										//	//logger.debug("nessuna proprieta' non di default di alfresco trovata");
										//	return null;
										//}
										
										logger.debug("AGGIORNO VERSIONE COMMENTO SU PROPRIETA'");

										//logger.debug("Proprieta' in modifica non di alfresco " + System.lineSeparator() + Arrays.toString(proprietaNonDiAlfrescoInModifica.toArray()));
										List&amp;lt;String&amp;gt; arrList = new ArrayList&amp;lt;String&amp;gt;();
										for(QName q : proprietaNonDiAlfrescoInModifica) {
											String s = DictionaryServiceUtilities.getTitleFromQName(versionableNode, q, serviceRegistry);
											arrList.add(s);
										}
								  		String commentToInsert = "Modificato: " + String.join(",", arrList);							  	
								  		logger.debug("AGGIORNO VERSIONE COMMENTO SU CREA VERSIONE' SU "+ classRef);						  		
								  		versionProperties.put(Version.PROP_DESCRIPTION,commentToInsert);
								  	}
									return null;
								} catch (Throwable ex) {
									logger.error(ex.getMessage() + ", " + ex.getCause());
									throw new AlfrescoRuntimeException(ex.getMessage() + ", " +ex.getCause(), ex);
    							} finally {
    				    		    ruleService.enableRules();
    				    		    behaviourFilter.enableBehaviour();
    							}
							}
						}, TenantUtil.getCurrentDomain());
					}
				} ,AuthenticationUtil.getSystemUserName());
			} finally {
				AuthenticationUtil.popAuthentication();
    		    ruleService.enableRules();
    		    behaviourFilter.enableBehaviour();
			}    		
	
			//logger.debug("END BEHAVIOUR METHOD '" + this.getClass().getSimpleName()+"' '"+new Object(){}.getClass().getEnclosingMethod().getName()+"'");
		}else {
			//logger.warn("Can't invoke the '"+new Object(){}.getClass().getEnclosingMethod().getName()+"' because the property 'enable' is false");
		}
	}&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Nov 2022 16:14:32 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/can-i-intercept-the-quot-versioning-on-update-properties-quot/m-p/123587#M33808</guid>
      <dc:creator>AlfrescoZZZ</dc:creator>
      <dc:date>2022-11-24T16:14:32Z</dc:date>
    </item>
  </channel>
</rss>

