cancel
Showing results for 
Search instead for 
Did you mean: 

Share subscribe action

sans
Champ in-the-making
Champ in-the-making
Hi,
I want to add 'subscribe' action in share for documents and folders.
The approach that I am using is write a custom action in share which will be displayed under +More… link.
When a user clicks on the link, the action will add nodeuuid and username in a MySQL table. ( which is not in alfresco database).
Now I have following questions on this approach.
1. Wheather I should use javascript or java to handle the action?( Entering the nodeuuid and username in MySQL).
2. How do I write step 1?
3. Whether I should use a separate database or do it in Alfresco?
4. How do I link my custom action with 'share send email when items are created or enter this folder'? So that I can send email only to those people who have subscribed to folder or a document.

Please help!!!
If there is any other best approach please suggest.

Thanks
Sanjay!!
7 REPLIES 7

sans
Champ in-the-making
Champ in-the-making
No replies!!!
So far I managed to write the custom action which displays nodeuuid, username, nodetype and nodename when a user clicks on the subscribe link/action. I have used javascript based webscript to do it.
Now I need to put these values in a database.
Any idea how can I put above data into database?

Please help!!

Thanks
Sans!!

mrogers
Star Contributor
Star Contributor
Perhaps you should say what you are trying to do rather than how.

To write to another database you will need to use Java and just use standard JDBC.

Step 4.  There is a send email action.   You can bolt two actions together or even better execute a sendEmail action post commit from your first action.

sans
Champ in-the-making
Champ in-the-making
Hi mrogers,
I have written the subscribe action which inserts data into non alfresco tables.( like userid, nodeuuid of the subscribed document, resource name and resource type-file or folder)
If there is any change/update to the subscribed document, I want to send an email to people who have subscribed to the document.
I know there is an inbound rule which sends an email to group/person on update or delete of space or sub-space.
Can you please tell me if there is a way that I can link that rule with my requirement?

Please help!!

Thanks
Sanjay!!

sans
Champ in-the-making
Champ in-the-making
Hi,
I have written a subscribe action which on click puts data in non-alfresco tables. Now I want to add My Subscriptions page the way Documents I am editing or Documents - My Favorites work.
Any Idea how can I do this?

Thanks
sans!!

mrogers
Star Contributor
Star Contributor
One way of doing this is to have a policy that fires when a node is updated.    I'd add a "subscribed" aspect onto the nodes that triggers your buisness logic on create and on update.      That will have to read your custom tables and send emails.   Or just run a Stored Proc or a webscript or something in your external application that sends the emails.

Are you sure your architecture is correct?   You could manage these subscriptions within alfresco and avoid the complications of having a dependency between systems.

sans
Champ in-the-making
Champ in-the-making
Hi,
I could have used the logic of adding subscribed aspect onto the nodes.
But how am I going to scale it up for multiple users?
If two users subscribe to the same document, then how shall I reflect/show it onto the node?
Also if one of the users unsubscribes, remove the aspect but then other users will also be unsubscribed.
If there is any better approach please suggest.



Thanks
Sans

sans
Champ in-the-making
Champ in-the-making
Hi,
One more quick question on the subscribe action.
I have written the subscribe action earlier with GET webscript. But the problem I found with Ajax GET request is that when you run your action in IE7, it caches your reponse and on the next click of action it doen't even submit the GET request. It simply shows the cached success or faliure message.
To work around this problem, now I am trying to convert my GET webscript into POST webscript.
But I am not sure How do I pass the nodeRef from javascript to my Java class.
Here are the snippets from different files.
subscribe-action-min.js
this.modules.actions.genericAction(
        {
           success:
           {
              message: this.msg("message.subscribe.success", file.displayName)
           },
           failure:
           {
              callback:
              {
                 fn: failureHandler,
                 scope: this
              }
           },
           webscript:
           {
         name: "subscribe/site/{site}/{container}",
              method: Alfresco.util.Ajax.POST
           },
      wait:
               {
                     message: this.msg("message.please-wait")
               },
           params:
           {
              site: this.options.siteId,
              container: this.options.containerId
           },
           config:
           {
              requestContentType: Alfresco.util.Ajax.JSON,
              dataObj:
              {
                 nodeRefs: [file.nodeRef]
              }
           }
        });
SubscribeWebScript.java
public class SubscribeWebScript extends AbstractWebScript
{
……final public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
    {
        try
       {
           //userTransaction = registry.getTransactionService().getUserTransaction();
          authenticationService = registry.getAuthenticationService();
          String userName = authenticationService.getCurrentUserName();
          
          String rootNodeRef = req.getParameter("nodeRefs");
           
            if(rootNodeRef != null && NodeRef.isNodeRef(rootNodeRef))
            {
               nodeRef = new NodeRef(rootNodeRef);
               nodeuuid = nodeRef.getId();
            }
           
            nodeService = registry.getNodeService();
            String fileName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
This one bombs out on (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
Giving following exception.
org.springframework.extensions.webscripts.WebScriptException: 07080002 Couldn't subscribe to resource [color=#BF4080]NodeRef may not be null for calls to NodeService.  Check client code.[/color]   at uk.nhs.sth.crest.webscript.subscribe.SubscribeWebScript.execute(SubscribeWebScript.java:151)
   at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:383)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:381)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:436)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:466)
   at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:304)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:333)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
   at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
   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.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
   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:127)
   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:298)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:619)
subscribe.post.json.ftl
<#import "action.lib.ftl" as actionLib />
web-scripts-application-context.xml
<bean id="webscript.org.alfresco.slingshot.documentlibrary.action.subscribe.post" 
         class="uk.nhs.sth.crest.webscript.subscribe.SubscribeWebScript"
         parent="webscript">
         <property name="repository" ref="repositoryHelper" />
         <property name="serviceRegistry" ref="ServiceRegistry" />
         <property name="subscribeDAOImpl" ref="subscribeDAO" />
   </bean>
subscribe.post.desc.xml
<webscript>
  <shortname>Subscribe Webscript</shortname>
  <description>Document/Folder List Action - Subscribe document/folder</description>
  <url>/slingshot/doclib/action/subscribe/site/{site}/{container}</url>
  <authentication>user</authentication>
  <format default="json">argument</format>
  <transaction>required</transaction>
</webscript>

My question is how do I pass the parameters from client subscribe-action-min.js to my java class?

Thanks
Sans!!!