Showing posts with label AEM. Show all posts
Showing posts with label AEM. Show all posts

Saturday, 24 October 2015

Integrating Apache Wookie with AEM


Interactive websites - term making a lot of buzz over world wide web. 

But what are Interactive websites ?

Interactive websites are the ones which provides a number of different features to make interactive experience for users. One of the most important qualities of a website is interactivity. It allows users to interact with the website. With change of time web visitors expect to interact meaningfully with websites. 
There interactive aspects of a website often include : 
  • responsive forms
  • chat applications
  • games
  • or some sort of mini applications

Though creating any such feature is not a rocket science but it does comes with some development time associated with each feature. And creating such site in AEM would also cost time as there are no such features provided in AEM 'out of the box'. 

What if we have a central server where we can have such mini applications and use them directly in AEM ? 
Where users can select from a wide variety of interactive mini applications like chat-applications, geolocation sharing apps, a to-do list or a game and many such ready to use mini applications. 

Integrating Apache wookie with AEM allows users to drag & drop such interactive application. We have developed a connector tool for connecting AEM with apache wookie : AEM-WookieConnector 

Apache wookie is Java server application with allows you to upload & deploy widgets (mini web applications) for your applications. Using AEM-Wookie Connector tool AEM users can use simply drag n drop wookie widgets on their AEM pages and use from any where. 

