cancel
Showing results for 
Search instead for 
Did you mean: 

Scheduled Actions:The java implementation,how does it works?

kroax
Champ in-the-making
Champ in-the-making
Hi,

I got a look at http://wiki.alfresco.com/wiki/Scheduled_Actions which explain the concept of scheduled actions. It is quite good but I know we need to reference java code to run the scheduled action. Particularly, we have to implement a java bean, but I know nothing more. There are no code examples on wiki, which class do I need to extend, which interfaces do I need to implement, basically, which part of the API do I need to use ?

Any code example will be great !

Thanks for your help.
3 REPLIES 3

kroax
Champ in-the-making
Champ in-the-making
I tried to set parameters in the .xml as required. My script names "autoImport.js". Unfortunately, the script doesn't run every minutes as I expect. Why ?

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD ?EAN//EN'
    'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
   <!–
      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>
   <!–Example Chapter 6 : Action Definition
      Action is to execute the "Company Home > Data Dictionary >
      Scripts > chapter6_publish_effective_content.js" script
   –>
   <bean id="autoImport.js"
      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>
               <value>
                  ${selectSingleNode('workspace://SpacesStore',
                  'lucene',
                  'PATH:"/app:company_home/app:dictionary/app:scripts/cm:
                  autoImport.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>
   <!–
      Example Chapter 6 : The query and scheduler definition
      Query     - No specific query is used
      Scheduler - Run the script for every 15 minutes
      Action    - Call chapter6_runScriptAction defined above
   –>
   <bean id="autoImport_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>PATH:"/app:company_home"</value>
      </property>
      <property name="cronExpression">
         <value>0 0/1 * * * ?</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="autoImport.js" />
         <!– 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>
</beans>

togomez
Champ on-the-rise
Champ on-the-rise
I've got quite same problem. The action seems to be running due to the log

13:29:05,026 DEBUG [action.scheduled.AbstractScheduledAction] Found 1
13:29:05,026 DEBUG [action.scheduled.AbstractScheduledAction] Executing in individual transaction
13:29:05,037 DEBUG [repo.action.ActionServiceImpl] Exceute action impl action chain = null
13:29:05,037 DEBUG [repo.action.ActionServiceImpl] Current action = c88e361d-20b3-11dc-862c-dd60beb0b159
13:29:05,037 DEBUG [repo.action.ActionServiceImpl] Doing executeActionImpl
13:29:05,038 DEBUG [repo.action.ActionServiceImpl] Adding c88e361d-20b3-11dc-862c-dd60beb0b159 to action chain.
13:29:05,038 DEBUG [repo.action.ActionServiceImpl] The action is being executed as the user: System
13:29:05,041 DEBUG [repo.action.ActionServiceImpl] Resetting the action chain.
13:29:25,017 DEBUG [action.scheduled.AbstractScheduledAction] Found 1
13:29:25,017 DEBUG [action.scheduled.AbstractScheduledAction] Executing in individual transaction
13:29:25,031 DEBUG [repo.action.ActionServiceImpl] Exceute action impl action chain = null
13:29:25,031 DEBUG [repo.action.ActionServiceImpl] Current action = d47934d1-20b3-11dc-862c-dd60beb0b159
13:29:25,031 DEBUG [repo.action.ActionServiceImpl] Doing executeActionImpl
13:29:25,032 DEBUG [repo.action.ActionServiceImpl] Adding d47934d1-20b3-11dc-862c-dd60beb0b159 to action chain.
13:29:25,032 DEBUG [repo.action.ActionServiceImpl] The action is being executed as the user: System
13:29:25,035 DEBUG [repo.action.ActionServiceImpl] Resetting the action chain.


Nevertheless the javascript isn't doing anything.

togomez
Champ on-the-rise
Champ on-the-rise
Following the example in the alfresco wiki finally my javascript works fine.


http://wiki.alfresco.com/wiki/Scheduled_Actions#Script_Action_Example