11-17-2010 09:56 AM
public void init() {
policyComponent.bindClassBehaviour(
NodeServicePolicies.OnCreateNodePolicy.QNAME,
UncModel.TYPE_STATE,
new JavaBehaviour(
this,
"onCreateNode",
NotificationFrequency.TRANSACTION_COMMIT
)
);
}
public void onCreateNode(ChildAssociationRef car) {
sender.queueItem(car.getChildRef(), false);
}
11-17-2010 03:48 PM
11-18-2010 09:19 AM
You should look at the "SDK Custom Aspect" in the SDK, which uses a TransactionListenerAdapter to execute stuff in its afterCommit() method so that it is effectively executed after the transaction has been committed.
package com.culturenetcymru.unc;
import com.culturenetcymru.unc.senders.Aggregator;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionListenerAdapter;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
/**
*
* @author Xian Stannard
*/
public class SendStatePolicy extends TransactionListenerAdapter implements NodeServicePolicies.OnCreateNodePolicy {
public static final String NODE_KEY = SendStatePolicy.class.getName() + ".node";
private PolicyComponent policyComponent;
private Aggregator sender;
public void setPolicyComponent(PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}
public void setSender(Aggregator sender) {
this.sender = sender;
}
public void init() {
policyComponent.bindClassBehaviour(
NodeServicePolicies.OnCreateNodePolicy.QNAME,
UncModel.TYPE_STATE,
new JavaBehaviour(
this,
"onCreateNode",
NotificationFrequency.TRANSACTION_COMMIT
)
);
}
public void onCreateNode(ChildAssociationRef car) {
AlfrescoTransactionSupport.bindListener(this);
AlfrescoTransactionSupport.bindResource(NODE_KEY, car.getChildRef());
}
@Override
public void afterCommit() {
NodeRef node = AlfrescoTransactionSupport.getResource(SendStatePolicy.NODE_KEY);
if(node != null)
sender.queueItem(node, false);
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.