cancel
Showing results for 
Search instead for 
Did you mean: 

Custom behaviour onCreateNode policy

pedrosaraiva
Champ in-the-making
Champ in-the-making
Hello,

I'm trying to implement a listener to integrate alfresco with another system. The listener will be triggered when a file (or folder) is created, deleted, updated and versioned. I’ve created a behaviour and binded to the policies onContentUpdate, onCreateNode, onUpdateNode… etc, using java.

When I create a folder the onCreateNode is triggered. Then, I create a new thread and send to the other system, via webservice, an event with the webdav URL of the resource. The other system will try to connect to that URL and sometimes it will fail. The failure happens because the resource was not created yet.
The only way I'm seeing to make this work "right" is to make the thread sleep for while and then send the event. But that's a very bad solution…
I was hoping to find a afterCreateNode policy, but apparently it doesn't exist.

Can you help me, please?

Kind regards,

Pedro Saraiva
5 REPLIES 5

zaizi
Champ in-the-making
Champ in-the-making
How are you creating your new thread?

Take a look at the Aspect SDK example bundled with the Alfresco SDK. It provides an example of how to bind post-commit operations to policies.

pedrosaraiva
Champ in-the-making
Champ in-the-making
Hello,

Thanks a lot, it's working now  Smiley Very Happy… with some hacks and problems  Smiley Indifferent ..

I'm binding the policies like this:

this.policyComponent.bindClassBehaviour( QName.createQName( NamespaceService.ALFRESCO_URI, "onCreateNode" ), "cm:content", this.onCreateNode );

If I change that to :

this.policyComponent.bindClassBehaviour( QName.createQName( NamespaceService.ALFRESCO_URI, "onCreateNode" ), ContentModel.TYPE_CONTENT, this.onCreateNode );

The policy isn't triggered.
On the SDK example you mentioned there's this code to prevent the refire of a policy:


this.policyComponent.bindClassBehaviour( ContentServicePolicies.ON_CONTENT_READ,  ASPECT_CONTENT_HITS, new JavaBehaviour(this, "onContentRead", notificationFrequency.TRANSACTION_COMMIT));

policyFilter.disableBehaviour(nodeRef, ASPECT_CONTENT_HITS);

Using ContentModel.TYPE_CONTENT on disableBehaviour method gives me an exception. So how can I create a QName for the "cm:content" to pass on disableBehaviour?

Another problem :x. If I bind the “onCreateVersion”, the versioning system stops working. Every time I try to access via  web interface to a version of the document there's this error:

The node’s content is missing:
node: versionStore://version2Store/832c5cae-d7e8-4945-96db-5cbb3169b0b9
reader: null
Please contact your system administrator.

On the javadoc of the method there’s this warning:

WARNING: implementing behaviour for this policy effects the versioning behaviour of the type the behaviour is registered against.

How can I make this work right?

Kind regards,

Pedro Saraiva

zaizi
Champ in-the-making
Champ in-the-making
Your code should read something like this;

this.policyComponent.bindClassBehaviour( QName.createQName( NamespaceService.ALFRESCO_URI, "onCreateNode" ), this, this.onCreateNode );

Assuming you are not updating the node or creating a new node, you should not have to worry about refiring the policy.

Why are you binding to create version?

wesse
Champ in-the-making
Champ in-the-making
ContentServicePolicies.ON_CONTENT_READ will probably generate more events since it is also triggerd by the indexing service.

mitpatoliya
Star Collaborator
Star Collaborator
Hi All,

I have deployed the Custom Aspect example(Version 3.2r) on my alfresco instance not changed any thing in given code just a single change done in the file
content-hits-context.xml.
Change done is as follow original thread pool executor entry is replaced with entry like this
<property name="threadExecuter">
          <ref bean="threadPoolExecutor"/>
  </property>
as it has solved my one problem where i was not able to start the alfresco instance,
but the problem which i am facing now is when i attach content hits aspect to any content and try to down load the content or try to read it it gives me error:


Invalid Value
17:13:31,296 User:admin ERROR [repo.transaction.AlfrescoTransactionSupport] After completion (committed) listener exception:
   listener: org.alfresco.sample.ContentHitsAspect$ContentHitsTransactionListener@94449c
java.lang.NullPointerException
        at org.alfresco.sample.ContentHitsAspect$ContentHitsTransactionListener.afterCommit(ContentHitsAspect.java:212)
        at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.afterCompletion(AlfrescoTransactionSuppo
rt.java:814)
        at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.ja
va:133)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionMana
ger.java:904)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionMan
ager.java:879)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java
:707)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.ja
va:314)
        at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:467)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:349)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:253)
        at org.alfresco.web.app.servlet.DownloadContentServlet.doGet(DownloadContentServlet.java:119)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.web.scripts.servlet.StaticAssetCacheFilter.doFilter(StaticAssetCacheFilter.java:76)
        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:74)
        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:597)
        at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:122)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy167.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:619)

It must be problem with Out of box SDK example.
Please suggest me the solution.

Regards,
Mit