Sling Context Aware Configuration AEM 6.5 Examples

OSGI configuration

We all know every OSGI service/ component configurations meta data in OSGI Console, Configuration section or we can deploy the as part of the code base. We can maintain these configurations based on the run modes by deploy as part of the code base and we can configure in Felix console.We need admin permissions to configure through Felix console. To change in Felix configurations in not best practice.
We can deploy configurations with runmodes, which is environment specific what if we want to configurations based on the content hierarchy?
To achieve this we can make use of Sling Context Aware Configuration

Sling Context Aware Configuration

What can we do with the sling context aware configuration? We can store the configurations based on the repository hierarchy

How to implement this?

 You just need to create a Java POJO class with “@Configuration” with required properties as variables. If add collection = true   Attribute, it will treat as collection.

You can configure these under the /conf with the content hierarchy and you need to add “sling:congRef“ property to page by pointing the configuration




How to read in Java class (Services)

To get the configuration

To get the collections (you should declare your configuration as collection as true)

How to read in HTL

In HTL component you access the configurations by using “caconfig”

${caconfig['subbu.blogspot.caconfig.core.slingcaconfig.SiteConfiguration'].stringArrayParam}

How it works?



How Inheritance will work


By adding the sling:configPropertyInherit as true to the configuration resource it will look into parent configurations for the not adding properties

By adding sling:configCollectionInherit  as true to the configuration resource it will look for the parent configurations


The result of this example is: C, A, B. It would by just C if the sling:configCollectionInherit is not set.
  

How to manage the configuration

A project form a wcm.io providing the editors and extensions to edit the configurations
Editor: Configuration Editor Template for AEM.
·       By using this you can edit the CA configs under the /content tree as page
·         Before creating the CA configs you need to define the sling:configRef. This can be done by proving the configuration in page properties
·         The configuration editor supports only editing configuration for which configuration metadata is present.
What to Install
·         Editor bundle – these are already provided in 6.5
·         Editor package (io.wcm:io.wcm.caconfig.editor.package) – you can deploy this along with your application as sub package
<subPackage>
                 <groupId>io.wcm</groupId>
                 <artifactId>io.wcm.caconfig.editor.package</artifactId>
                 <filter>true</filter>
                          </subPackage>
               
Extensions AEM applications: AEM-specific extensions for Sling Context-Aware Configuration.
What to install
·         Deploy the bundle io.wcm.caconfig.extensions along with your application to the AEM instance. As bundle
<embedded>
<groupId>io.wcm</groupId>
             <artifactId>
                    io.wcm.caconfig.extensions
              </artifactId>
              <target>/apps/ca-config-examples/install</target>
                 </embedded>

References



Sling Doc:



WCM IO Doc:
https://wcm.io/caconfig/index.html

AEM 6.4/ AEM 6.5 Clientlib specific Preprocessors minification

AEM 6.4/ AEM 6.5 Clientlib specific Preprocessors

AEM allows for pluggable preprocessors and ships with support for YUI Compressor for CSS and JavaScript and Google Closure Compiler (GCC) for JavaScript with YUI set as AEM's default preprocessor.

By default, AEM uses the YUI Compressor. Switching to GCC compressor for particular clientlibs may solve some issues observed when using YUI.

You can choose to configure the preprocessors configuration per client library or system-wide.
  • Add the multivalue properties cssProcessor and jsProcessor on the clientlibrary node
  • Or define the system default configuration via the HTML Library Manager OSGi configuration

A preprocessor configuration on the clientlib node takes precedence over the OSGI configuration.

cssProcessor: ["default:none", "min:yui"]
jsProcessor: ["default:none", "min:gcc;compilationLevel=advanced"]

Adobe Documentation link click here

CQ5 / AEM Tags are not resolving/ showing / null after upgrading to 6.4

AEM Tags are not resolving/ showing / null after upgrading to 6.4

While upgrading to AEM 6.4 you should upgrade tags as well. On AEM 6.4 onwards tags will store under /content/cq:tags whereas in the earlier versions they will store under /etc/tags.

Resolving the issue.
  1. you should move your tags under /etc/tags to /content/cq:tags and removed /etc/tags folder
  2. Via the AEM Web Console, restart the Day Communique 5 Tagging OSGi bundle at http://serveraddress:serverport/system/console/bundles/com.day.cq.cq-tagging for AEM to recognize the New Location contains content and should be used.