cancel
Showing results for 
Search instead for 
Did you mean: 

Really need help. quite Urgent

joksy
Champ in-the-making
Champ in-the-making
Hi Guys  :cry:  :cry:

I really need some help because i va tried a lot of things for achieve my goal but, nothing happen.

The point is: When a user update some property in a file i have the rule which run a js script. This work very good if are all properties of the content. But nothing happen if the user update an association. And this i clear because in the repository there are class like
    OnPropertyUpdateRuleTrigger
    OnContentUpdateRuleTrigger
    etc
but there is no class which trigger rule on association change. The point is that exist the interface which if it will added to the policyComponent with a behavior, after an association change the method is called. So wow when this method will be called I run the script. But sorry guys I fail every time. Below i post all my code/try I hope that someone can help me.

class

public class ExcuteScriptOnAssociationUpdtate
      implements NodeServicePolicies.OnDeleteAssociationPolicy, NodeServicePolicies.OnCreateAssociationPolicy {


   //Dep.
   private PolicyComponent policyComponent;
   private NodeService nodeService;
   private ActionService actionService;
   
   

   private Behaviour onDeleteAssocs,onCreateAssocs;
   
   
   
   public void onDeleteAssociation(AssociationRef ar) {
      
      return;
   }

   public void onCreateAssociation(AssociationRef ar) {

        NodeRef nodeRef = ar.getSourceRef();
   

         NodeRef scriptRef = new NodeRef(….no idea to get the script );
 


        //this.actionService.executeAction(action, nodeRef);
            
   }
   
   
   public void init(){
      onCreateAssocs = new JavaBehaviour(this,"onCreateAssociation",NotificationFrequency.EVERY_EVENT);
      onDeleteAssocs = new JavaBehaviour(this,"onDeleteAssociation",NotificationFrequency.EVERY_EVENT);
      
      policyComponent.bindAssociationBehaviour(
            QName.createQName(NamespaceService.ALFRESCO_URI,"onCreateAssociation")
            , "onCreateAssociation",
            onCreateAssocs);
      
      policyComponent.bindAssociationBehaviour(
            QName.createQName(NamespaceService.ALFRESCO_URI,"onDeleteAssociation")
            , "onDeleteAssociation",
            onDeleteAssocs);
      
      

   }

   public PolicyComponent getPolicyComponent() {
      return policyComponent;
   }

   public void setPolicyComponent(PolicyComponent policyComponent) {
      this.policyComponent = policyComponent;
   }

   public NodeService getNodeService() {
      return nodeService;
   }

   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }

   public ActionService getActionService() {
      return actionService;
   }

   public void setActionService(ActionService actionService) {
      this.actionService = actionService;
   }
   

   
}

spring bean config


<bean id="assocsBehavior" class="classpath.ExcuteScriptOnAssociationUpdtate" init-method="init">
   <property name="nodeService">
      <ref bean="nodeService"/>
   </property>
   <property name="policyComponent">
      <ref bean="policyComponent"/>
   </property>
   <property name="actionService">
      <ref bean="actionService"/>
   </property>
</bean>


an other attempts is to extend on of the existing class but…..  :?:


public class OnContentAssocUpdate extends OnPropertyUpdateRuleTrigger //extends OnContentUpdateRuleTrigger
implements NodeServicePolicies.OnDeleteAssociationPolicy, NodeServicePolicies.OnCreateAssociationPolicy {
   
   

   @Override
   public void onUpdateProperties(NodeRef arg0, Map<QName, Serializable> arg1,
         Map<QName, Serializable> arg2) {
   
      super.onUpdateProperties(arg0, arg1, arg2);
      
   
      
      
       List<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(arg0);
         for (ChildAssociationRef parentAssocRef : parentsAssocRefs)
         {
             triggerRules(parentAssocRef.getParentRef(), arg0);
         }
   
        
         triggerRules(arg0, arg0); 
        
   }
   

   public void onDeleteAssociation(AssociationRef nodeAssocRef) {
      
   }

   public void onCreateAssociation(AssociationRef nodeAssocRef) {
           List<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeAssocRef.getSourceRef());
            for (ChildAssociationRef parentAssocRef : parentsAssocRefs)
            {
                triggerRules(parentAssocRef.getParentRef(), nodeAssocRef.getSourceRef());
            }
       
            triggerRules(nodeAssocRef.getSourceRef(), nodeAssocRef.getSourceRef());
       
   
      
   }

   public void registerRuleTrigger() {
      super.registerRuleTrigger();
      this.policyComponent.bindAssociationBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateAssociation"), this,
            new JavaBehaviour(this, "onCreateAssociation"));

      this.policyComponent.bindAssociationBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteAssociation"), this,
            new JavaBehaviour(this, "onDeleteAssociation"));

   }



}


Thanks guys

Best Regards.
2 REPLIES 2

joksy
Champ in-the-making
Champ in-the-making
Hi guys, since until now noon are reply to my post, I ve decide tu update my small progress.

I see the bean in rule-service-context.xml which clear define some behavior during the update rule. And in fact confirm what i say in the previous post, the change of association is not taken in account.

   <bean id="update" class="org.alfresco.repo.rule.RuleTypeImpl" parent="rule-type-base">
      <constructor-arg>
         <list>
            <ref bean="on-property-update-trigger"/>
            <ref bean="on-content-update-trigger"/>
         </list>
      </constructor-arg>
   </bean>

Ok i decide to look more in detail in the repository and i found the class org.alfresco.repo.rule.ruletrigger.SingleAssocRefPolicyRuleTrigger.
Mhh quite interesting. So this is my class after this discovery.


