cancel
Showing results for 
Search instead for 
Did you mean: 

Triggers differences

jjhinojosa
Champ in-the-making
Champ in-the-making
Hi, I´m trying to do a new trigger, and I use other class that I had implement before, and only change one line. The first class is the next:

import org.alfresco.repo.rule.ruletrigger.OnPropertyUpdateRuleTrigger;
import java.util.*;
import org.alfresco.service.cmr.repository.*;
import org.alfresco.service.namespace.QName;
import java.io.Serializable;
import org.alfresco.util.EqualsHelper;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class UpdateVersionTrigger extends OnPropertyUpdateRuleTrigger{
   
   private static Log logger = LogFactory.getLog(UpdateVersionTrigger.class);
    private boolean triggerParentRules;

    public UpdateVersionTrigger()
    {
        triggerParentRules = true;
    }
       
   private boolean havePropertiesBeenModified(NodeRef nodeRef, Map before, Map after)
    {
        boolean result=false;

        QName name = QName.createQName("http://www.alfresco.org/model/content/1.0", "versionLabel");
        Serializable beforeValue = (Serializable)before.get(name);
        Serializable afterValue = (Serializable)after.get(name);
        if(!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
        {
            result=true;
        }
           
        return result;
    }
    public void onUpdateProperties(NodeRef nodeRef, Map before, Map after)
    {
        if(logger.isDebugEnabled())
        {
            logger.debug((new StringBuilder()).append("OnPropertyUpdate rule triggered fired; nodeRef=").append(nodeRef.toString()).append("; triggerParentRules=").append(triggerParentRules).toString());
        }
        Object createdNodeRef = AlfrescoTransactionSupport.getResource(nodeRef.toString());
        if(createdNodeRef == null && havePropertiesBeenModified(nodeRef, before, after))
        {
            if(triggerParentRules)
            {
                List parentsAssocRefs = nodeService.getParentAssocs(nodeRef);
                ChildAssociationRef parentAssocRef;
                for(Iterator i$ = parentsAssocRefs.iterator(); i$.hasNext(); triggerRules(parentAssocRef.getParentRef(), nodeRef))
                {
                    parentAssocRef = (ChildAssociationRef)i$.next();
                }

            } else
            {
                triggerRules(nodeRef, nodeRef);
            }
        }
    }


}




and the new class is this:

import org.alfresco.repo.rule.ruletrigger.OnPropertyUpdateRuleTrigger;
import java.util.*;

import org.alfresco.service.cmr.repository.*;
import org.alfresco.service.namespace.QName;
import java.io.Serializable;
import org.alfresco.util.EqualsHelper;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CrearPropiedades extends OnPropertyUpdateRuleTrigger{
   
   private static Log logger = LogFactory.getLog(UpdateVersionTrigger.class);
    private boolean triggerParentRules;

    public CrearPropiedades()
    {
        triggerParentRules = true;
    }
       
   private boolean havePropertiesBeenModified(NodeRef nodeRef, Map before, Map after)
    {
        boolean result=false;

        //QName name = QName.createQName("{Asuntos.model}asuntos", "codigo_as");
        QName name = QName.createQName("{Asuntos.model}asuntos", "asunto");
        Serializable beforeValue = (Serializable)before.get(name);
        Serializable afterValue = (Serializable)after.get(name);
        if(!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
        {
            result=true;
        }
           
        return result;
    }
    public void onUpdateProperties(NodeRef nodeRef, Map before, Map after)
    {
        if(logger.isDebugEnabled())
        {
            logger.debug((new StringBuilder()).append("OnPropertyUpdate rule triggered fired; nodeRef=").append(nodeRef.toString()).append("; triggerParentRules=").append(triggerParentRules).toString());
        }
        Object createdNodeRef = AlfrescoTransactionSupport.getResource(nodeRef.toString());
        if(createdNodeRef == null && havePropertiesBeenModified(nodeRef, before, after))
        {
            if(triggerParentRules)
            {
                List parentsAssocRefs = nodeService.getParentAssocs(nodeRef);
                ChildAssociationRef parentAssocRef;
                for(Iterator i$ = parentsAssocRefs.iterator(); i$.hasNext(); triggerRules(parentAssocRef.getParentRef(), nodeRef))
                {
                    parentAssocRef = (ChildAssociationRef)i$.next();
                }

            } else
            {
                triggerRules(nodeRef, nodeRef);
            }
        }
    }
   

}

Then, why the first class work and the second class don´t work?
Can anyone help me?
1 REPLY 1

jjhinojosa
Champ in-the-making
Champ in-the-making
I find my error, in the QName


private boolean havePropertiesBeenModified(NodeRef nodeRef, Map before, Map after)
    {
        boolean result=false;

        QName name = QName.createQName("Asuntos.model", "asunto");
        Serializable beforeValue = (Serializable)before.get(name);
        Serializable afterValue = (Serializable)after.get(name);
        if(!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
        {
            result=true;
        }
           
        return result;
    }