Showing posts with label Extension. Show all posts
Showing posts with label Extension. Show all posts

Friday, 13 May 2016

Understanding springmvcstore Extension Template

The springmvcstore template is a small, simple web shop application based on Spring MVC. Basically, springmvcstore is an implementation of the hybris Multichannel Suite Ordering Process. It allows logging in, browsing of products, and ordering. It does not use Commerce functionality, such as vouchers. Also note that this template only consists of a web extension module and, for example, does not contain an items.xmlfile. This extension also presents the concept of a web-container separated unit test for Controller logic as well as usage of Spring Security.

The springmvcstore extension uses:
  • The web extension module
  • Spring Web MVC frontend technology
  • Use cases
  • Logging in and out
  • Browsing products
  • Ordering
  • Testing controllers

The springmvcstore Extension Structure

The extension only consists of a web module. It provides the following directories:
  • web/src: Contains Facade, Controller, and DTO classes, as well as classes for converting a model to a DTO. It also contains some form classes.
  • web/testsrc: Contains classes for testing controllers.
  • web/webroot: Contains JSP files for views.
  • web/webroot/WEB-INF: Contains web.xml for servlet configuration and activating Spring Security, springmvcstore-web-spring.xml for configuration of Spring Security, springmvcstore-servlet.xml for configuration of dispatcher servlet and OS cache related configuration files.

Furthermore, the resources folder contains resource bundle files for formatting representation classification attributes
Dispatcher Servlet
The Spring Web MVC DispatcherServlet, acting as the front controller, receives all requests and dispatches them to the appropriate controllers. This servlet is configurable using the extension's web.xml file.
Spring Web MVC Beans
Spring Web MVC defines several beans whose use is shown in the springmvcstore template:
  • Controllers: Responsible for receiving requests from the DispatcherServlet and building the related model upon receiving data from business facades or user input and returning an appropriate literal for the view.
  • Handler Mappings: Responsible for mapping incoming web requests to handlers. Spring provides several handler mappings for common use cases, but new implementations can be defined by implementing the org.springframework.web.servlet.HandlerMapping interface.
  • View Resolvers: Responsible for mapping a view name to a view. Spring provides several view implementations for use. Thespringmvcstore template utilizes JSP for the view technology.
  • Locale Resolvers: Responsible for determining the Locale to use for a request. Spring provides several locale resolvers, including resolvers for inspecting the request accept header, cookie, and session.
  • Theme Resolvers: Responsible for determining the theme to use for a request.
  • Multipart File Resolvers: Responsible for handling file upload.
  • Exception Resolvers: Responsible for mapping exceptions to views and implementation of exception handling code.

Class Interaction Flow diagram

This conceptualized interaction flow shows how a request is made from the front-end:





















The central part of this process uses controllers which receive model and form objects from the Spring framework filled in by users or some initialization logic. The controllers decide which view literal they will switch to.

This interaction diagram shows a sample submit action:





































Classes or stereotypes of classes accept actions during the POST method being triggered from the front end. The Validator, Facade, Service, and Converter objects encompass the business logic of the process.
Several services from the hybris core are utilized in the Facade classes.


Thursday, 12 May 2016

Understanding Accelerator extension structure

Modulegen copies codes from Accelerator extension template to your custom extension folder. It is important to understand the significance of the accelerator structure as it will help in finding out the place where you need to make change for your personal customization,dependency between different extension and platform .It will further help in writing cleaner and modularized code which will assist in extending hybris platform services and easier hybris version update process in future.

Once you have completed the steps mentioned in Create/Publish store you will find out that modulegen has added 7 new extensions folder to C:\hybristest\hybris\bin\custom\training folder.

We will explore the structure and importance of new custom extensions :


1.)trainingcockpits  
This extension is where you will programmatically extend hybris cockpit business tools to customize existing features of a cockpit or add additional features. It extends the acceleratorcoreextension.All the  XML file based configuration that is added to any of the extension will be added to  acceleratorcore extension
2.)trainingcore
It is the business service layer extensions where the data model is extended, services from other hybris extensions are combined, added to and enriched and further services are added for project use. This extension come with a core and hybris Management Console (hMC) module. All core data vital for the provisioning of an accelerator storefront is loaded in the trainingcore extension as a part of essential and project data. You can alter these scripts and add further data scripts here.
3.)trainingfacades
This extensions organize and aggregate multiple business services to provide a storefront API that exposes actions and a data model that is optimized for a B2C commerce front-end use. It extends the functionality offered by the commercefacades extension and would be where a you would add all additional facades and customize the commercefacades extension functionality. It has a core module but no hybris Management Console (hMC) and web module.
4.)trainingfulfilmentprocess
Here you can extend and customize the fulfillment process that comes OOB with hybris. It contains order process and consignment process XMLs that define the order fulfillment and management process in Hybris
5.)traininginitialdata
It is used to add data for running and setting up  your storefront and application. It provides initial impex templates. From here acceleratorsampledata extension is coupled to this particular implementation. The acceleratorsampledata extension adds all the products and content necessary for each of the three sample storefronts as well as test promotions, users, advanced personalization rules and etc.. A project would not go live with acceleratorsampledata extension, it is provided purely as a sample. The data is separated into this extension to make it very easy to not include the sample data as a part of a project.
6.)trainingstorefront
This extensions contain the code for the front-end tiers that expose storefront functionality using web site. And do not have a core or the hybris Management Console (hMC) module.
7.trainingtest
Here you can put your JUnit testcases to test the functionality provided by your implementation. It Provides  tools, configuration and data for testing hybris Multichannel Accelerator.


Create/Publish new store(website) using hybris accelerator extension template

In Hybris yaccelerator is a default out-of-box store but we want to create our own  by using Hybris multi-channel suite.Follow the below steps for the same.

Step 1: Go to cmd and hybris bin plateform directory and run >ant modulegen











Step 2: Choose extension template as "accelerator" , name as "training" and package name as "com.training"














After performing all above step , Below seven extension gets

(1)  trainingcockpits
(2)  trainingcore
(3)  trainingfacades
(4)  trainingfulfilmentprocess
(5)  traininginitialdata
(6)  trainingstorefront
(7)  trainingtest








































Step 3: Now add all the 7 newly created extensions in localextensions.xml

Step 4: Run ant clean all

Step 5: Start hybris server using hybrisserver.bat

Step 6: Initialize extension from Hybris admin console


In case any CMSSite related issues is faced. Please initialise apparel/electronics(which ever you going to use) first from admin console.

Monday, 9 May 2016

Creating a web module in Hybris

A web module in hybris is referenced as extension. We have multiple templates in hybris which we can choose as base to create our new extension.

Step 1: Create a new extension using hybris extension command ant extgen. Select the template as yempty

give extension name as "extensiontest" and package as "com.test". Refer screens below











Step 2:Once step 1 is done, the below screen will be appeared with a message of build successful




















Step 4: Once build is done.Go to directory C:\hybristest\hybris\bin\custom and you will find folder with name of your extension.

















Step 5: Make entry of the new extension in localextensions.xml. Can be found at C:\hybristest\hybris\config\localextensions.xml

Step 6: Run ant clean all. Once build is successful add the new extension to your workspace using import.

Step 7: Start hybris server using hybrisserver.bat

Step 8: Open hybris admin console using admin and nimda as username and password(http://localhost:9001/) and under extensions tab you can see the newly created extension, which validates that the new extension is created successfully.

Here is the general structure of an extension we see in eclipse