public class AssocUpdateTrigger extends SingleAssocRefPolicyRuleTrigger
   implements NodeServicePolicies.OnDeleteAssociationPolicy, NodeServicePolicies.OnCreateAssociationPolicy {

   public void onDeleteAssociation(AssociationRef ar) {
      super.policyBehaviour(ar);
      
   }

   public void onCreateAssociation(AssociationRef ar) {
      super.policyBehaviour(ar);
      
   }
   
   @Override
   public void registerRuleTrigger() {
      super.registerRuleTrigger();
      
      policyComponent.bindAssociationBehaviour(
      QName.createQName(NamespaceService.ALFRESCO_URI,"onCreateAssociation")
      , "onCreateAssociation",
      new JavaBehaviour(this,"onCreateAssociation"));

      policyComponent.bindAssociationBehaviour(
      QName.createQName(NamespaceService.ALFRESCO_URI,"onDeleteAssociation")
      , "onDeleteAssociation",
      new JavaBehaviour(this,"onDeleteAssociation"));
   }

}


and the new bean

   <bean id="update" class="org.alfresco.repo.rule.RuleTypeImpl" parent="rule-type-base">
      <constructor-arg>
         <list>
            <ref bean="on-property-update-trigger"/>
            <ref bean="on-content-update-trigger"/>
            <ref bean="on-create-association-trigger"/>
            <ref bean="assocs-trigger"/>
</list>
      </constructor-arg>
   </bean>


Well deploy restart … and try to test.
From here nothing have sense for me(until now).
With a user with all permission i have tried to modify an association in my content. and an error appear

A system error happened during the operation: Failed to execute script 'workspace://SpacesStore/5334993a-dbe0-40b3-b493-0ae46a06a6d4': Access Denied. You do not have the appropriate permissions to perform this operation.

What ??? But ok the system try to execute the script and it is exactly what i want.

BUT BUT :?:  :?:  :?:  :roll:  When i tried to do the same things with the admin user nothing happen and the script is not called.
(NB: I use also the debbugger for js code and i see if the script is called or not).

So Now i really don t know how and why I ll think to post a ticket in jira because sounds really strange.

If someone cal help/explain WHY i really appreciate.

Best Regards


PS i post also the stacktrace

11:00:29,530 User:mp ERROR [ui.common.Utils] A system error happened during the operation: Failed to execute script 'workspace://SpacesStore/5334993a-dbe0-40b3-b493-0ae46a06a6d4': Access Denied.  You do not have the appropriate permissions to perform this operation.
org.alfresco.scripts.ScriptException: Failed to execute script 'workspace://SpacesStore/5334993a-dbe0-40b3-b493-0ae46a06a6d4': Access Denied.  You do not have the appropriate permissions to perform this operation.
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:228)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:187)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:275)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy185.executeScript(Unknown Source)
   at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:157)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:127)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:688)
   at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:72)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:127)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:688)
   at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:625)
   at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:487)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:275)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy19.executeAction(Unknown Source)
   at org.alfresco.repo.rule.RuleServiceImpl.executeRule(RuleServiceImpl.java:928)
   at org.alfresco.repo.rule.RuleServiceImpl.executePendingRule(RuleServiceImpl.java:896)
   at org.alfresco.repo.rule.RuleServiceImpl.executePendingRulesImpl(RuleServiceImpl.java:867)
   at org.alfresco.repo.rule.RuleServiceImpl.executePendingRules(RuleServiceImpl.java:840)
   at org.alfresco.repo.rule.RuleTransactionListener.beforeCommit(RuleTransactionListener.java:63)
   at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.doBeforeCommit(AlfrescoTransactionSupport.java:710)
   at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.doBeforeCommit(AlfrescoTransactionSupport.java:690)
   at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.beforeCommit(AlfrescoTransactionSupport.java:650)
   at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:48)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:835)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:645)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314)
   at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:467)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:336)
   at org.alfresco.web.bean.dialog.BaseDialogBean.finish(BaseDialogBean.java:128)
   at org.alfresco.web.bean.dialog.DialogManager.finish(DialogManager.java:534)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
   at javax.faces.component.UICommand.broadcast(UICommand.java:109)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
   at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
   at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:97)
   at sun.reflect.GeneratedMethodAccessor427.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.alfresco.repo.management.ManagedSubsystemProxyFactory$1.invoke(ManagedSubsystemProxyFactory.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy173.doFilter(Unknown Source)
   at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:88)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.repo.web.filter.beans.NullFilter.doFilter(NullFilter.java:51)
   at sun.reflect.GeneratedMethodAccessor427.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.alfresco.repo.management.ManagedSubsystemProxyFactory$1.invoke(ManagedSubsystemProxyFactory.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy173.doFilter(Unknown Source)
   at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:88)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:613)
Caused by: org.alfresco.repo.security.permissions.AccessDeniedException: Access Denied.  You do not have the appropriate permissions to perform this operation.
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:275)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy4.setProperties(Unknown Source)
   at org.alfresco.repo.jscript.ScriptNode.save(ScriptNode.java:1124)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
   at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3237)
   at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2394)
   at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:173)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:449)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:224)
   … 109 more
Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
   at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:394)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   … 132 more

joksy
Champ in-the-making
Champ in-the-making
Uff, guys the posts above, are (for me the right way) in fact now i m able to do what i wanted. So the only difference is,
in  the class not extends SingleAssoc… but directly OnPropertyUpdateRuleTrigger. And modify the bean.

So two words: Could be nice have a behavior like this just in bound in alfresco, because is true that associations != property but for the user are all data which probably are needed so a change to an association became a property as well.
Ok anyway thanks and

Best Regards.