Tuesday, 11 March 2014

Adobe CQ/AEM - CQ dependencies POM

Here is an example of setting up the pom file for CQ dependencies:
http://dev.cqblueprints.com/nexus/content/repositories/releases/com/cqblueprints/cqdependencies/5.6.0/cqdependencies-5.6.0.pom

Obviously you wouldn't include everything in that file - just the ones needed for the project. I believe the order of dependencies matters too.

Wednesday, 5 March 2014

Adobe CQ/AEM - Logging configuration

Here is an example for adding a configuration to log CQ query information:

  1. Open http://localhost:4502/system/console/configMgr and scoll down to "Apache Sling Logging Logger Configuration" and click on it.
  2. In the dialog set the following
    • Log Level to 'Debug
    • Log File to 'logs/query.log'
    • Logger to 'org.apache.jackrabbit.core.query.QueryImpl'
  3. Click on save.
There should be a new entry created under Apache Sling Logging Logger Configuration

Tuesday, 25 February 2014

Adobe AEM/CQ overwriting built-in plugins for richtext editor

Example given here -
to overwrite the built-in link configuration dialog box by adding a field to set a link title:
http://forums.adobe.com/thread/1230814

Very important to compare the code given in the example for changes.

Overview:
  1. Setup in the apps director to create a "widgets" folder with these values
    • jcr:primaryType  = cq:ClientLibraryFolder
    • sling:resourceType = widgets/clientlib
    • categories = cq.wcm.edit
  2. Create a js file that overrides the built-in js plugin, note:
    • Initialize the name of the plugin
    • Register the name to the built-in xtype
    • Uses CQ.form instead of CUI.
  3. Create a js.txt and include the name of js file within



Friday, 21 February 2014

Adobe AEM/CQ seach results


Configure indexing for search:
http://helpx.adobe.com/experience-manager/kb/SearchIndexingConfig.html

Overview:
  1. Create a mapping with index to latest articles
  2. Components can retrieve articles via the mapping
  3. When new articles come in, update the mapping of index at the background
  4. Once the new mapping is complete, replace the mapping

Tuesday, 11 February 2014

Adobe CQ/AEM Query Builder - empty property

So at work, I was faced with a scenario where I have to use the CQ query builder to retrieve a bunch of articles that when they do not have a date property it will be selected along with the ones with date property that does not expire.

A little pseudo-code to show what I mean:

if (!article.hasDate) {
  return true;
} else {
  if (article.date >= now()) {
    return true;
  }
  return false;
}

Here are some articles I found online before I came up with a solution:



Finally, here is what I have in CQ query builder:

path=[path/to/articles]
type=cq:Page
99_property=@jcr:content/cq:template
99_property.value=[apps/path/to/template]
10_group.p.or=true
10_group.1_property=@jcr:content/offTime
10_group.1_property.operation=not
10_group.2_daterange.property=@jcr:content/offTime
10_group.2_daterange.lowerBound=[current-date-or-hardcode-date-for-testing]
10_group.2_daterange.lowerOperation=>=

This is now returning articles that does NOT have the offTime property; also it returns articles that DO have the offTime date and are current.

Wednesday, 5 February 2014

Adobe CQ/AEM package install behaviour - filter.xml

Encountered a problem that whenever a package is deploy / installed, it will overwrite existing content and folder structure that was setup.

Using the filter.xml under META-INF/vault, we can configure it in a way that it keep existing content intact.

http://www.wemblog.com/2012/04/how-to-change-package-install-behavior.html

There are three Modes available:

  1. replace: Normal behavior. Existing content is replaced completly by the imported content, i.e. is overridden or deleted accordingly.
  2. merge: Existing content is not modified, i.e. only new content is added and none is deleted or modified
  3. update: Existing content is only updated but never deleted



Add it under META-INF/vault/filter.xml
<?xml version="1.0" encoding="UTF-8"?>

<workspaceFilter version="1.0">
    <filter root="/content" mode="update"/>
</workspaceFilter>


Advance package filtering include / exclude regular expression

http://aemfaq.blogspot.com.au/2013/04/cq5-package-filter-includeexclude.html

Example META-INF/vault/filter.xml
<?xml version="1.0" encoding="UTF-8"?>

<workspaceFilter version="1.0">
    <filter root="/content" mode="update">
        <include pattern="/content/foo/bar/*"/>
        </filter>
</workspaceFilter>



Tuesday, 14 January 2014

Java - re-using test classes across different projects | modules | packages

Reference:
http://blog.frankel.ch/re-use-your-test-classes-across-different-projects

In the POM.xml of the project|module that you have your testing code in src/test/java, include this plugin:
<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The test artifact is stored side-by-side with the main artifact once deployed in the repository. Note that the configured test-jar is bound to the install goal. E.g:
[your project|module name]/src/main/
[your project|module name]/src/test/


In the other project|module POM.xml, include this dependency:
<dependency>
  <groupId>com.rookiegeek.foobar</groupId>
  <artifactId>foo-bar</artifactId>
  <version>1.0.0</version>
  <type>test-jar</type>
  <scope>test</scope>
</dependency>

The type has to be test-jar instead of simply jar in order to Maven to pick the attached artifact and not the main one. Also, note although you could configure the dependency with a classifier instead of a type, the current documentation warns about possible bugs and favor the type configuration.