Monday, July 28, 2014

Using Automated Tests for Sling Based Applications

Testing Sling based Applications:

Automated UI Testing

AEM Dev Tools for eclipse released TODAY

Just released today. The new AEM Dev Tools for Eclipse:

Need the stand-alone files if you work disconnnected?, you can get the contents here:

Use this link to learn how to use it:

The main features of this Eclipse plugin are:
  • Seamless integration with AEM instances through Eclipse Server Connector.
  • Synchronization for both content and OSGI bundles.
  • Debugging support with code hot-swaping capability.
  • Simple bootstrap of AEM projects via a specific Project Creation Wizard.
  • Easy JCR properties editing.
Here are a few screenshots of the plug-in in action. It's a great tool that will get you away from using CRXDE Lite and finally optimizes your development workflow. You will still need to configure your filter.xml to set what syncs to your server.

Configuring the server, publishing changes

Adding Nodes

Local changes automatically published

Setting Properties

Wednesday, July 23, 2014

Migrating Assets Approach

I'm working on a project that requires a significant asset migration from a legacy system. I've used this approach for a few different migrations from legacy systems, and it has not failed me yet. As much as I would like to use a connector or some other easy route out of a lot of code, I didn't have a choice because the legacy software was ancient or the customer didn't want to keep both systems up.

So, the approach was to:
  1. If this is a mass asset migration, turn off the workflow, "DAM Update Asset" and any other custom workflows that might interfere and cause noise.
  2. If you have a slave, turn it off to eliminate another variable. When you turn the slave on, it will sync.
  3. Ensure your aem instance is patched.
  4. Go into the legacy system, zip up each package of content with an associated metadata xml file
  5. Curl it over from the legacy system to AEM to a place under /content/dam/migrate/
  6. Excluded a directory from the DAM Update Asset workflow so it wouldn't create renditions of content I was about to migrate. (see my post about regular expressions)
  7. Create a workflow launcher that listens for zip files being created in that directory
  8. Execute a custom workflow model
    1. Created a custom workflow step that saves the path. This was needed because the payload gets destroyed in the next step.
    2. Executes the DAM unarchiver workflow to extract the contents, destroys the zip
    3. Execute a custom workflow step to process the data
      1. Use the path stored in step 1, use JAXB to read the data from the XML file
      2. Create the asset/page/etc... and add the custom data fields as needed
I've used other variations in my workflow model to DRM documents using the LiveCycle connector, executing other processes, and sending emails.

If you migrated a ton of assets, you can put the assets back into the "DAM Update Asset" workflow by using the script here:

AEM 6 Reference materials

AEM 6 Documentation

What's new in AEM 6?

Gems on Adobe Experience Manager - Many recorded in depth videos

AEM 6.0 and Admin Sessions

What is Sightly? (Preferred HTML templating system in AEM 6. No more JSP's!)

AEM 6 Hotfixes

RELEASED TODAY (July 28th, 2014) - The AEM Sightly Brackets Extension:

Thursday, July 17, 2014

Another way to get an OSGI Reference

The code below will return a ResourceResolver without using an annotation. This will significantly clean up your method signatures in many cases. The only caveat to using this approach is understanding how this command will execute (currently under admin), so if you need to perform an action under a particular user, you will need to pass in additional parameters depending on what you're trying to do.

import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;

private ResourceResolverFactory factory;

private ResourceResolver getResolver() throws LoginException {

//Get the Bundle's context
BundleContext context = FrameworkUtil.getBundle(this.getClass().getBundleContext();
//Set the service reference you want
ServiceReference ref = context.getServiceReference(ResourceResolverFactory.class.getName());
//Retrieve the Service
factory = (ResourceResolverFactory) context.getService(ref);
return factory.getAdministrativeResourceResolver(null);


Regular Expressions and Workflow Launcher Paths

An invaluable tool to configuring workflow launcher paths is regular expressions. The rules that are used to launch models uses regular expressions. I've been using to test and validate my launcher paths with great success. There are a few other sites out there, but this one has worked for me.

Friday, July 11, 2014

Applying Hotfixes to CQ 5.6.1

On most projects we just patch the environments individually and create a document which lets us know which ones have been installed, i.e not checking them into github/other SCM. You should be judicious in choosing which hotfixes you install. The following link shows in bold which ones are important and I would start with just those. If you're not using a feature such as twitter, social, and others, I wouldn't install.

For installing, one approach is to curl the hotfixes over with sleep statements between each statement. Be aware of hotfix 3285. For now, you need to downgrade com.adobe.granite.ui.commons-5.5.86.jar and use 5.5.77.CQ561-006.

Tuesday, July 8, 2014

Structuring Content for Faceted / QueryBuilder Searches

Tip #1 - Use the correct data types and ensure values are saved correctly. For example, if you have a date that is being saved as a string. Everything may seem fine right now, but as soon as you want to use QueryBuilder to find the content, it won't return the results you expect.

Tip #2 - Never, ever use custom data types. Use mix-ins. You've been warned.

Tip #3 - Test your content to make sure it is searchable by using the Query Builder Debugger. http://localhost:4502/libs/cq/search/content/querydebug.html

Tip #4 - Don't over complicate your data structure. For example, don't nest a bunch of nt:unstructured nodes so it makes it impossible to search the content.

Tip #5 - When you search, you typically want to sort by jcr:score. If you're not receiving the results you want, then you need to tweak the rules in your query. For example, if you want to do this at runtime, you could add, "^2" to the end of a query to property the value of a result.

QueryBuilder Predicate Operations


Not Exists



Unequals (Not equals)

Date Ranges

Skip Node Iterator Count in QueryBuilder (Save significant amount time if you have a custom authorization provider for nodes, but you don't get a count)