4

I am trying to implement notifications for calendar events. I have followed the discussion in

Email Notifications on Calendar Events in Alfresco

to the letter but still can't get it to work. I want to send notifications based on calendar events 2 days before a calendar event. It should only send it to site members (it is worth noting that the site members & all users in general are being picked from an ldap server).

My scheduled-action-services-context.xml looks like the following:

        <!--
Define the model factory used to generate object models suitable for use with freemarker templates.
-->
<bean id="templateActionModelFactory" class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
    <property name="serviceRegistry">
        <ref bean="ServiceRegistry"/>
    </property>
</bean>

        <!--
Execute the script /Company Home/Record Management/testscript.js
-->
<bean id="runScriptAction" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
    <property name="actionName">
        <value>script</value>
    </property>
    <property name="parameterTemplates">
        <map>
            <entry>
                <key>
                    <value>script-ref</value>
                </key>
                <!-- Note that as of Alfresco 4.0, due to a  Spring upgrade, the FreeMarker ${foo} entries must be escaped -->
                <value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:calendar_notify.js"' )\}</value>
            </entry>
        </map>
    </property>
    <property name="templateActionModelFactory">
        <ref bean="templateActionModelFactory"/>
    </property>
    <property name="dictionaryService">
        <ref bean="DictionaryService"/>
    </property>
    <property name="actionService">
        <ref bean="ActionService"/>
    </property>
    <property name="templateService">
        <ref bean="TemplateService"/>
    </property>
</bean>

 <!--
  Run the script every minute - select the single node company home that is not used ...
