cancel
Showing results for 
Search instead for 
Did you mean: 

Listener of add files

vincentod
Champ in-the-making
Champ in-the-making
Hello everybody

i want to developp a composant who integrates a listener for files' add by user.
I have to execute a certain treatment when each file is added.

What kind of project architecture do I find my way?
What are the important elements that can help me?

Thank you for all the information you can give to me.

Vincent
2 REPLIES 2

jpotts
World-Class Innovator
World-Class Innovator
You could do this with rules. Using this approach you would configure a rule in the UI to take some action when content is added. The action you take could be an out-of-the-box action or it might be something custom.

If rules don't work for you for some reason you could use a behavior. If you go this route, you might start with the Behavior tutorial on ecmarchitect.com.

The major difference is that rules must be configured for each folder users might add content into. Users with sufficient access could disable the rule. Behaviors, on the other hand, operate at a lower level. Behaviors are bound to types (or aspects or other things), not folders. So a behavior is invoked whenever content is added to the repo, regardless of where it is added, if it is an instance of the type to which your behavior is bound. Also, behaviors are implemented as code deployed to the Alfresco WAR so even an admin would have to have access to the app server to make a change.

Hope that helps,

Jeff

vincentod
Champ in-the-making
Champ in-the-making
Hello,

i reach to listen on adding files, like this:

public class AddFileListener implements NodeServicePolicies.OnCreateNodePolicy {

   private Logger logger = Logger.getLogger(AddFileListener.class);
   
   private Behaviour onCreateNode;

   private PolicyComponent policyComponent;

   protected NodeService nodeService;

   protected ContentService contentService;

   public void setContentService(ContentService contentService) {
      this.contentService = contentService;
   }

   public void setPolicyComponent(PolicyComponent policyComponent) {
      this.policyComponent = policyComponent;
   }

   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }

   void init() {

      // Create behaviours
      this.onCreateNode = new JavaBehaviour(this, "onCreateNode",
            NotificationFrequency.EVERY_EVENT);

      // Register interest in the onCreateNode policy - for content
      policyComponent.bindClassBehaviour(QName.createQName(
            NamespaceService.ALFRESCO_URI, "onCreateNode"),
            ContentModel.TYPE_CONTENT, onCreateNode);

   }

   @Override
   public void onCreateNode(ChildAssociationRef childAssRef) {

      System.out.println("node value is ::" + childAssRef.getQName());

   }

The adding file is logged but now i  want to get the added file to read the content.
I tried like this:


   @Override
   public void onCreateNode(ChildAssociationRef childAssRef) {

      System.out.println("node value is ::" + childAssRef.getQName());
                NodeRef nodeRefFile = childAssRef.getChildRef();
      ContentReader reader = contentService.getReader(nodeRefFile,ContentModel.PROP_CONTENT);

   }
      

But i get a null reader.

Any ideas ?

Thanks.