Sunday, November 24, 2013

Hybris commerce suite - Insight

Recently started exploring Hybris commerce suite 5.0.4 and have some of the interesting facts to share. So let’s start with basics.

What is [y] Hybris ?
Hybris is one of the upcoming agile and comprehensive commerce suite. Hybris platform is simple and based on open standards like Spring, ZK, SOLR/Lucene, ANT, Groovy, Apache Commons. The hybris commerce suite is engineered for expansion, extension and scale.

How’s the [y] Hybris architecture ?
From business standpoint the hybris Commerce Suite is divided into individual packages, such as Commerce, Content, Channel and Orders. These packages are bundles of functionality assembled for a certain range of business functionality.

From a technical point of view, packages consist of individual modules (aka extensions).
Extensions written by hybris provide standardized functionality and are supported and maintained by hybris.


hybris Commerce Suite is run in a Java Virtual Machine on a Servlet Container or a J2EE-compliant application server (such as IBM Websphere or Oracle WebLogic) and connects to an external database (MySQL, Oracle DB, Microsoft SQL Server). Internal caching and persistence mechanisms allow the hybris Commerce Suite to run on a Servlet Container. A full-fledged J2EE-compliant application server can be used, but is not necessary.


















What are the key Hybris commerce capabilities and features which comes out of the box  ?

General Storefront Capabilities - Language selection , Country selection , Currency selection , SEO frienddly URLs
Product Search - Solr-based product search with Keyword Search , Keyword Autocomplete , Spelling suggestions , Faceted browsing and more
Merchandising
Personalization and Promotion
Catalog Navigation
Product Display
Cart
Checkout
Hosted Payment
Customer Account
Store Location
Content Management
Data Import / Export
Google Local / Google Shopping
Content Pages and Templates
Organization Management
Jirafe Customer Intelligence
Google Analytics
Quote Negotiation
Order Approval
Order Management (OMS)
Store Locator
Device Detection

Lets dig deeper into some of the other concepts which is essential to know –

Hybris Cockpit framework –
The hybris Cockpit framework offers a large number of highly configurable components which can be used to build a new cockpit for your customers needs, such as for example workflow and comments.

The hybris Cockpit framework is the foundation for all hybris Cockpits. It offers a large number of highly configurable components, which can be used to build a Graphical User Interface (GUI) to support high-level business use cases, allowing users to perform all their common tasks quickly and intuitively. The hybris Cockpit framework complements the functionality offered by the hMC, which provides lower-level control over all the data in the hybris system.

The hybris Cockpit framework is based on ZK, a rich internet application (RIA) framework that enables desktop-like GUIs within a web browser. The ZK Framework is also well supported by Spring. ZK delivers a rich set of user interface (UI) components, making it easy and quick for developers to deliver a rich front end experience.

The major features of the hybris Cockpit framework include:
  • Security infrastructure based on Spring security
  • Ready to use front end template
  • Base configuration as a starting point for new applications, based on Spring
  • Reusable front end components in addition to existing ZK components
  • Generic abstraction of persisted items in the front end layer via the Type Service
  • GenericSearch providers
  • Highly customizable front end
  • Automatically stored user interface configuration at application run time
  • Drag and drop functionality
Here’s the key Hybris cockpits listed with brief description -

Hybris Administration Console -  The hybris Administration Console is an administration Web page provided by the hac extension. It provides functionality for administration, monitoring, and configuration of the hybris Commerce Suite.
Hybris Management Console (hMC) - hMC is the administration tool of the hybris Commerce Suite. As part of the hybris Commerce Suite, it runs in web browsers. Using the hMC, you can manage business objects of the hybris Commerce Suite such as products, customer data, orders.

Product Cockpit - The hybris Product Cockpit enables organizations to manage and structure product information and catalogs in high-volume and collaborative environments. Product managers can visualize their input from multiple perspectives and make product management processes more efficient

WCMS Cockpit - The hybris WCMS Cockpit enables you to manage data of a website. For efficient management of information on your online shop, you can use both the catalog perspective and live edit perspective. Each of them provides you with different ways of data management.
In the hybris WCMS Cockpit you can easily do the following:
·         Create and update website pages and content components
·         Check and change website pages status
·         Synchronize catalog versions of your website
·         Create collections of chosen pages
·         Search for website pages, according to advanced criteria

