Hi Guys
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 likeOnPropertyUpdateRuleTriggerOnContentUpdateRuleTriggeretc
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 guysBest Regards.