cancel
Showing results for 
Search instead for 
Did you mean: 

Running a rule on a schedule?

drakee
Champ in-the-making
Champ in-the-making
I am new to using Alfresco, but I have searched unsuccessfully for documentation on how to do the following: I would like to create a simple rule that Publishes documents at a specific time interval (e.g. every week on Sunday at midnight). So, for example, this rule would move any documents in the 'Staging' folder to the 'Published' folder at the same time each week.

In my searches, I found references to scheduled actions, which may be what I'm looking for, and people have mentioned the scheduled-action-services-context.xml file, but I haven't been able to find a tutorial or example that explains how to use it. Thanks for any help you can offer!
2 REPLIES 2

drakee
Champ in-the-making
Champ in-the-making
OK, I think I figured out how this is supposed to work. In ${ALFRESCO_HOME}/tomcat/shared/classes/alfresco/extension/scheduled-actions-services-context.xml, I have:


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
  <bean id="publishFromStagingAction" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
        <property name="actionName">
            <value>move</value>
        </property>
        <property name="parameterTemplates">
            <map>
                <entry>
                    <key>
                        <value>destination-folder</value>
                    </key>
          <value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/cm:Published"' )}</value>
                </entry>
                <entry>
                    <key>
                        <value>assoc-type</value>
                    </key>
                    <value>${node.primaryParentAssoc.typeQName}</value>
                </entry>
                <entry>
                    <key>
                        <value>assoc-name</value>
                    </key>
                    <value>${node.primaryParentAssoc.QName}</value>
                </entry>
                <entry>
                    <key>
                        <value>deep-copy</value>
                    </key>
                    <value>false</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="publishFromStagingSchedule" 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/cm:test_image.gif"</value>
        </property>
        <property name="cronExpression">
            <value>0 */5 * * * ?</value>
        </property>
        <property name="jobName">
            <value>jobA</value>
        </property>
        <property name="jobGroup">
            <value>jobGroup</value>
        </property>
        <property name="triggerName">
            <value>triggerName</value>
        </property>
        <property name="triggerGroup">
            <value>triggerGroup</value>
        </property>
        <!– Inject the scheduler - the trigger will be registered with this scheduler –>
        <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="publishFromStagingAction"/>
        </property>
        <property name="transactionService">
            <ref bean="TransactionService"/>
        </property>
        <property name="runAsUser">
            <value>System</value>
        </property>
    </bean>
</beans>

On startup, this should initiate a schedule for moving a test image from the company home into the Published directory, every 5 minutes. However when starting Alfresco I get the error:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'templateActionModelFactory' is defined

Is this a known issue? I found one reference on the Internet:
http://forums.alfresco.com/en/viewtopic.php?f=10&t=9716

But I didn't get any clues from that post. Thanks!

drakee
Champ in-the-making
Champ in-the-making
I figured out what was missing. In the scheduled-actions-services-context.xml file, I needed to include the following:


    <bean id="templateActionModelFactory" class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
    </bean>

After fixing that, I was finally able to get the scheduled action to work - but only after fixing a few other issues:
  • I had to comment out the "deep-copy" entry in the parameterTemplates map in scheduled-actions-services-context.xml

  • In CronScheduledQueryBasedTemplateActionDefinition.java:229 I had to print out the variable templateService and the result of getTemplateActionModelFactory() to avoid a NullPointerException.

  • In SimpleTemplateActionDefinition.java:202 I had to print out the variable dictionaryService and the variable paramName to avoid a NullPointerException
The last two fixes required downloading the Alfresco source from svn (version 3.2), altering the source code, and running ant to compile everything. I took the newly compiled classes and substituted them for the originals in ${ALFRESCO_HOME}/tomcat/webapps/alfresco/WEB-INF/lib/alfresco-repository.jar.

Hope this helps someone!