Nested Property Name References
How can you refer to nested property name references, such as ‘${p:${p:domain}.url}. For example, if the ‘domain’ property has a value of SampleDomain, we want to call ${p:SampleDomain.url}. UCD does NOT have any standard support for nested property name references.
This article uses the following sample data…
- There are three domains, DOM1, DOM2 and DOM3.
- Each domain has a different URL, as defined by the properties DOM1.url=http://server123, DOM2.url=http://server345, DOM3.url=http://server678.
The target domain is a property named ‘domain’ which has one of the allowed values for any given deployment.
The process needs to access the appropriate Domain URL. The obvious solution is to use a nested property reference as ${p:${p:domain}.url}. But, this doesn’t work because UCD doesn’t support nested property name references.
However, UCD does support cascading property references. For example, if the property ‘a’ has a value of ‘${p:b}’ and the property ‘b’ has a value of ‘c’, then value of ‘${p:a}’ is ‘c’.
It is possible to use cascading property references to achieve the desired result. To do so, create an intermediate property which partially resolves the nested reference. In this case, call the new property ‘domain.url.ref’. It will contain values such as “${p:DOM1.url}” or “${p:DOM2.url}”. In other words, it will resolve the inner name reference. Then you can simply use ${p:domain.url.ref} to resolve the outer reference and get the desired value.
Let’s look at a detailed solution:
- Add a Groovy step.
- Name it “calculate domain.url.ref”
- The script is…
outProps.put( "domain.url.ref", '$' + '{p:' + '${p:domain}.url' + '}' )
- Subsequent steps can get the value by calling:
${p:calculate domain.url.ref/domain.url.ref}
Note that the Groovy step breaks up the outer property reference (${p:…}) into multiple string elements to make sure that UCD doesn’t try to process the outer property reference yet.