Admin Cockpit - At present, the hybris Administration Cockpit is used for the manipulation of: Data Validation constraints and Instances of types

Customer service Cockpit - The hybris Customer Service Cockpit enables you to quickly and efficiently manage the customer and orders in the call-center environment. 

Report Cockpit - The hybris Reporting Module adds Report Cockpit in which users can create and manage personal Dashboard containing rich graphical report widgets.

Print Cockpit - The hybris Print Cockpit enables you to create the publication structure and to manage the publication data for in an intuitive and user-friendly way. Linked with Adobe InDesign, it is a unique and powerful application.

Lets take closer look at some technical bits –

Adding a new page in Hybris –
  • Create a new page using the cmscockpit and with the available templates(we can also create new templates using the hmc as per the requirement).
  • Add components to the content slots available
  • Create a controller to handle the user requests for the newly created page.
  • Get the request mapping from the request, perform the business logic and return the model and view

Adding a new component in Hybris –
  • Create own item in items.xml file as below
            jaloclass="de.hybris.platform.endeca.jalo.cms2.components.OurComponent">
           //necessary attributes go here.....
  •  Create a new controller OurComponentController.java
      Note: The name of controller is important and should be created as follows: Component Type +"Controller" (in       our case OurComponentController). Beside that we also have to create a representation of our component           ourComponent.jsp

      All the controllers  are defined the way we define beans in Spring MVC in the spring-servlet.xml file as                 mentioned below
  •  Perform the business logic and return the model and view.


Creating new extensions --
The hybris Commerce Suite comes with an extension generator system called extgen located in the ${HYBRIS_BIN_DIR}/platform/extgen/ directory. Using extgen, you can create new extensions based on extension templates.

The hybris Commerce Suite comes with the following extensions, which you can use as a template for new extensions:

yempty
ycockpit
yaddon
ybackoffice
yacceleratorstorefront
yacceleratortest
ycommercewebservices
yinstoreinitialdata
yacceleratorcore
yacceleratorfacades
yacceleratorinitialdata

Extgen prompts you to specify:
  • The extension's name.
  • The extension's Java package.
  • The extension template to use.
After you have provided the prompted values, extgen does the following:
  1. Copying the extension template to a temporary directory.
  2. Modifying the extension template to reflect the specified values.
  3. Copying the new extension from the temporary directory to the directory specified by  the extgen.extension.path property in the project.properties file.
To create a new extension we follow following steps -
  1. Optionally: Modify default values for the extension generation process.
  2. Create a new extension.
  3. Reference the new extension in localextensions.xml file.
  4. Rebuild the hybris Commerce Suite.
  5. Update the hybris Commerce Suite.
Afterwords, you can start implementing your business logic in the new extension.

How to get started with Hybris ?
Best to register at https://wiki.hybris.com and get started. As of now they only allow certain partner companies to register so please check with your organization.
Once you registered at their wiki then you can access the product documentation.

I would highly recommend doing the Hybris core and commerce Trails. They are logically sequenced and it helps to understand overall product features and capabilities. Make sure you are good with Spring framework fundamentals , Annotations and ant commands.



Final thoughts ... No deny that Hybris has put great efforts to bring a light weight agile commerce framework which seems very promising. Best part is it cuts lot of development time to build some of the common features in a commerce site in no time, Their modular approach and open stack also gives you enough choice to pick and chose as per your need. It will be interesting to see how their future releases fair. I am yet to see how it scales and perform in a high volume and high transaction environments.

Sunday, November 10, 2013

Emerging languages series - Groovy

Our favorite Java is getting some serious competition in recent years , It seems there are more than 200 languages that target Java platform.
There is growing interest in languages like Scala, Groovy , Clojure , JRuby, Jython for their features and simplicity. Out of this lot we will take a close look at Groovy today as its getting wide attention in the market over recent years.

Why Groovy ?
  • Groovy is more or less a superset of Java
  • Builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk
  • Could seamlessly switch back and forth between Java and Groovy 
  • Considered simpler and easier to learn over Jython and JRuby
  • Groovy has Java-like syntax and hence the learning curve is not steep.
  • Simplifies testing by supporting unit testing and mocking out-of-the-box

Once you install Groovy, you could straightaway start programming in Groovy,  just put your Groovy jar file along with your application and get the program working in any machine.
There are many online editors and IDE plugin available to compile and run your Groovy code.