-->
<bean id="runScript" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
    <property name="transactionMode">
        <value>UNTIL_FIRST_FAILURE</value>
    </property>
    <property name="compensatingActionMode">
        <value>IGNORE</value>
    </property>
    <property name="searchService">
        <ref bean="SearchService"/>
    </property>
    <property name="templateService">
        <ref bean="TemplateService"/>
    </property>
    <property name="queryLanguage">
        <value>lucene</value>
    </property>
    <property name="stores">
        <list>
            <value>workspace://SpacesStore</value>
        </list>
    </property>
    <property name="queryTemplate">
        <!--<value>+@ia\:fromDate:\$\{luceneDateRange(now, \"P10D\")\} AND +PATH:"/app:company_home/st:sites/cm:prova/cm:calendar//*"</value>-->
                      <value>+PATH:"/app:company_home/st:sites//*/cm:calendar//*" AND   +@ia\:fromDate:[NOW TO MAX]</value>

    </property>
    <property name="cronExpression">
        <value>0 0/10 * * * ?</value>
    </property>
    <property name="jobName">
        <value>jobD</value>
    </property>
    <property name="jobGroup">
        <value>jobGroup</value>
    </property>
    <property name="triggerName">
        <value>triggerD</value>
    </property>
    <property name="triggerGroup">
      <value>triggerGroup</value>
    </property>
    <property name="scheduler">
        <ref bean="schedulerFactory"/>
    </property>
    <property name="actionService">
        <ref bean="ActionService"/>
    </property>
    <property name="templateActionModelFactory">
        <ref bean="templateActionModelFactory"/>
    </property>
    <property name="templateActionDefinition">
        <ref bean="runScriptAction"/> <!-- This is name of the action (bean) that gets run -->
    </property>
    <property name="transactionService">
        <ref bean="TransactionService"/>
    </property>
    <property name="runAsUser">
        <value>System</value>
    </property>
</bean>

My email template is found in the location

Company Home > Data Dictionary > Email Templates > Notify Email Templates

and the template is as follows:

 <html>
 <head>
  <style type="text/css"><!--
  body
  {
     font-family: Arial, sans-serif;
     font-size: 14px;
     color: #4c4c4c;
  }

  a, a:visited
  {
     color: #0072cf;
  }

  .activity a
  {
     text-decoration: none;
  }

  .activity a:hover
  {
     text-decoration: underline;
  }
  --></style>
</head>

 <body bgcolor="#dddddd">
<#assign displayPaths=document.displayPath?split("/")>
<#assign site=displayPaths[3]>
<#assign contenuto=document.content>
  <table width="100%" cellpadding="20" cellspacing="0" border="0" bgcolor="#dddddd">
     <tr>
        <td width="100%" align="center">
           <table width="70%" cellpadding="0" cellspacing="0" bgcolor="white" style="background-color: white; border: 1px solid #aaaaaa;">
              <tr>
                 <td width="100%">
                    <table width="100%" cellpadding="0" cellspacing="0" border="0">
                       <tr>
                          <td style="padding: 20px 30px 0px;">
                             <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                <tr>
                                   <td>
                                      <div style="font-size: 22px; padding-bottom: 4px;">
                                         Clinical Information Network reminds you that tomorrow ...
                                      </div>
                                      <div style="font-size: 14px; margin: 18px 0px 24px 0px; padding-top: 18px; border-top: 1px solid #aaaaaa;">


                                            <div class="activity">
                                               title: ${document.properties["{http://www.alfresco.org/model/calendar}whatEvent"]}
 <br></br>
 <br></br>
 description: ${document.properties["{http://www.alfresco.org/model/calendar}descriptionEvent"]}
  <br></br>
  <br></br>
  date: ${document.properties["{http://www.alfresco.org/model/calendar}fromDate"]?date}
  <br></br>
  <br></br>
  from: ${document.properties["{http://www.alfresco.org/model/calendar}fromDate"]?time}
  <br></br>
  <br></br>
  where: ${document.properties["{http://www.alfresco.org/model/calendar}whereEvent"]}

                                            </div>
                                            <div style="font-size: 11px; padding: 4px 0px 12px 0px;">
                                            </div>
                                      </div>
                                   </td>
                                </tr>
                             </table>
                          </td>
                       </tr>
                       <tr>
                          <td>
                             <div style="border-top: 1px solid #aaaaaa;">&nbsp;</div>
                          </td>
                       </tr>
                       <tr>
                         <td style="padding: 0px 30px; font-size: 13px;">
                             Please do not reply to this mail, the complete calendar is at:
                http://host:8080/share/page/site/${site}/calendar
                          </td>
                       </tr>
                       <tr>
                          <td>
                             <div style="border-bottom: 1px solid #aaaaaa;">&nbsp;</div>
                          </td>
                       </tr>
                       <tr>
                          <td style="padding: 10px 30px;">
                             <img src="${shareUrl}/themes/default/images/logo.png" alt="" width="117" height="48" border="0" />
                          </td>
                       </tr>
                    </table>
                 </td>
              </tr>
           </table>
        </td>
     </tr>
  </table>
 </body>
 </html>

And the calendar_notify.js javascript that is found in

Company_Home > Data Dictionary > Scripts

looks like the following:

var titoloEvento = document.properties["{http://www.alfresco.org/model/calendar}whatEvent"];
var fromDate = document.properties["{http://www.alfresco.org/model/calendar}fromDate"];

var today = new Date();

fromDate.setHours(0,0,0);
today.setHours(0,0,0);

var milli_fromDate = fromDate.getTime();
var milli_today = today.getTime();

var diff = fromDate - today;

var num_days =Math.round(diff/(86400000));

var person;
var email;

if (num_days == 1) {

  var displayPaths=document.displayPath.split("/");
  var siteName = displayPaths[3];
  var site=siteService.getSite(siteName);

 var siteMembers = site.listMembers(null,null,0);

 if(siteMembers !=null){
        for (userName in siteMembers ){

               person = people.getPerson(userName);

               email = person.properties["cm:email"];

             var mail = actions.create("mail");

             mail.parameters.html = "html";

             mail.parameters.to = email;

             mail.parameters.template =   search.findNode("workspace://SpacesStore/f98619dc-7b09-40c6-8057-2867728c45a0"); //please set the correct node reference for the email template

             mail.parameters.subject = "Share reminder: "+titoloEvento;
             mail.parameters.from = "clinicalinformationnetwork@gmail.com";

             // execute action against a document   
             mail.execute(document);
     }
  }
}

What could be causing it to fail? I have tried to figure it out for the last 48hrs and I still don't see why it's not executing.

Community
  • 1
  • 1
Timothy Tuti
  • 992
  • 2
  • 15
  • 29
  • 1
    your -context is invalid, you have a duplicate bean id="runScript & a non-closed bean-tag – alfrescian Jan 22 '14 at 10:26
  • Sorry about that. I had pasted the code wrongly because of copying segment by segment. I have edited the post to reflect how it actually is. Sorry for that. Would you take a look and tell me what might be the problem? – Timothy Tuti Jan 22 '14 at 10:40

1 Answers1

1

Though this answer might be too late but it is still good to give some answer here. Because I happen to recently try to set up this function as well.

After some time of digging, I could finally make it work in my Alfresco. Here are some things you may want to check:

  1. Check alfresco.log in the alfresco root folder. You might see some exceptions every time the scheduled task is run, and it might give you the clue.

  2. Need to double check the reference ID in "mail.parameters.template = search.findNode...." points to the correct node of the email template.

  3. You might not have set up the SMTP mail server correctly. Google SMTP alfresco to find it out.

  4. For most SMTP server, they check the "from" field to match your login account. Make sure the "mail.parameters.from =" is correct.

  5. The Gmail SMTP doesn't work. Looks like Gmail requires stronger security client that Alfresco does not comply with.

  6. In order to debug, an easy way is to add statements like below to some points of the javascript. The warnning message will be put in alfresco.log as well. logger.warn("....");

Hope this helps.

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
Gordon Liang
  • 348
  • 2
  • 11