Posts

Showing posts with the label AEM

Add a custom button in AEM DAM console and validate the asset Before Deleting

Image
Add a custom button in AEM DAM Console (Touch UI) Sling Merger is the best way to overlay and hide/add any buttons in components or even AEM consoles. If you would like to do any custom action on the assets, for ex: Validate the asset before deleting, you can follow the below process. Use Case Scenario: When we select the asset and click on the delete, there is no way of holding that activity, we can catch the events by using Event Listeners and do any activity post deletion, but if you would like to make any check's before deletion and stop deleting the asset, There are a couple of options for this requirement 1. Create a workflow and assign the workflow to the asset to do the activity 2. Add a custom button and call a servlet to do required actions, if you are satisifed the conditions in the servlet, you can delete it directly or you can hold the deletion and send emails or any other actions. You can even call a workflow from the servlet to do the activity if any ...

Delete DAM Asset using Workflow

This article shows you to create a simple workflow process step and use it for deleting an DAM Asset. You can ask me why do I need a workflow when I can delete it directly using the delete button :) The intention is to validate the asset information before deleting the asset or trigger any other workflow for the asset and do manipulations like updating the asset data to an user before the deletion as you will not be able to get that post deletion. you can catch the events in the Event Listeners, but there will be no data by then. Simple Workflow Process Step Create a workflow process step by using the below example package com.flash.aem.core.workflow; import java.util.HashMap; import java.util.Map; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import org.osgi....

Standalone scripts to execute in AEM

Few sample scripts which can be run from any IDE are available in the below GITHUB repository. ReadChildNodes CreatePage Github URL:  https://github.com/sudheerdvn/standalone-scripts Will try to add more scripts going on.

Groovy Console Integration and executing scripts in AEM

Image
Steps to install Groovy in AEM. Below Github have the steps to install the latest Groovy console https://github.com/icfnext/aem-groovy-console You can also navigate to the releases section and download the required package. https://github.com/icfnext/aem-groovy-console/releases I have used 12.0.0 version for this demo. Download the Groovy Package ( Direct link to the package  ) Upload the package to AEM via Package manager  http://localhost:4502/crx/packmgr/index.jsp Once the package is installed, you should be able to access the groovy console  http://localhost:4502/etc/groovyconsole.html Note: From 13.0.0 release, the paths were changed from /etc/ to /apps/ to access Groovy Console Sample Groovy Scripts: Printing a simple String println 'Hello World'; Click on Run Script Displays Hello World in the Console Get a Page Object final def page = getPage('/content/aem-flash') println 'page path is: ' + page.path; Re...

Helpful AEM Queries

Find out the nodes where the property exists and not empty. SELECT * FROM [nt:unstructured] as node WHERE ISDESCENDANTNODE(node, "/content/path-to-search") AND node.[propertyname] <> "" Search for all the nodes which are having a specific value SELECT * FROM [nt:unstructured] as node WHERE ISDESCENDANTNODE(node, "/content/path-to-search") AND node.[propertyName] = "property-value"

AEM - Few Important Information for debugging

Compiled Class path before AEM 6 is available in the crx console /var/classes/org/apache/jsp/apps/<<Project_Name>> Compiled Class path from AEM 6.1 is available in the installation directory of AEM /crx-quickstart/launchpad/felix/bundle305/data/classes/org/apache/sling/scripting/sightly/apps/<<Project_Name>> Extract log statements in b/w a specific time frame: awk '/^01.08.2018 00:07:23.002*/,/01.08.2018 00:09:09.345*/' error.log > /tmp/error_aug1_period.log Create a custom logger from crx/de  To configure a custom log file, perform these steps.  1. In CRXDE Lite, select /apps/logsample/config.author. 2. Create a node with below configurations:      Type - sling:OsgiConfig      Name - org.apache.sling.commons.log.LogManager.factory.config-logsample-model 3. Add the following properties to this node:       org.apache.sling.commons.log.file (String) - logs/logsample-model.l...

AEM - Sightly Elements

In the earlier blogs, we have seen when use data-sly-test using a div tag, div tag is also displayed in the html content. To avoid unnecessary wrappers around the actual HTML content, we can directly use the required HTML markup or use the sly element directly. For Example: <div data-sly-test.pageLinkReference="${properties.cq:pageLinkRef}">    <a href="${pageLinkReference}">${page.title}</a> </div> Output: (We can see the additional div tag around the anchor elements.     <div>            <a href="/content/sampleproject/fr.html">This text is populated from the component</a>     </div> To remove the additional div use the below example with sly elements     <sly data-sly-test.pageLinkReference="${properties.cq:pageLinkRef}">          <a href="${pageLinkReference}">${page.title}</a>     </sly> ...

Sightly

Sightly data-sly-test Use this tag for printing any tag if the value exists, if the value does not exists, the tag itself will not be displayed. This tag will also be used for assigning any values as below <div data-sly-test.pageLinkReference="${properties.cq:pageLinkRef}">    <a href="${pageLinkReference}">${page.title}</a> </div> data-sly-list Use this tag to print any list of objects Printing component properties in Sightly  ${properties.text} ${properties.linkTo} Note: In the above example: text and linkTo are the property names Sample to displaying using data-sly-test <div data-sly-test="${properties.linkTo}"> <a href="${properties.linkTo}.html">${properties.text}</a> </div> Sample to retrieve data from a regular service in AEM <div data-sly-test="${properties.linkTo}"> <a href="${linkComponent.link}.html" data-sly-use.linkComponent=...

AEM in Debug Mode

To start the AEM in debug mode, start the server with the below command java -jar aem-author-p4502.jar -debug 45024 -debug is used to start the server in the debug mode  40524 is the debug port Once the server is up and running, Configure the debug configurations in your IDE (Eclipse, etc..) For Eclipse: Click on Debug Configurations from the Debug Menu Create a new "Remote Java Application" Enter the details as below:            Name: sampleproject            Project: sampleproject.core            Host: localhost            Port: 45024 (Same port as the AEM instance has run on the debug mode) Apply the changes and Click on Debug Once the above configurations are completed, add a break point in any service/model/utility class. when we try to refresh the page where the respective service is being called, Debug mode will be ...

AEM projects using Maven archetypes

AEM projects can be created using the Maven archetypes Run the below command to create the project.  mvn  org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=12 -DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/ Archetype Version - 12 for AEM 6.3 or newer Archetype Version - 11 for AEM 6.2 or newer Provide the required information as below example: groupId:                             com.sudheer.aemgroup artifactId:                           sampleproject version:                              1.0-SNAPSHOT package:                           ...