AnsweredAssumed Answered

Scheduled actions with javascript and/or xml

Question asked by lorenz on May 7, 2007
Latest reply on Jul 30, 2007 by naveenkumar
Hi all,

I'm trying to define some scheduled processes that execute actions defined in xml or in JavaScript.

So far I managed to persuade Alfresco to execute a query on the repository and sending me a test email for every record found. I use a custom aspect called "expiring" in my own namespace http://www.mydomain.org/model/content/1.0 like the following:


   <bean id="sendTestMail" 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>
      <!– Find all nodes that have the aspect my:expiring and are due tomorrow –>
      <property name="queryTemplate">
         <value>
            +PATH:"/app:company_home/*//*"
            +ASPECT:"{http://www.mydomain.org/model/content/1.0}expiring"
            @my\:expirationDate:${luceneDateRange(today, "P1D")}
         </value>
      </property>
      <property name="cronExpression">
         <value>10 * * * * ?</value>
      </property>
      <property name="jobName">
         <value>mydomainExpirationChecker</value>
      </property>
      <property name="jobGroup">
         <value>mydomainJobGroup</value>
      </property>
      <property name="triggerName">
         <value>mydomainTriggerEC</value>
      </property>
      <property name="triggerGroup">
         <value>mydomainTriggerGroup</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="sendTestMailAction"/>
      </property>
      <property name="transactionService">
         <ref bean="TransactionService"/>
      </property>
      <property name="runAsUser">
         <value>System</value>
      </property>
   </bean>

The above configuration executes an action called "sendTestMailAction" defined as follows:


<bean id="sendTestMailAction" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
      <property name="actionName">
         <value>mail</value>
      </property>
      <property name="parameterTemplates">
         <map>
            <entry>
               <key><value>to</value></key>
               <value>lorenz@mydomain.org</value>
            </entry>
            <entry>
               <key><value>from</value></key>
               <value>lorenz@mydomain.org</value>
            </entry>
            <entry>
               <key><value>text</value></key>
               <value>this is a test</value>
            </entry>
            <entry>
               <key><value>subject</value></key>
               <value>test from scheduler</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>

.. so far everything runs smoothly (well at least I get tons of emails ;)

I now wonder how I could change the above to send some meaningful messages, i.e. using an email template containing a reference to the content linked to the things the query found.

Another thing I was not able to figure out is how I manage to execute some JavaScript code instead of the above email action.

I'm quite new to Alfresco, so please be forgiving in case I just asked something stupid :-/ I read through the Wiki and various posts here on the forum, but couldn't find an answer to my questions.

What I'm trying to achieve in the end is to implement some sort of scheduling processes that can move content from space to another or start advanced workflow processes depending on an objects expiration date.

Any help ist greatly appreciated.

Lorenz

Outcomes