06-03-2016 05:07 AM
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//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>
<bean id="runScriptActionTestJScript" 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', 'fts-alfresco', 'PATH:"/app:company_home/app:dictionary/cm:Scheduled_x0020_Actions/cm:myTestScript.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="runtestScheduleEveryOneMinutes" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
<property name="transactionMode">
<value>UNTIL_FIRST_FAILURE</value>
<!–value>ISOLATED_TRANSACTIONS</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>fts-alfresco</value>
</property>
<property name="stores">
<list>
<value>workspace://SpacesStore</value>
</list>
</property>
<!– Find all nodes that do not have the aspect –>
<property name="queryTemplate">
<value>PATH:"/app:company_home/st:sites/cm:mySite/cm:documentLibrary/cm:_Inbox"</value>
</property>
<property name="cronExpression">
<value>0 0/15 * * * ?</value>
</property>
<property name="jobName">
<value>TestJScriptJobName</value>
</property>
<property name="jobGroup">
<value>TestJScriptJobGroup</value>
</property>
<property name="triggerName">
<value>TestJScriptTriggerName</value>
</property>
<property name="triggerGroup">
<value>TestJScriptTriggerGroup</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="runScriptActionTestJScript"/>
</property>
<property name="transactionService">
<ref bean="TransactionService"/>
</property>
<property name="runAsUser">
<value>System</value>
<!–value>admin</value–>
</property>
</bean>
</beans>
06-04-2016 07:48 PM
06-05-2016 04:13 PM
logger.system.out(" -> running script, " + new Date().toString());
try{
if ((debug) || (log))
{
// get or create log file
var configFolder = companyhome.childByNamePath(configRootPath);
var logFile = configFolder.childByNamePath(logFileName);
// if no log file, create a new one
if ( logFile == null)
{
logFile = configFolder.createFile(logFileName);
}
// else rotate log file if necessary
else if (parseInt(logFile.size/1024) > logMaxSize){
var logFileBackup = configFolder.childByNamePath(logFileNameBackup);
// remove previous log backup
if (logFileBackup != null){
configFolder.removeNode(logFileBackup);
}
// rename existing log
logFile.name = logFileNameBackup;
logFile.save();
// create new log file
logFile = configFolder.createFile(logFileName);
}
if ( logFile == null) throw "Unable to open/create log file";
logFile.content += "\n\n________________________________________________________________\n";
logFile.content += new Date().toString() + "Run execution \n";
}
// manage locks (one process at a time).
var configFolder = companyhome.childByNamePath(configRootPath);
var lockFile = companyhome.childByNamePath(configRootPath + "/" + lockFileName);
if (!lockFile){ // lock file does not exists
// create lock file if not exists
if (!lockFile) lockFile = configFolder.createFile(lockFileName);
if (!lockFile) throw "Unable to create lock file";
// get document array to process
var childsFiles = new Array();
if (document.type == "{http://www.alfresco.org/model/content/1.0}folder"){
if (log) logFile.content += "\nCurrent node is a folder, processing childs\n";
childsFiles = document.childFileFolders(true, false);
}
else if (document.type == "{http://www.alfresco.org/model/content/1.0}content"){
if (log) logFile.content += "\nCurrent node is a document, processing current node only\n";
childsFiles[0] = document;
}
else {
throw "Unknow document type";
}
// process documents
for (ii_main in childsFiles){
if (log) logFile.content += " -> Processing file: " + childsFiles[ii_main].properties.name + "\n";
if (debug) logger.system.out(" -> Processing file: " + childsFiles[ii_main].properties.name);
//
// put all business logic here ()
//
}
// release lock (hide)
var lockFile = companyhome.childByNamePath(configRootPath + "/" + lockFileName);
if (lockFile){
configFolder.removeNode(lockFile);
}
}
else{
// Process already running
if (log) logFile.content += "Process already running\n";
if (debug) logger.system.out("Process already running");
}
}
catch (err){
logger.system.out("! Aborting, error message: " + err);
if (log) logFile.content += "\n ! Aborting, error message: " + err + "\n";
// release lock
var configFolder = companyhome.childByNamePath(configRootPath);
var lockFile = companyhome.childByNamePath(configRootPath + "/" + lockFileName);
if (lockFile){
configFolder.removeNode(lockFile);
}
}
06-09-2016 05:04 AM
06-09-2016 08:38 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.