So what is Groovy ?
James Strachan conceived the idea of Groovy language and started development in 2003.
Groovy is a dynamic language that dynamically compiles the code to the Java platform. It is popular as a scripting language and also widely used for unit testing Java code. Groovy is open source (Apache v2 license) and is backed by VMware.
The current stable release is Groovy 2.2. You can use Groovy in most common operating systems like Linux, Windows, and Mac. 

Let’s see how Groovy looks better Java with few examples –

Hello World Example –

// Java
class HelloWorld {
public static void main(String []args) {
System.out.println("Hello world");
}
}

// Groovy
println("hello world")


More Detailed Examples –

Let’s take a look at collection (map) processing example. Lets create a map and do some processing in both Java and Groovy.

// Java
Map worldCapitals = new HashMap<>();
worldCapitals.put("England", "London");
worldCapitals.put("Japan", "Tokyo");
worldCapitals.put("France", "Paris");
worldCapitals.put("Italy", "Rome");
worldCapitals.put("USA", "Washington");
for(Map.Entry capital : worldCapitals.entrySet()) {                       
System.out.printf("%s => %s \n", capital.getKey(), capital.getValue());
}

// Groovy
def worldCapitals =   [ "England" : "London",
"Japan" : "Tokyo", 
"France" : "Paris",
"Italy" : "Rome",
"USA" : "Washington" ]
worldCapitals.each {
key, value ->  
println "$key = $value" 
}

In this case Groovy provides a simple array-like syntax for the Map data structure. See how use of each() method closure makes it simple to write the code.

We all know how we write custom code to sort a map by value in Java but the same can be achieved in a line with Groovy. See below -

def sortedMap = worldCapitals.sort { it.value }
sortedMap.each {
key, value ->  
println "$key => $value" 
}

In above Groovy code, we just passed the it.value (current iterator’s value) to the sort method. With the power of closures, the code became much simple and readable.
Groovy provides a higher-level abstraction to this functionality, and hence the code is much simpler.

Tip - The soon to be released Java 8 has also introduced concept of closures in form of  "lambda expressions". It will be interesting to see how Java is incorporating these new age language features in their new release. I will write separate post to cover Java 8 features and capabilities soon.

XML Generation Example -
In general it’s very common to generate structured output like HTML , XML or JSON in Java code. So let’s see one example around this piece.

// java
PrintWriter pw = new PrintWriter(new FileWriter("/capitals.xml"))
pw.println("");
for(Map.Entry capital : worldCapitals.entrySet()) {                  
pw.printf("\t \n \t\t '%s' \n \t \n", capital.getKey(), capital.getValue());
}
pw.println("
");


// Groovy
def capitals =   [ "England" : "London",
"Japan" : "Tokyo", 
"France" : "Paris",
"Italy" : "Rome",
"USA" : "Washington" ]

xmlbuilder = new groovy.xml.MarkupBuilder()
xmlbuilder.worldcapitals {
capitals.each {
key, value ->
country(name:key) { capital(value) }
}
}

Now just see how simple it is to do the same thing with Groovy with lot of readability. Groovy supports builders (based on Builder design pattern) for creating HTML and XML files.

Take away from this comparison -
  • Traversing a data structure is easy in Groovy - you can use “closures” instead of plain loops and use each() method. 
  • Groovy is high on meta-programming and regular expression handling capabilities.
  • Groovy builders are fabulous if you dealing with HTML , XML , JSON etc.
  • Better for productivity and code readability for sure
  • Being a dynamic language Groovy is an excellent candidate for creating DSLs (Domain Specific Languages)

We have just tried to explore few basic features of Groovy here. You should explore further programming improvements such as automatic check for nulls, helper methods, embedded expressions in strings, and operator overloading. One should also explore its meta-programming and regular expression handling capabilities.
You’ll find Grails web framework and Groovy Server Pages (GSP) interesting if you are a serious web-developer. If you are an admin, you may find Gradle build automation framework useful. Grails framework (that is similar to Ruby on Rails) is built on top of powerful and popular frameworks such as Spring and Hibernate.
Resources to learn further –
Programming Groovy 2 - Dynamic Productivity for the Java Developer, By Venkat Subramaniam
Groovy in Action, By Dierk Koenig, Andrew Glover, Paul King, Guillaume Laforge, Jon Skeet

If you are a developer, tester or script guru, you have to love Groovy. So keep grooving and have fun with it !!

Popular Posts