Update (April 30th, 2018): I changed the name of the configuration item to align with with future development. Next to this change I also added a few bugfixes in the git repo.
In the last 2 blog (1,2) posts I talked about why a more content-oriented and content-centric way to store configuration is useful. And I also described 2 scenarios in which CA-Config can actually be used. Now I want to demonstrate how Sling Context-Aware Configuration can actually be used.
Let’s take the example from last blog post: For the approval workflow we want to configure the approval group externally via Sling CA-Config, so it can be configured per subtree/page. I use AEM 6.3 here, but it should work with 6.2 as well.
In the next steps I will guide you through the steps required to implement these steps. For reference the complete project is available at https://github.com/joerghoh/cqdump/tree/master/ca-config-example.
- Create a structure in /conf where you would like to store your configuration. In my example the content lives in
/content/ca-config with the subites “en” and “fr”, and for /conf I choose
- Create a property “sling:configRef” with the value “/conf/ca-config/content” at
/content/ca-config/jcr:content/. This links your content to the configuration.
In the CA-Config lingua you created a configuration bucket at
/conf/ca-config/content, which is referenced by
And that’s it. Now every lookup through Sling CA-Config will lookup there.
Now let’s create some code which is using such a configuration. I created a DynamicParticipant WorkflowStep named “CaConfigParticipantStepChooser“, which assigns the workflow to a group defined by CA-Config. As you can see there a POJO class “CaConfigParticipantStepChooserConfig” is used to store the config read from CA-Config.
When you run this code, it will try to lookup the config property “approverGroup” (which is derived from the field name in CaConfigurationParticipantStepChooserConfig), but it returns the default value “admin”, as we haven’t provided any configuration value yet.
Now let’s assume that this workflow step, if it is executed on content below
/content/ca-config, should assign the workflow to the group “content-authors“. Create a folder “
/conf/ca-config/content/sling:configs” and add a node with the name “
de.joerghoh.cqdump.caconfig.workflow.CaConfigParticipantStepChooserConfig“; add the property “
approverGroup” and set it to the value “content-authors“.
To validate this setting there is a small tool in the OSGI webconsole.
- Goto localhost:4502/system/console/slingcaconfig (in the navigation it’s “Sling” => “Context-Aware Configuration”)
- enter “/content/ca-config” as content path
- Enter “de.joerghoh.cqdump.caconfig.workflow.CaConfigParticipantStepChooserConfig” as “Other config name”.
- And press “OK”.
It will display that that for this configuration name a property “approverGroup” with the value “content-authors” can be resolved. Which is exactly what we want.
When you test the workflow now, the workflow will be assigned correctly to the “content-authors” group.
To demonstrate the flexibility of context-aware configuration, let’s create a new folder
/conf/ca-config/content/fr/sling:configs, add a node “
de.joerghoh.cqdump.caconfig.workflow.CaConfigParticipantStepChooserConfig” and add a property “
approverGroup” with the value “contributors“. Additionally add the property”
sling:configRef” with the value “
/conf/ca-config/content/fr” to the
/content/ca-config/fr page. When you start the workflow now on
/content/ca-config/fr the workflow will be assigned to the contributors group. And of course this also works for every page below
(An important remark here: The paths are choosen arbitrarily. Especially in /conf you are very flexible, and the structure there does not necessarily need to match the structure below /content. I just choose the same structure for a better understanding of this example, and for convenience reason I recommend you to do the same.)
Congratulations, you are now able to use Sling Context-Aware Configuration! You can now freely package /content to move it to another stage, and the per-stage approver groups do not need to be re-adjusted.
But to be honest, this is a very simple way, and it has some drawbacks:
- You need to use CRXDE to maintain the properties in /conf.
- The need to create sling:configRef nodes for all buckets.
Let’s try to address these topics another time, in the next blog post.
You must be logged in to post a comment.