Saturday, 17 June 2017

Changing a .content.xml file locally is not reflecting in CRX after maven build

If .content.xml file is changed locally and changes are not reflecting in crx then check maven-resources-plugin.

Add below plugin in pom.xml of UI module.(aem-sample/aem-content-ui/pom.xml).

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-content-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/vault-work</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/content</directory>
                                    <filtering>true</filtering>
                                    <excludes>
                                        <exclude>**/.svn</exclude>
                                        <exclude>**/.vlt</exclude>
                                        <exclude>**/.vltignore</exclude>
                                        <exclude>**/.DS_Store</exclude>
                                        <exclude>/etc/designs/${project.parent.artifactId}/jcr:content(/.*)?</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

For maven-resources-plugin check that its copying your .content.xml to target folder and for content-package-maven-plugin check that correct filter values are set.
We can also verify by extracting the generated package and check if it has the changes or not or look at a vault-work directory in target and get to the directory in which you have changed the .content.xml, verify if it has changes. If your changes are there in vault-works then the maven-resources-plugin is working absolutely fine and the issue may be with the content-package-maven-plugin.

If bundle is not installed check this post.


Saturday, 10 June 2017

Remove duplicate user defined objects from an ArrayList

To remove duplicate user defined objects we need to override hashCode() and equals() methods and update the comparison logic accordingly.

I had a scenario where I had a list of objects, I need to remove duplicates from the list. I have overrided hashcode() and equals() method. When the duplicate object is encountered, the hashcode value will be same, then equals method is executed. If both objects are equal then it returns true and object will not be added to HashSet.

package com.kishore.samples;

import java.util.ArrayList;
import java.util.HashSet;

public class RemoveDuplicates {

    public static void main(String a[]) {

        ArrayList<Price> listOfBlogs = new ArrayList<>();
        listOfBlogs.add(new Price("aaa", 20));
        listOfBlogs.add(new Price("22", 40));
        listOfBlogs.add(new Price("333", 30));
        listOfBlogs.add(new Price("aaa", 200));

        HashSet<Price> set = new HashSet(listOfBlogs);
        for (Price pr : set) {
            System.out.println(pr);
        }

    }
}

class Price {

    private String item;
    private int price;

    public Price(String itm, int pr) {
        this.item = itm;
        this.price = pr;
    }

    public int hashCode() {
        System.out.println("In hashcode");
        int hashcode = 0;

        hashcode = item.hashCode();
        hashcode += item.hashCode();
        System.out.println("hash code value for " + item + " is " + hashcode);
        return hashcode;
    }

    public boolean equals(Object obj) {
        System.out.println("In equals");
        if (obj instanceof Price) {
            Price pp = (Price) obj;
            return (pp.item.equals(this.item));
        } else {
            return false;
        }
    }

    public String getItem() {
        return item;
    }

    public void setItem(String item) {
        this.item = item;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String toString() {
        return "item: " + item + "  price: " + price;
    }
}

Output:

In hashcode
hash code value for aaa is 192642
In hashcode
hash code value for 22 is 3200
In hashcode
hash code value for 333 is 101286
In hashcode
hash code value for aaa is 192642
In equals
item: aaa  price: 20
item: 22  price: 40
item: 333  price: 30

Adobe Analytics vs Google Analytics

Google Analytics and Adobe Analytics both are web analytics services used in the measurement, collection, analysis and reporting of web data for purposes of understanding and optimising web usage. However, Web analytics is not just a process for measuring web traffic, but can be used as a tool for business and market research, and to assess and improve the effectiveness of a website.



Read More

Friday, 2 June 2017

Sling Models in AEM

We used to develop back-end login to components either by using WCMUse or WCMUsePojo or even JSP. With the release of AEM 6.3 and AEM Core WCM Components, we see that using Sling Models have been advocated by Adobe as the best practice. Now let’s take a look how we can use Sling Models.


You can work with Sling Models when developing with Adobe Experience Manager (AEM). That is, when developing an AEM project, you can define a model object (a Java object) and map that object to Sling resources. For more information, see Sling Models.
A Sling Model is implemented as an OSGi bundle. A Java class located in the OSGi bundle is annotated with @Model and the adaptable class (for example, @Model(adaptables = Resource.class). The data members (Fields) use @Inject annotations. These data members map to node properties.

Saturday, 13 May 2017

AEM - Salesforce lightning component - Access-Control-Allow-Origin

When I try to access salesforce lightning components in AEM, I was not able to access the lightning script from AEM server, I got below error in browser console.

Issue:

XMLHttpRequest cannot load https://AAAAAA.lightning.force.com/lightning/lightning.out.js. 
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' 
header is present on the requested resource. Origin 'https://localhost:5544' is therefore not allowed access.

Solution:

We need to whitelist the origin i.e. our aem server in salesforce. 
  • Goto salesforce.com site, click on Setup -> search for CORS
  • Goto CORS console, give the AEM server url pattern, in my case it is https://localhost:5544



Tuesday, 2 May 2017

Create AEM porject structure using Lazybones

Lazybones is a command line tool to create AEM project structure. Adobe is recommending its customers to create AEM project structure using Lazybones instead of traditional Maven archetype 10. As when we create a aem project using Maven archetype it is not easy to customize, it provides lots of sample content and packages like test, launcher. Which might not be required for your project, on contrary lazybones bones is very interactive , flexible and easy to customize according to your project need. Adobe consulting Services (ACS) provides a aem multi module template using which you can create AEM projects, which includes lot of default config options and also provides an option to include the ACS commons package as a sub package.
The aim of this tutorial is to learn what is lazybones and how we can use it to create an aem skeleton project structure, as Adobe consulting Services (ACS) has updated the template version and provided the support for AEM 6.3 also i am going to create project structure for AEM 6.3, for learning i am using windows machine so we are going to install lazybones on windows, but you can install it on linux and other operating systems also.
Lazybones Overview:- Lazybones is a command line tool and is build in two parts. First lazybones command line tool and second project templates. This command line tool allows you to create a new project structure for any framework or library for which the tool has a template. Currently ACS has contributed one template for creating AEM multi module project, which we are going to use in this tutorial. You can also contribute templates by sending pull requests to this GitHub project or publishing the packages to the relevant Bintray repository.