Wednesday, March 21, 2018

Creating standard AEM project structure on latest Archetype

Objective:

Archetypes create a minimal AEM project setup which works as a starting point for any new AEM application. So when setting up codebase for your new project, DO NOT COPY it from your old codebase. Instead, the code base should be setup using latest archetype. Using archetype is very easy thing and it just need to run a single command. Even if you are migrating old code bases to new AEM version, start from creating a new code base based on recommended archetype (Refer table below) and then copy individual pieces of old code base to appropriate location as per new archetype structure. 

This article talks about maven archetypes. If you are looking for Lazybones, refer this link: https://helpx.adobe.com/experience-manager/using/aem_lazybones.html


Solution:

Based on your AEM version, choose the desired project archetype from the below table:

Archetype VersionAEM Version
76.0 or newer
86.0 or newer
96.0 or newer
106.0 or newer
116.2 or newer
126.3 or newer
136.4, 6.3 + SP2
146.4, 6.3 + SP2
156.4, 6.3 + SP2
166.4, 6.3 + SP2
176.4, 6.3 + SP2
186.5, 6.4, 6.3 + SP3
196.5, 6.4, 6.3 + SP3
206.5, 6.4, 6.3 + SP3


Follow these steps to generate standard project structure:
  1. Go to the project code folder
  2. Open command prompt
  3. Run the below command:
    mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=18 -DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/
    OR
    mvn archetype:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=20

    *Change the "DarchetypeVersion" parameter depending on AEM version. Refer table above.
  4. When prompt enter additional details about groupId, artifactId etc.


References:
1. https://helpx.adobe.com/experience-manager/using/maven_arch13.html
2. https://github.com/adobe/aem-project-archetype
3. https://github.com/adobe/aem-project-archetype/blob/master/VERSIONS.md

Tuesday, March 13, 2018

QueryBuilder - Useful Queries

AEM provides useful tool to run dynamic queries on repository.

QueryBuilder Link- http://localhost:4502/libs/cq/search/content/querydebug.html

1. Find List of all templates template


Set Extract facets true (Enable checkbox)

path=/content/mysite/mypath
type=cq:Page
property=jcr:content/sling:resourceType
property.operation=exists // Check that property exists
p.hits=selective // you want only selected properties as defined by p.properties
p.properties=sling:resourceType  // What properties you want in facets, multiples separated by space

2. Find list of pages of a particular template


path=/content/mysite/mypath
type=cq:Page
property=jcr:content/sling:resourceType
property.value=my-site/components/page/somepage
p.limit=-1 //All results
p.guessTotal=true // Makes search faster

3. Check asset types in a DAM path


Set Extract facets true (Enable checkbox)

path=/content/dam/myapp
type=dam:Asset
property=jcr:content/metadata/dam:Fileformat // OR use dc:format for better results
property.operation=exists
p.hits=selective by p.properties
p.properties=jcr:content/metadata/dam:Fileformat // OR use dc:format for better results

4. Find list of all components used in site


path=/content/my-site
type=nt:unstructured
property=sling:resourceType
property.operation=exists
p.hits=selective by p.properties
p.properties=sling:resourceType

Notes-

property.operation : “equals” for exact match (default), “unequals” for unequality comparison, “like” for using the jcr:like xpath function , “not” for no match , (value param will be ignored) or “exists” for existence match .(value can be true – property must exist)

5. Property Does not Exist


type=dam:Asset
path=/content/dam/my/project
1_property=jcr:content/metadata/dc:format
1_property.value=application/zip
2_property=jcr:content/metadata/custom
2_property.value=false
2_property.operation=exists
p.limit=-1

6. Find all nodes created after a particular time or with in a specified interval


path=/content/dam/my/project
type=dam:Asset
property=jcr:content/metadata/dc:format
property.value=application/zip
daterange.property=jcr:created
daterange.lowerBound=2019-03-04T00:00:00.000+05:30

You can use upperBound if you want less than "<" restraint on this query to find items with in a specified time period.

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...