cancel
Showing results for 
Search instead for 
Did you mean: 

when OnContentRead behavior trigger

kevinchen
Champ in-the-making
Champ in-the-making

hi everyone:

      I want to implement Click through rate of a content ,   I use the sample "ContentHitsAspect"  

public class ContentHitsAspect implements ContentServicePolicies.OnContentReadPolicy,
                                                                        ContentServicePolicies.OnContentUpdatePolicy,
                                                                        NodeServicePolicies.OnAddAspectPolicy

but  when I visit  this address "http://localhost:8080/share/page/site/swsdp/inline-edit?nodeRef=workspace://SpacesStore/286ec938-240..."  ,   the OnContentRead behavior  triggered  

not this address "http://localhost:8080/share/page/site/swsdp/document-details?nodeRef=workspace://SpacesStore/286ec93..."

in my mind  "inline-edit" should be the oncontentupdate  behavior  and the OnContentRead behavior should be the "document-details"

what behavior can trigger when i visit  document-details address,  anybody can help me about this  problem  

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

Minor correction: The OnContentRead policy is triggered when a reader is obtained from the ContentService. The policy does not require that the content is actually read.

View answer in original post

10 REPLIES 10

kaynezhang
World-Class Innovator
World-Class Innovator

Every time when the content is read by the content reader form content store.

afaust
Legendary Innovator
Legendary Innovator

Minor correction: The OnContentRead policy is triggered when a reader is obtained from the ContentService. The policy does not require that the content is actually read.

kevinchen
Champ in-the-making
Champ in-the-making

hi,do you know how to display content  download count

Key idea is we need to catch the event which occurs during download action happen.In this example we are invoking our piece of code whenever download API is called from core services.

i don't know how to do this 

afaust
Legendary Innovator
Legendary Innovator

Download will also cause the OnContentRead policy but the problem is that one download can cause multiple invocations of the OnContentRead policy because clients may download chunks of a file in multiple requests (progressive loading).

kevinchen
Champ in-the-making
Champ in-the-making

i found PDF can trigger it every time,but  PNG  WORD...can't trigger every time when visit URL document-details?nodeRef=    any suggestion

afaust
Legendary Innovator
Legendary Innovator

Contents may also be cached by the client and thus not cause an additional OnContentRead. Also if previews are shown in document-details then the OnContentRead will occur on the preview, not the document (e.g. Word) itself.

kevinchen
Champ in-the-making
Champ in-the-making

thanks Axel ,but how can i catch the preview OnContentRead event ? 

i think the preview is the cmSmiley Tonguedf ,so  i bind  QName.createQName("http://www.alfresco.org/model/content/1.0", "thumbnail"), but can't trigger the OnContentRead event  

this.policyComponent.bindClassBehaviour( ContentServicePolicies.OnContentReadPolicy.QNAME,TYPE_CONTENT_HITS,new JavaBehaviour(this, "onContentRead"));

if(!nodeName.equals("doclib")&&type.equals(TYPE_CONTENT_HITS)){
                                NodeRef parentNodeRef= nodeService.getPrimaryParent(nodeRef).getParentRef();
                                Set<QName> aspectSet=nodeService.getAspects(parentNodeRef);
               for(QName aspect:aspectSet){
                         if(aspect.equals(ASPECT_CONTENT_HITS)){
                                            Runnable runnable = new ContentHitsReadCountIncrementer(parentNodeRef,tenantService.getCurrentUserDomain());
                                            threadExecuter.execute(runnable);
                         }
                  }
}

kaynezhang
World-Class Innovator
World-Class Innovator

OnContentReadPolicy is triggered automaticly when a reader is obtained from the ContentService,but it will be not get triggerd from an exist content writer.
So following line will have no use.
this.policyComponent.bindClassBehaviour( ContentServicePolicies.OnContentReadPolicy.QNAME,TYPE_CONTENT_HITS,new JavaBehaviour(this, "onContentRead"));

The reason why you can't catch OnContentRead event   ,I guess  it is because of following reason:

When you preview the pdf ,alfresco will try to generate the pdf file first(if not generated) and write it to renditin node ,and the reader is obtained  from an existing content writer , so OnContentReadPolicy wiil not be triggered .

kevinchen
Champ in-the-making
Champ in-the-making

finally,  i implement it by webscript when click download button ,  I modify the action link to javascript