Posts

Embed Third party dependency using bnd-maven-plugin

Image
This post explains the use of bnd-maven-plugin to embed third party dependency  Two main instructions of bnd-maven-plugin that serves the purpose are detailed below.  -conditionalpackage  pick packages from respective library and copy them in the bundle. Any dependencies of those copied packages will also be copied if they match the selectors. This means we need to explicitly list all the Java package names of desired dependency as part of this instruction (including its transitive dependencies) More about conditionalpackage instruction from official docs -  https://bnd.bndtools.org/instructions/conditionalpackage.html -includeresource  For including resource inline -includeresource: @artifactId-version.jar!/* For embedding as a jar with an entry in bundle class path -includeresource: artifactId-version.jar;lib:=true For several other possible combinations for including the resource, please check - https://bnd.bndtools.org/instructions/includeresource.html With complete understandin

Set OSGi Component properties dynamically using OCD - Use case with Sling ResourceChangeListener

Image
This post demonstrates the use of Object Class Definition(OCD) in setting the OSGi component properties. In general, per OSGi R6 annotations and above, we can set OSGi component properties via property attribute of @Component annotation (Static values) or Dynamically using @ ObjectClassDefinition together with  @ AttributeDefinition     (property amends in run time via Config Admin or /system/console/configMgr ) AttributeDefinition should be framed such that it evaluates to the property name correctly (underscores are converted to dots/period) Association of OCD with OSGi component happens via annotation named @Designate Example : Component properties like service.ranking  and in case of specific implementations like say WorkflowProcess , we set property named process.label  and for EventHandler, it is  EventConstants.EVENT_TOPIC  and examples add on in a similar fashion for any OSGi Component for that matter.   In order to illustrate this, I would like to consider Sling ResourceChang

Prioritize Search Results based on Boost in Lucene Index

Image
This short post explains the use of boost property in Index definition to prioritize the search results.  In Lucene Index, we have a property named boost   of type Double   which will help assign weightage to desired properties (that are part of fulltext/contains query) Properties with high boost value will be displayed earlier in the search results. Recently we had a query in the Community related to this subject to prioritize search term in URL to be first in the search results than the one found in properties like title/description.  In AEM, URL/path to the resource is simply the node names.  Node names are declared as property within the indexRules using special case identifier as   :nodename   and  is already available OOTB in cqPageLucene(/oak:index/cqPageLucene) Prerequisite for fulltext/contains query : We should make sure that we have two other properties named nodeScopeIndex and analyzed set to true (Both are of type "Boolean")  For Prioritizing : Set boost with hi

Embedding Third party dependency/OSGi bundle in AEM application hosted in AEMasCS

Image
This post illustrate the ways of embedding third party dependency in AEM maven project. Steps are mentioned considering the project structure to be followed for AEMasCS while the same can be followed for classic versions too.  Before we begin, I would like to explain the scenario of including a dependency in our AEM maven project.  When we would like to make use of an API that is not already available in our project, we look for that in maven-central repository and specify the dependency in main pom.xml and desired module's pom.xml file. (Lets say, AWS S3 Java SDK V2 dependency) Upon updating the project in the IDE, we would see our class files (making use of those APIs) are compiled/build successfully without any errors.  Now, in the context of AEM/OSGi environment, when the same package and hence the bundle is deployed to AEM instance, dependencies that we added new might not be resolved/available in the OSGi as a bundle. Something like the below This indicates that the added dep

Index on Functions | Coalesce function in JCR-SQL2

Image
 This post illustrates the index definition for function with sample use case using function named Coalesce in JCR-SQL2 query.  Recently, we had a query in forum related to Sorting columns/properties with different names - https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-sort-query-results-by-combining-multiple-fields-as-single/td-p/419215 ie. To sort based on language where the language value is stored against a different property name in each component say, lang/language/compLanguage. Sorting needs to be based on the consolidated values of each of these fields.  I came across this blog which explains the similar scenario and the solution is to use Coalesce function in JCR-SQL2 query.  I reproduced the same (as illustrated in the blog above) in my local and it works fine. I haven't tried index definition for Functions before and hence decided to use this example. Note : I suggest to read through the forum query and the blog before proceeding furth

AEMasCS REST API calls from POSTMAN or any external application

Image
This post details the steps to invoke REST API hosted in AEM as a Cloud Service (AEMasCS) instance from POSTMAN or any external application.  As we all know AEM is REST based Web application and contents of Repository can be accessed via GET call to respective path (Eg say,  ".json" extension or content path with ".html" extension) and  updates to Repository is possible via respective HTTP method type + API endpoint as exposed (Eg. Assets HTTP API Create Folder POST request) ,  provided we have Authentication and Authorization to the accessing endpoints.  Authentication is achieved using the credentials that we use to access our instance. Eg. In our local AEM author instance, we login using admin/admin or any username as created/available in the respective instance Authorization refers to the permissions to the path we are accessing  Eg: If we are to make GET request on /content/we-retail.html , we need to have read permission on this path. Given this understa

AWS Service in AEM

Image
 This post details the steps to make use of AWS service in web application developed using AEM. For incorporating any third party services/APIs in AEM, we have two direct possible routes - Via  Java SDK (as available in Maven Central) and via  Javascript SDK . Choice between the two depends on the availability, functional requirement and existing project set up.  With respect to AWS services, we have both SDK available and in this post, I am using AWS JAVA SDK V2.  Note  : The intention of this post is to demonstrate the ways to make use of AWS service in AEM projects and not to illustrate about the AWS service itself.  Prerequisites: AWS IAM user with Programmatic access type and with permissions to desired service set via Groups in IAM Access Key and Secret key pertaining to the user as created above. Reference :   https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html Approach: Include SDK in code base. Set up the acquired Security credentials (Access key and Secr