cancel
Showing results for 
Search instead for 
Did you mean: 

Default missing parameters in context

rjohnson
Star Contributor
Star Contributor
I have a timed job that sets its quarrtz cron string using a parameter like this


        <property name="cronExpression">
         <value>${myservice.cron}</value>
        </property>


I would like to be able to default the service cron should someone not set the parameter myservice.cron in alfresco-global.properties and I cannot find out how to do this.

At first I thought this was Freemarker but

${(myservice.cron)!'0 0/1 * * * ?'}

did not work.

Then I found an article saying Freemaker directives must be escaped so I tried

\$\{(myservice.cron)!'0 0/1 * * * ?'\}

but that didn't work either.

More ferreting around on the internet suggests that Alfresco "works out" how to process a parameter based on regex & an array of processors but I cannot fathom out how that works.

Grepping the entire context xml files in Alfresco did not yield any suggestions as to how this can be done

Any kind soul want to explain to me how I set a parameter string that says Use this value if the property exists and if not us "0 0/1 * * * ?"?

Many thanks
2 REPLIES 2

mrogers
Star Contributor
Star Contributor
Do you want to default the parameter in the spring context for injection into a spring bean or format something like a web script response with a freemarker template?   There is a big difference.

If in the spring context then there are a number of locations loaded.    Alfresco's default property values are provided in the repository.properties file which can then be overridden by files like alfresco-global.properties.   I remember documenting the precedence rules on the wiki although you can also follow the property loading in the bootstrap section of the spring context.   It gets slightly more complicated by modules and subsystems but its still simply loading property files in a specific order,

If in a freemarker template then your property needs to be in the model passed to the template.   Freemarker has commands for testing whether values exist and defaulting a value for example the ? and ! operators or <#if>

rjohnson
Star Contributor
Star Contributor
Basically its for the trashcan cleaner quartz job. What I wanted to happen was that is the cron expression was not set up in alfresco-global.properties it woukld default to a preset value which was provided via the context XML.

I have got it using the .properties just fine, I just wanted to be able to effectively say "if this property does not exist, use this string instead".