Here are the steps to install AEM-WookieConnector Tool : 


  • Install Wookie as a standalone jar or as a WAR version from instructions given here
  • Next, Clone the AEM Wookie connector 
  • Build and Deploy :
       mvn clean install -PautoInstallPackage
  • Configure and provide the Wookie server URL and API Key













  • And Start Using !























  • AEM Wookie connector tool was presented as a solution to wider audience at a annually organized event AEMHub 

    Other useful links :



    Wednesday, 19 August 2015

    Creating custom Content Finder tab in AEM

    AEM provides a quick and easy way to find & use content while editing a page via Content Finder. Content Finder is a way to search different types of assets stored in AEM and make them available for drag N drop on the pages. 

    Creating a custom tab in Content finder makes it easier for user locate content or drag N dropable data. While creating a connector tool for AEM I came across this use case where I had to provide custom tab in the content finder to make data available for user while editing the page. 


    Creating custom tab is a 2 step process : 

    • Creating a back-end service for providing data.
    • Creating custom content finder step.

    1. Back-end service : It provides the data to the custom content finder tab to display. For this post I have created a text file with JSON data, in real world scenario it would be a service providing dynamic data.

    2. Creating custom content finder step : 

    • Create a folder with jcr:primaryType as sling:folder under /apps/wcm/extensions hierarchy with name contentfinder.
    • Set property extensionGroup as tabs on "contentfinderfolder.
    • Set property extensionType as "contentfinder_extension" on contentfinder folder.
    • Now create a JS file under contentfinder folder.  

    Above code creates a new content finder tab with name mentioned as tabTip property, setting the ranking as 1 makes this tab to appear on #1 position in the content finder, iconCls property sets the class on the tab and displays the icon on the tab. The most important part is creating a result box using CQ.wcm.ContentFinderTab.getResultsBoxConfig to display the result fetched from URL mentioned. 
    After creating a similar JS file there will be new tab added in the content finder as shown here :  


    Here is the link to github repository : 
    https://github.com/ankit-gubrani/Codebrains








    Wednesday, 1 July 2015

    Configuring AEM 6.0 with remote SOLR server

    Apache Jackrabbit Oak is the next generation repository implementation which powers in AEM 6.0. Oak does not index content by default to offer improved performance. Every JCR query will traverse whole repository, impacting the performance of the repository. Custom indexes need to be created to reduce node traversal with for every query in the repository.

    The SOLR index


    There are multiple options to index data in AEM, in this post we will be covering "The SOLR index".The Solr index in oak can be used for any type of JCR query. The integration in AEM 6.0 happens at repository level so Solr is one of the possible indexes that can be used in oak. 

    Here are the steps for configuring AEM 6.0 with remote SOLR server : 

    1. First extract the Solr zip prior to version 5.0 (I used solr 4.9.1) in folder named Solr .
    1. This solr folder should be parallel to crxfolder folder AEM installation directory, i.e inside Author directory.

    1. Copy the example folder and paste in the same directory (Solr), rename the folder as node1 (any name).

    1. Repeat step 3, just rename the folder as node2.

    1. Create a folder in node1 and node2 with name cfg. Inside this folder paste solr.xml, zoo.cfg and oak core config folder. (I used default core collection1 in my case)

    1. Now start the first solr shard with zookeeper configured. Run the following command from node1 directory :

    java -Xmx256m -Dbootstrap_confdir=./cfg/oak/conf
    -Dcollection.configName=myconf -DzkRun -DnumShards=2 -jar start.jar

    1. Now start the second shard by running the following command from node2 directory :
    java -Xmx256m -Djetty.port=7574 -DzkHost=temphost.ig.com:9983 -jar  start.jar
    Catch here is Solrcloudserver does not use the URL for initialization, rather it uses the connection string. Connnection string is same we pass with the zkHost parameter. In my case it was not working if I passed value as localhost:9983. I had to create a custom host name and the pass the same connection string while configuring with AEM.

    1. Once second shard is up and running, check if it both the shards are working or not by accessing the url :

    http://localhost:8983/solr/#/~cloud

    1. Now open the Configuration Manager console (localhost:3502/system/console/configMgr), and set the value of Oak Solr server provider as Remote Solr from drop down.

    1. Now edit Oak Solr remote server configuration and set the values as :

    Solr HTTP URL : http://localhost:8983/solr/
    ZooKeeper host : http://temphost.ig.com:9983
    Solr collection : collection1
    No. of collection shards : 2
    Replication factor : 1
    Solr configuration directory : /home/codebrains/CQ_Instance/Author/solr/node1/cfg/oak

    solrremoteconfig.png

    1. Now open the CRXDE Lite and create a node under oak:index with following properties :
    Name : solrindex (String)
    jcr:primaryType : oak:QueryIndexDefinition
    reindex : true (Boolean)
    async : async
    type : solr

    Thursday, 16 April 2015

    Polling Importer configuration in AEM 6.0

    AEM houses a powerful feature which allows user to poll after specified interval, as we discussed in our earlier blog Feed importer in Adobe CQ/AEM
    Its pretty straight forward to create a custom polling importer in AEM all one needs to do is create a polling configuration node with following properties on a nt:unstructured node : 










    While with AEM 5.6 it is fine to create such polling node any where in CRX, polling importer will work fine but with AEM 6.0 polling works only if polling configuration node is created either under /etc or /content hierarchy.

    I was stuck in similar problem when my project that was imported from AEM 5.6 to AEM 6.0. As we were creating the polling config nodes under /var hierarchy and it was not initiating the polling our service.

    AEM 6.0 allows users to configure path under which if polling configuration nodes can be created, polling importer work fine i.e. after configuring the Day CQ Polling importer service one can create polling node in the specified path and polling still works fine.




    Or one create a sling:OsgiConfig with name as PID of the Polling importer service and add the allowed path property. As follows :



    Thursday, 12 March 2015

    Requesting AEM Component via AJAX

    Why?
    In AEM pages are created in modular fashion and this modularity is achieved using components. But we often come across a situation where we want a specific component to be reloaded and not the complete page but mostly dispatcher is the main reason for loading a component via AJAX.

    As dispatcher caches component's output html due to which dynamicity of a component becomes questionable. For instance if we want a component to show unique results with each request. Loading component via AJAX is one way out for handling such scenarios.


    Sample AJAXified component

    How?
    To request a component via AJAX we will be using a Sling trick. In this trick we will request the URL to the component node then Sling resolution comes into the picture and it look for sling:resourceType property ,executes the script at given path & sends final HTML response.

    It is quite straight forward to implement this approach. We need to create a cq:component and the Javascript code for making a AJAX request.  As we would want our component to give unique response each time, we can either use a selector or query parameters and then give response accordingly.

    Code snippet below gives an example of how to request the desired component via ajax and show  the latest result.

    But for requesting a component's node we need to store the path on which we would be requesting, we will have to store that on our page itself in the page's DOM. Like shown below:

    Now we just need to read the path of the component node and request for component to reloaded via AJAX. Here is the sample jQuery method for how to achive this.

    I have created a demo component which is loaded on the page via AJAX. To use it one need to drop AJAX Demo Component inside parsys of AJAX Demo Warpper component and on press of reload button it reloads the component via AJAX.

    Here is the link for code repository for a sample component that is reloaded via AJAX : Requesting cq:components via AJAX

    Tuesday, 20 January 2015

    OSGI : Creating Factory configuration in CQ

    AEM houses a powerful open source framework in its technology stack, Apache Felix. Felix is a open source implementation of OSGi. OSGi provides a way to manage bundles and their configurations.

    OSGi provides a way to configure services and modify those configurations on the run-time. But apart from this there is a another powerful feature that OSGi provides that is : ability to create Factory Configurations. Factory Configurations is a way to create a single service, and bind multiple configurations to it  & then consume those configurations from different classes/Services. You all might have used Logger service provided by CQ out of the box, logger is an example of factory configuration service. 


    Factory Configuration















    Here are the steps for how to create factory configuration in CQ.

    Step 1:

    Create a Component/Service class to hold configurations values. This component will act a interface for adding properties of multiple configurations. Key for creating this Component/Service class is that declare this class as a configurationFactory and pass configuration policy as required.



    Step 2:

    Create a service to that actually uses the FactoryConfig Component/Service as a interface to allow user to add configuration and accept values of properties. For creating this service we will use dynamic binding of OSGi. We will have to create a collection of FactoryConfig class and binding & unbinding methods are also required that will add or remove each FactoryConfig object in/from the collections.


    Here is the link to code repository for this service : OSGi Factory Config

    Wednesday, 10 December 2014

    Default vaules with CQ5/AEM component

    Attimes we come across a situation while creating Components in CQ/AEM, where we want a default value of some property to be set the moment component is dropped. This can be done via JCR API but there is an easy way that I will cover in this post.

    Using cq:template node :



    cq:template node

    Simply create a node under component node with name "cq:template" of type "nt:unstructured". 


    Now add any property on this node you want to set as default value on the component. Not only properties you can even add node under this node if you want to create a default node under the component node.


    Component node hierarchy under /apps 

    And Its done. Now every time you drop this component on any page, default values will be created under the component node as shown below :

    Final node hierarchy under /content

    Here is link to code repository for this component : https://github.com/ankit-gubrani/Codebrains/commit/eea7cc35ae9c736e7ac4d39b398a37f9e5939b88

    Saturday, 15 November 2014

    Feed importer in Adobe CQ/AEM

    AEM comes with a pre-installed feature to import feeds into CQ. Feed importer comes with capability to import RSS and Atom feeds.

    Hey!! Wait before that you must be thinking, what is a feed?

    Web feed is a way to provide users with updated content. Web feeds are commonly used for news updates as news are the most frequently updating data.

    Feed importer is a service to fetch data from feeds or any external source of data on a periodic basis and save data fetched, in the form of CQ page.It polls the specified external data source in given interval.


    Here are the steps how to create feed importer in CQ :


    Firstly, create a page under which all the imported data will be saved in the form of CQ:Page. All the new pages that will be created under root page will have sling:resourceType property's value same as the root page.

    Now once root page is created, create Feed importer :

    Open http://<host>:<port>/etc/miscadmin and go to importers




    And Open the Feed Importer page, it will open a page as shown 
    below :



     Now click on the Add button and complete the dialog as shown below:



    Here is link for Atom feeds of Codebrians blog :

    http://codebrains.blogspot.com/feeds/posts/default

    The moment OK is clicked a Polling configuration node is created, that will poll given feed URL and fetches new data back to CQ then creates pages under given hierarchy.

    Here is the one of the auto-create page:























    Here is the Link to Github repository of Codebrains to refer the code : 
    https://github.com/ankit-gubrani/Codebrains

    Wednesday, 12 November 2014

    Populate dropdown in CQ5 dialog using Servlet

    Dropdowns in CQ5 are easy to create and use, all that needs to be done is create a node with name options and primaryType as cq:widgetcollections and sub-nodes with options.

    But problems comes in when the dropdowns with dynamic data or options is to be created. So, in this blog you will see how to address the problem of populating dropdown dynamically.

    Firstly, create a source from which data is to be fetched in our case we have registered a Servlet in OSGI at path "/bin/codebrains.json" which returns a JSON object as :

    {"root":[{"text":"CodeBrains_Text_0","value":"CodeBrains_Value_0"},{"text":"CodeBrains_Text_1","value":"CodeBrains_Value_1"},{"text":"CodeBrains_Text_2","value":"CodeBrains_Value_2"},{"text":"CodeBrains_Text_3","value":"CodeBrains_Value_3"},{"text":"CodeBrains_Text_4","value":"CodeBrains_Value_4"}]}

    Once your servlet is ready and it gives response in the desired format, now browse to Dropdown widget node and add properties that are shown below :









    Add following properties on the node :
    • xtype (Required) : selection
    • type : select
    • options (Optional but required if data is to be fetched from servlet) : <path-of-the-servlet> [Value of this property should be path of servlet which will serve the JSON data to be populated in the combo-box]. In our case its value should be "/bin/codebrains.json" as it the path at which servlet is registered in OSGI. 
    • optionsRoot  (Optional):  [Name of the property that contains options array. Use "." or dot-annotation to get till the property that contains options array. ] In our case its value should be "root" as root property of JSON object contains the Array.
    • optionsTextField (Optional): [Name of the field for the options text. This property is used if options object does not contains Text property which is read by default.
    • optionsValueField (Optional) : [Name of the field for the options value. This property is used if options object does not contains Value property which is read by default. ] (Optional)
    • allowBlank  (Optional) : [This property should have boolean value and is used to make any field mandatory. If set false that widget becomes mandatory cannot be set blank. ]





























    Here is the Link to Github repository of Codebrains to refer the code : 
    https://github.com/ankit-gubrani/Codebrains

    Wednesday, 22 October 2014

    AEM Multifield with different widgets

    Multifield widget in AEM was introduced to allow authors to enter any number of values they want and multifield serves its purpose pretty well. But multifield widget out of the box provides only textbox to take input from author. And at times we are in a situation where we want multifield with different widget for eg pathfield or a textarea or datefield. 

    In this article we will see how to create or use multifield with different widgets or Xtypes.


    Default Multifield widget

    Solution : 

    Creating a multifield with custom xtype or widget is a two step process. 

    Step 1 : Create a multifield widget i.e create a new widget with xtype multifield. But this will create multi-type with only text field for input as shown above. 

    FieldConfig node














    Step 2 : create another widget with name fieldConfig and add value of xtype property as whatever widget you want in multifield, in this example we have used pathField. 

     
    Multifield with pathfield as xtype Multifield with Datefield as xtype


    The values that are stored can be accessed the same ways we access in a values of default mutifield widget. 

    For reference, here is the Link for the demo Multi-field component : 

    https://github.com/ankit-gubrani/Codebrains/tree/master/content/src/main/content/jcr_root/apps/codebrains/components/content/multifieldDemo    

    Monday, 4 August 2014

    AEM Project Setup using Maven

    This article focuses on how to setup a AEM/CQ project using Maven and explaining the basic structure of AEM projects. 

    Lets start with a brief about APACHE MAVEN :

    Maven is a build automation tool that helps managing the builds of the projects and their dependencies (jar files required). It is based on the concept of POM (Project Object Model). There are numerous number of maven plugins available over the internet, each of which fulfills a different purpose.As we are here for AEM Project setup we won't cover anything more about maven here.

    Now let us see the folder structure of a AEM Project which you get to see in CRXDE Lite :
    • /apps : Top level folder whatever you code will be stored in this folder.
    • /apps/[YOUR-APP-FOLDER] : Root folder of one out of many projects that you will be creating under apps folder.
    • /apps/[YOUR-APP-FOLDER]/components : Folder that contains all the components and their respective JSPs.
    • /apps/[YOUR-APP-FOLDER]/templates : Folder that contains all the templates that you will be creating, which points to respective page component.
    • /apps/[YOUR-APP-FOLDER]/install : Folder that contains bundle of your project.
    • /apps/[YOUR-APP-FOLDER]/config : Folder that stored configuration specific to this project.
    • /etc/design//[APP-DESIGN-PAGE] : Design page of your application that stores all clientlibs (JS and CSS) and other static resources as well.
    • /content/dam/[YOUR-APP-DAM-FOLDER] : Folder that contains all the assets of your site.
    • /content/[YOUR-SITE] :  Location where site is stored .

    Before we move forward here are some pre-requisites that should be available on your machine (installed) for building AEM project using maven : 

    1. First and foremost would be Apache MAVEN .
    2. Adobe AEM/CQ running instance.
    3. Any IDE eg Eclipse , Idea, Netbeans etc(Here we are using Intellij Idea for this example)
    Link of source code for the demo project created https://github.com/ankit-gubrani/Codebrains

    Here are the steps to create AEM Project using maven :


    Step 1 : Create maven project using Adobe's multimodule-content-package-archetype. Using Command prompt go to the directory where you want to create project and run following command :

    mvn archetype:generate -DarchetypeRepository=http://repo.adobe.com/nexus/content/groups/public/ -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.2

    after this maven will prompt and ask for some information(like groupid, arifactid,version etc), provide that infomation and your project will be created.This will create a multimodule maven project with 2 modules (Bundle and Content)

    Step 2 : Verify the code if it works fine or not. You can check it by running command :

    mvn clean install 

    if it completes without any error that means project was made successfully.

    Step 3 : Import the project in any IDE . Here in the example I am using IntelliJ Idea : 


    Step 4 : Now that everything is set in place , import the project in CQ running instance by running command : 

    mvn clean install -PautoInstallPackage 

    but if you are running CQ on different port or if username and passowrd is changed used following cmmand :

    mvn clean install -PautoInstallPackage -Dcrx.port=3502 -Dcrx.username=newuser -Dcrx.password=newpassword

    This will install the project in CQ instance and you can see following folder structure iunder your project : 




      
    And this is it we are done with creating a AEM project using maven build tool. 

    Using this you will create a two module maven project. Those modules are :

    1. Content Module : This module contains all the code that will pe under apps/[YOUR-APP-PROJECT] or /etc/[DESIGN-PAGE] or /content/[ANY-PAGE] folder.
    2. Bundle Module : This module contains all the java files that will be wrapped up into a bundle and will be installed into Feilx.



    Here is the source code for the demo project created https://github.com/ankit-gubrani/Codebrains


    Your comments and suggestions are welcome.