Obsolete Pages{{Obsolete}}
The official documentation is at: http://docs.alfresco.com
Content ModelingActionsScheduled Processes
A scheduled action is made up of three parts:
At the times specified by the cron expression, the query template is used to generate a query. Any supported query language can be used. The query is run to select a set of nodes. For each of the nodes in the set, the action template is converted into an action and then the action is applied to the node.
The use of query templates allows the query to generate entries for dates and date ranges such as 'today' and 'the last four years'. The use of templates for actions allows properties of each node found by the query to be used to parameterise the action instance. The parameters defined in the action template can be defined as FreeMarker templates. When the action is built from the action template its parameters are generated from the FreeMarker templates using a template model with the current node defined. So you can use properties of the node to set the properties on the action.
Currently definitions of scheduled actions are made in XML.
The action templates can be composite action templates or single actions.
Currently an action applies to a single node (it can not take the whole set of selected nodes)
The query can be something like:
...
And the action any one of the built in:
This example finds files without the general classifiable aspect and adds it with a default classification.
The examples shown all refer to a bean templateActionModelFactory but do not define it. The docs here show that the only known implementing class of TemplateActionModelFactory interface is FreeMarkerWithLuceneExtensionsModelFactory and the example scheduled-action-services-context.xml.sample defines the bean as such:
<bean id='templateActionModelFactory' class='org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory'>
<property name='serviceRegistry'>
<ref bean='ServiceRegistry'/>
</property>
</bean>
You should define this bean within your override, perhaps at alfresco/extension/scheduled-action-services-context.xml
<bean id='addClassifiableAspectAction' class='org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition'>
<property name='actionName'>
<value>add-features</value>
</property>
<property name='parameterTemplates'>
<map>
<entry>
<key>
<value>aspect-name</value>
</key>
<value>{http://www.alfresco.org/model/content/1.0}generalclassifiable</value>
</entry>
<entry>
<key>
<value>{http://www.alfresco.org/model/content/1.0}categories</value>
</key>
<value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:'/cm:generalclassifiable/cm:Languages/cm:English'' )\}</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>
<bean id='addClassifiableAspectEveryTenMinutes' 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:'//\*' -ASPECT:'{http://www.alfresco.org/model/content/1.0}generalclassifiable'</value>
</property>
<property name='cronExpression'>
<value>0 50 * * * ?</value>
</property>
<property name='jobName'>
<value>jobA</value>
</property>
<property name='jobGroup'>
<value>jobGroup</value>
</property>
<property name='triggerName'>
<value>triggerA</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='addClassifiableAspectAction'/>
</property>
<property name='transactionService'>
<ref bean='TransactionService'/>
</property>
<property name='runAsUser'>
<value>System</value>
</property>
</bean>
Those properties not mentioned explicitly are required services and should be set as the above example.
Those properties not mentioned explicitly are required services and should be set as the above example.
The FreeMarker template is extended with some support to build Lucene query strings.
This is mostly around dates.
Template expression | Meaning |
---|---|
${luceneDateRange(\'2000-01-01T00:00:00.000Z\', \'P4D\')} | [2000-01-01T00:00:00.000Z TO 2000-01-05T00:00:00.000Z] |
${luceneDateRange(today, \'P4D\')}' | a range of the form [X TO Y] where X is today and Y is Today + 4 days |
${luceneDateRange(today, \'-P4D\')} | a range of the form [X TO Y] where X is today and Y is Today - 4 days |
${luceneDateRange(today, today)} | a range of the form [X TO Y] where X is today and Y is today |
Date ranges are expressed as XML durations.
Note that as of Alfresco 4.0, due to a Spring upgrade, the FreeMarker ${foo} entries must be escaped in the Context XML. A
FreeMarker expression such as ${today} much be written in the XML as \$\{today\}
PATH:'//\*' -ASPECT:'{http://www.alfresco.org/model/content/1.0}generalclassifiable'
Find all nodes that do not have the general classifiable aspect
ASPECT:'{http://www.alfresco.org/model/content/1.0}generalclassifiable'
Find all nodes that do have the general classifiable aspect
+PATH:'/app:company_home/*//*' +TEXT:'tutorial'
Find all nodes under company home that also contain tutorial in the content.
@cm\:created:\$\{luceneDateRange(yesterday, '-P10Y')\}
Find all nodes created yesterday or in the 10 years before
A cron expression is 6 or 7 text fields that are separated by whitespace.
Field Name | Position | Mandatory | Allowed Values | Special Characters |
---|---|---|---|---|
Seconds | 1 | Yes | 0-59 | , - * / |
Minutes | 2 | Yes | 0-59 | , - * / |
Hours | 3 | Yes | 1-23 | , - * / |
Day of Month | 4 | Yes | 1-31 | , - * ? / L W C |
Month | 5 | Yes | 1-12 or JAN-DEC | , - * / |
Day of Week | 6 | Yes | 1-7 or SUN-SAT | , - * ? / L C # |
Year | 7 | No | empty, 1970-2099 | , - * / |
Expression | Meaning | Notes |
0 0 12 * * ? | At 12pm (noon) every day | Note that the day of the month is specified as all (*) and the day of the week as unspecified (?). |
0 0 12 * * ? * | At 12pm (noon) every day | |
0 0 12 ? * * | At 12pm (noon) every day | |
0 0 12 ? * * * | At 12pm (noon) every day | |
0 30 2 * * ? | At 2:30 am every day | |
0 30 2 * * ? 2006 | At 2:30 am every day during 2006 | |
0 10 * * * ? | Every hour at ten past the hour | |
0 * 8 * * ? | Every minute from 8.00am until 8.59 every day | |
0 0,30 8-18 * * ? | Every half hour from 8.00am until 18.00 | |
0 0/15 * * * ? | Every 15 minutes at 0, 15, 30, 45 minutes past the hour | |
0 0 2,14 ? * FRI | At 2.00am and 2pm every Friday | |
0 0 4 LW 3,6,9,12 ? | At 4.00am on the last week day of each quarter | |
0 0 2 * * 6#1 | At 2.00am on the first friday of every month |
<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>
<value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:'/app:company_home/cm:Record_x0020_Management/cm:testscript.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>
<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>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='runScriptAction'/>
</property>
<property name='transactionService'>
<ref bean='TransactionService'/>
</property>
<property name='runAsUser'>
<value>System</value>
</property>
</bean>
More examples can be found in config\alfresco\extension\scheduled-action-services-context.xml.sample
.