cancel
Showing results for 
Search instead for 
Did you mean: 

subscribe aspect

xerox
Champ in-the-making
Champ in-the-making
I made a link by every document(in de browse page) with subscribe.
the meaning of this is, that a person can subscribe himself on a document.
If you click on that link, it calls browsebean.subscribe.

code of browsebean.subscribe

public void Subscribe()
   {
      UserTransaction tx = null;
     
      try
      {
         tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
         tx.begin();
        
         // add the versionable aspect to the node
         this.nodeService.addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_SUBSCRIBABLE, null);
        
         // commit the transaction
         tx.commit();
        
         // reset the state of the current document
         getDocument().reset();
      }
      catch (Throwable e)
      {
         // rollback the transaction
         try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
         Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
               FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_SUBSCRIBE), e.getMessage()), e);
      }
   }
But this doesn't work.
Does someone know how to deal with the subscribe aspect?
12 REPLIES 12

gavinc
Champ in-the-making
Champ in-the-making
Hi,

The subscribe aspect is one that doesn't have any functionality tied to it. The code you have looks fine so you'll probably find that it has in fact added the aspect to the node (you could see this through the node browser in the admin console). You would also have to add the association to a 'person', this can be done through the UI. Simply configure the "subscribedBy" association to appear for any nodes that have the "subscribable" aspect applied.

However, for something to happen when the node is "touched" will require some customisation. The other topic you posted to had some information on tying into the policy framework which could be used to accomplish this.

xerox
Champ in-the-making
Champ in-the-making
thx…

<You would also have to add the association to a 'person', this can be done through the UI. Simply configure the "subscribedBy" association to appear for any nodes that have the "subscribable" aspect applied. >

How can I do this? can you explain a little further, because I don't get it.

Nick
thx in advance

gavinc
Champ in-the-making
Champ in-the-making
I'm presuming you know about the web-client-config-custom.xml file, if not take a look at: http://wiki.alfresco.com/wiki/Web_Client_Configuration_Guide

Edit the web-client-config-custom.xml file and add the following config section:


<config evaluator="aspect-name" condition="subscribable">
   <property-sheet>
      <show-association name="subscribedBy" />
   </property-sheet>
</config>

Then when you view and edit the properties of the node you will see the subscribedBy property listed.

xerox
Champ in-the-making
Champ in-the-making
With which method of the nodeservice can I add associations?
I mean when a user click on the subscribe link, he needs to be add as an association of subscribe.

I tried this.but this isn't working.

String nameuser = this.authenticationService.getCurrentUserName();
NodeRef refuser = this.personService.getPerson(nameuser);
        
         //associate the user with it.
        
this.nodeService.createAssociation(getDocument().getNodeRef(),refuser,ContentModel.ASSOC_SUBSCRIBEDBY);

Nick

gavinc
Champ in-the-making
Champ in-the-making
The code you have looks fine to me.

When you say it isn't working what do you mean? You don't see an association from the node to the user in the node browser? or are you getting an exception?

xerox
Champ in-the-making
Champ in-the-making
I always get a null pointer exception.
I also don't see the association in de node browser.

xerox
Champ in-the-making
Champ in-the-making
I found my mistake. the services authenticationService and personService  gave the nullpointer exception.
My solution

FacesContext context = FacesContext.getCurrentInstance();
//       Obtain the ServiceRegistry
        ServiceRegistry serviceRegistry = Repository.getServiceRegistry(context);
              
           // Obtain the services we need from the ServiceRegistry
           authenticationService = serviceRegistry.getAuthenticationService();
           personService = serviceRegistry.getPersonService();

this is working with the authenticationservice, but not with the personservice. Because the serviceRegistry doesn't know a personservice.
How can I fix this?

xerox
Champ in-the-making
Champ in-the-making
it workes…
Now a person can subscribe at an item.

for the personservice I needed this line

PersonService personService = (PersonService)FacesContextUtils.getRequiredWebApplicationContext(context).getBean("personService");

Now I'll try to implement a class which sends email to the subscribers.

Nick

xerox
Champ in-the-making
Champ in-the-making
If now a person subcribe to content, It works.
But If If Checkout and than checkin that content I've always get an error

Unable to check in Content Node due to system error:null

and the error takes place when it runs the trought the follwing code
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
            throws InvalidNodeRefException, AssociationExistsException
    {
        // Invoke policy behaviours      
       invokeBeforeUpdateNode(sourceRef);
      
   
      
        Node sourceNode = getNodeNotNull(sourceRef);
        System.out.println(sourceNode);
        Node targetNode = getNodeNotNull(targetRef);
        System.out.println(targetNode);
        System.out.println(assocTypeQName);
        // see if it exists
        NodeAssoc assoc = nodeDaoService.getNodeAssoc(sourceNode, targetNode, assocTypeQName);
        if (assoc != null)
        {
            throw new AssociationExistsException(sourceRef, targetRef, assocTypeQName);
        }
        // we are sure that the association doesn't exist - make it
        assoc = nodeDaoService.newNodeAssoc(sourceNode, targetNode, assocTypeQName);
        AssociationRef assocRef = assoc.getNodeAssocRef();

      // Invoke policy behaviours
      invokeOnUpdateNode(sourceRef);
        invokeOnCreateAssociation(assocRef);
      
        return assocRef;
    }