1 package org.alfresco.sample.contentHits; 2 3 import java.util.Date ; 4 5 import org.alfresco.repo.content.ContentServicePolicies; 6 import org.alfresco.repo.node.NodeServicePolicies; 7 import org.alfresco.repo.policy.JavaBehaviour; 8 import org.alfresco.repo.policy.PolicyComponent; 9 import org.alfresco.service.cmr.repository.NodeRef; 10 import org.alfresco.service.cmr.repository.NodeService; 11 import org.alfresco.service.namespace.NamespaceService; 12 import org.alfresco.service.namespace.QName; 13 14 19 public class ContentHitsAspect implements ContentServicePolicies.OnContentReadPolicy, 20 ContentServicePolicies.OnContentUpdatePolicy, 21 NodeServicePolicies.OnAddAspectPolicy 22 { 23 24 public static final QName ASPECT_CONTENT_HITS = QName.createQName("extension.contenthits", "contentHits"); 25 26 27 public static final QName PROP_COUNT_STARTED_DATE = QName.createQName("extension.contenthits", "countStartedDate"); 28 public static final QName PROP_UPDATE_COUNT = QName.createQName("extension.contenthits", "updateCount"); 29 public static final QName PROP_READ_COUNT = QName.createQName("extension.contenthits", "readCount"); 30 31 32 private PolicyComponent policyComponent; 33 34 35 private NodeService nodeService; 36 37 42 public void setPolicyComponent(PolicyComponent policyComponent) 43 { 44 this.policyComponent = policyComponent; 45 } 46 47 52 public void setNodeService(NodeService nodeService) 53 { 54 this.nodeService = nodeService; 55 } 56 57 60 public void initialise() 61 { 62 this.policyComponent.bindClassBehaviour( 64 QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), 65 ASPECT_CONTENT_HITS, 66 new JavaBehaviour(this, "onAddAspect")); 67 this.policyComponent.bindClassBehaviour( 68 ContentServicePolicies.ON_CONTENT_READ, 69 ASPECT_CONTENT_HITS, 70 new JavaBehaviour(this, "onContentRead")); 71 this.policyComponent.bindClassBehaviour( 72 ContentServicePolicies.ON_CONTENT_UPDATE, 73 ASPECT_CONTENT_HITS, 74 new JavaBehaviour(this, "onContentUpdate")); 75 } 76 77 86 public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) 87 { 88 if (aspectTypeQName.equals(ASPECT_CONTENT_HITS) == true) 89 { 90 this.nodeService.setProperty(nodeRef, PROP_COUNT_STARTED_DATE, new Date ()); 92 } 93 } 94 95 102 public void onContentRead(NodeRef nodeRef) 103 { 104 Integer currentValue = (Integer )this.nodeService.getProperty(nodeRef, PROP_READ_COUNT); 106 int newValue = currentValue.intValue() + 1; 107 this.nodeService.setProperty(nodeRef, PROP_READ_COUNT, newValue); 108 } 109 110 117 public void onContentUpdate(NodeRef nodeRef, boolean newContent) 118 { 119 Integer currentValue = (Integer )this.nodeService.getProperty(nodeRef, PROP_UPDATE_COUNT); 121 int newValue = currentValue.intValue() + 1; 122 this.nodeService.setProperty(nodeRef, PROP_UPDATE_COUNT, newValue); 123 } 124 } 125 | Popular Tags |