Sunday 29 May 2016

Creating Custom Backoffice Extenstion..

Custom Backoffice Extenstion:-

You can create custom backoffice extenstion by using “ybackoffice” Template.This backoffice webapplication contains new modules,widgets and UI components.By using custom backoffice extenstion you can create your own implementation and your own components.

Creating a new backoffice extension:-

  •     Create the extension with "ant extgen" for that Open the cmd and go to the platform directory of your hybris folder and execute command setantenv.bat after that execute ant extgen then it will shows like
extgen:
    [input]
    [input] Please choose a template for generation.
    [input] Press [Enter] to use the default value ([yempty], yscala, ygroovy, yatddtests, yacceleratorfulfilmentprocess,ychinaacceleratorstorefront, yaddon, ycommercewebservices, ycommercewebservicestest, ycommercewebserviceshmc, ycockpit, ybackoffice)
  •     Choose the ybackoffice template Then it will ask for the name of the extension
  [input]
  [input] Please choose the name of your extension. It has to start with a letter followed by letters and/or numbers.
  [input] Press [Enter] to use the default value [training]
  •    Type the extenstionname in cmd. Ex:-custombackoffice
[input]
 [input] Please choose the package name of your extension. It has to fulfill java package name convention.
 [input] Press [Enter] to use the default value [org.training]
  •    Type the package name ex:-org.demohybris  press enter then it will ask 
[input] Create a sample widget?
 [input] ([true], false)
Eg;true
[input] Create sample style sheets? ([false], true)
Eg:true
  •    You can also leave the values to their defaults sample widget and sample style sheet.
  •    Add new extensions into config/localextensions.xml file.
 Ex: <extension dir="${HYBRIS_BIN_DIR}/custom/customcockpit"/>
  •    Perform complete build of the platform  using "Ant all" command in cmd.  

 Import the extension project into the IDE

  •     In Eclipse Right-click in package explorer and select Import
  •     Select General|Existing Projects into Workspace and browse to the new extension YOURPATH/bin/custom/extensionname
  •     Remember to ensure that the Copy projects into workspace check box is not checked before clicking on the Finish button
  •     You should now see the extension in your Eclipse Package Explorer



Saturday 28 May 2016

Hybris BackOffice Tools...

 Hybris BackOffice Tools


Hmc:- 

Hmc stands for Hybris Management Console. Easy to configure and customize via XML configuration.HMC tool for technical business users, developers and Administrators,By Using HMC Manage Product,Order,Customer data and business processes. Manage users and access rights.

Cockpits:-

Product Cockpit –

The hybris Product Cockpit Module enables cockpit end users to manage and structure product information and catalogs in high-volume and collaborative environments. Product and category administration

 

WCMS Cockpit –

The WCMS Cockpit Module supports regular websites.WCMS Cockpit provides a multi-channel publishing system that allows you to easily maintain websites.It provides an intuitive, graphical user interface for data presentation and management.

Admin Cockpit – 

The hybris Administration Cockpit is used for the manipulation of Data Validation constraints,Instances of types and manage B2B data.The aim of the hybris Administration Cockpit is to provide functionality similar to the hybris Management Console (hMC), but in a more intuitive and user-friendly fashion, as it is expected from the numerous hybris cockpits.


Customer Service Cockpit -

Customer Service module provides the dedicated solution for the call-center environment. It means by using this Cockpit to perform Call center activities.


Print Cockpit – 

Print Cockpit is use to manage printed catalogs. The Print Cockpit Module adds the desktop publishing functionality to the hybris Platform. It enables you to produce sales catalogs, leaflets, and other printed material.

Import Cockpit –

It reduces the complexity of importing data by allowing you to define import mappings using intuitive graphical user interface tool.By using this cockpit Keep your content accurate by importing the most current product. Aggregate all product information scattered across various systems and departments.Support the long-tail approach by enabling easy supplier on-boarding.information from your suppliers and business partners.

Report Cockpit –.

The hybris Reporting Module provides a cockpit in which users are able to configure and display graphical statistics and reports in one central location. The reports are shown using widgets technology. Report Cockpit access to operational reports

 

BackOffice CockpitNG:-



Next Generation Cockpit Framework (Cockpit NG) is highly extensible and Configurable(XML).Present there are Several areas  BackOffice CockpitNG Modules available they are Commerce Search,Backoffice admin area,OMS Cockpit & Admin.The CokpitNG is a Single User Interface for all Backend Business Tools easy to use and role based interface for all business and administrative users.Application mashup can be designed at runtime using the Application Orchestrator interface or XML configuration. BackOffice CockpitNG will replace hmc in the Future. The “ybackoffice” extension template is used to generate a custom extension within which you implement your own components.

Tuesday 24 May 2016

overview on Converters and Populators...!!!


Converters and Populators:
Converter:
If I want to convert my Model to DTO directly in facade layer then I can use converter. A converter is the one that constructs data objects from Models or service layers. It converters data from source to target using Populators. We can say converter contains one or more Populators. Converters create an object of DTO.

It converts data object to Model using populator and Model to data object using Reverse populator. The Data object is always created from a spring bean that is defined in the beans.xml file for the extension.All the converters are an instance of AbstractConverter or AbstractPopulatingConverter

Ex: Product Converter, Cart Converter, Customer Review Converter etc.

Note: No concrete Converters should be written, all converters should be spring configured only and should use the AbstractConverter base class.
Populators:
Populators break the code for filling up data in DTO. This is required because, not each DTO needs all attributes of a model. Each Populator carries out one or more related updates to the Data Object. Each population step can invoke services or copy data from the source business object to Facade Data object. Facades always use a Converter to create a new instance of a Data Object and then invoke Populators or other Converters to fulfill the task of building up the Data Object.
  1. It contains conversion logic
  2. We cannot use this directly in code, before that Converters should be spring injected and used.
  3. Populators are used in facade layer only.
  4. Reverse Populators are used in Service layer.
Ex: Product data populator, cart populator, gender data populator etc.

We have two types of Populators:
  1. Configurable Populators
  2. Modifiable Configurable Populators
ConfigurablePopulators may implement different conversion rules based on a set of enums.

1. First the converter creates a data object using all the Populators which fill the mandatory fields.
2. Then a configurable populator fills the fields which are only required by some components/pages of the front-end. It has a Map<enums option, populator>.
Modifiable Configurable Populators enables you to modify ConfigurablePopulators that implement the ModifiableConfigurablePopulator interface, which includes adding Populators to, and removing Populators from already configured ConfigurablePopulator beans.
Modifications are configured as spring beans that extend the abstract parent configurablePopulatorModification bean. They register themselves with the target populator during context initialization.
The commercefacades-spring.xml file contains the definition of the abstract configurablePopulatorModification parent bean, which defines the init method that executes the registration with the target populator.

Sunday 22 May 2016

JavaBeans in Hybris..

JavaBeans: 

 JavaBean  is a Java class that:
1.     Implements the Serializable interface
2.     Has a no-argument constructor
3.     JavaBean properties must have public setter and getter methods
 Java Bean makes it easy to reuse software components.

Example of JavaBean:

public class JavaBeanDemo  implements java.io.Serializable
{
          private int num;
          private String Fname;
                  
          public JavaBeanDemo()
          {
                   // default constructor
          }
          public void setNum(final int num)
          {
                   this.num = num;
          }              
          public int getNum()
          {
                   return num;
          }
          public void setFname(final String Fname)
          {
                   this.Fname = Fname;
          }
          public String getFname()
          {
                   return Fname;
          }   
}

 JavaBean in Hybris:

  • In hybris javabeans are automatically generated.
  • Each extension may provide a bean configuration file in this file class name, attributes or superclass are defined. 
  • Java Beans or Enums definitions are melded across extensions.
  • Java beans Contain an abstraction of models.  

Example for custom java bean Generating:

Configure the bean in extension-beans.xml
    <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
               <property name="Fname" type="String"/>
        </bean>
The following JavaBean is Generated under platform/bootstrap/gensrc folder based on above configuration. it generated  when ever we call “ant all” ( or)  “ant clean all” target.
 public class JavaBeanDemo  implements java.io.Serializable
{
          private int num;
          private String Fname;
                  
          public JavaBeanDemo()
          {
                   // default constructor
          }
       //Setters and getters methods..
}
  • Java beans are useful as DataObjects used by Frontend layer.
  • Merge attributes into existing beans.

For example:- extenstion1 and extenstion2 have same bean class with different attributes that attributes merge into one javabean class Generated under platform/bootstrap/gensrc.

 extension1-beans.xml:- 

        <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
                  <property name="Fname" type="String"/>
        </bean>

 extension2-beans.xml:-

        <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
                  <property name="Fname" type="String"/>
                  <property name=”Lname” type=”String”/>
        </bean>

Generated JavaBean Class:- 

public class JavaBeanDemo  implements java.io.Serializable
{
       private int num;
       private String Fname;
       private String Lname;
             
       public JavaBeanDemo()
       {
              // default constructor
       }
       public void setNum(final int num)
       {
              this.num = num;
       }           
       public int getNum()
       {
              return num;
       }      
       public void setFname(final String Fname)
       {
              this.Fname = Fname;
       }      
       public String getFname()
       {
              return Fname;
       }              
       public void setLname(final String Lname)
       {
              this.Lname = Lname;
       }       
       public String getLname()
       {
              return Lname;
       }
}




Saturday 21 May 2016

Overview on Dynamic Model Attribute...!!!



Dynamic Model Attribute:
What is an attribute?
An attribute is a property of any type. If an attribute consists of 
persistence type=”property” then a column is created in database which means values are stored in database.

What is dynamic attribute?
A dynamic attribute is the one which whose values are not stored in database i.e non-persistent values. One can identify dynamic attribute by seeing its
persistence type=”dynamic” in items.xml file
Ex: 1. Cart Size: whenever we added the new product to the cart the number will be increased in the cart.
      2. Amount added in order.

For each Dynamic Attribute, a spring bean ID known as attributeHandler is automatically generated. Else we may provide custom bean id.

How Dynamic Attributes are related to the hybris Model?
1.    The AbstractItemModel type holds a reference to the  DynamicAttributesProvider object, which in turn, holds a collection of DynamicAttributeHandler objects.
2.    By using the methods get and set on the DynamicAttributesProvider object, the call is delegated to the valid DynamicAttributeHandler instance.
3.    From user point of view, this process is transparent so only the interaction with the DynamicAttributeHandler instance is done by calling getter on the hybris Model

How to create Dynamic attribute?
Step 1: Dynamic Attributes are used to define attributes whose values are not persisted in a database. To acquire the knowledge how to do that lets see the below example
Ex :
<attribute type="java.lang.String" qualifier="longName">
<persistence type="dynamic"/>
 <modifiers read="true" write="true" optional="true" unique="false"/>
 </attribute>

Step 2:  
Provide a custom attributeHandler  by assigning a bean id of the class that implements the DynamicAttributeHandler interface and holds the logic:
Ex:  <persistence type="dynamic" attributeHandler="dynamicAttributesStringSample"/>

Step 3:  Implementing Dynamic attribute
 1.Create a new class named MyClass that implements DynamicAttributeHandler interface.
2. Override the getter and setter methods
Public String get()
{
}
Public String set()
{
}
Step 4: Register the spring bean in core-spring.xml

<bean id="MyClass" class="de.hybris.platform.servicelayer.test.DynamicAttributesStringSample"   />
Step 5 : update the system :
Update running system using the hybris Administration Console
or
using the following ant command in the command line:
ant  updatesystem
Sources are compiled and in the Model class  proper getter and setter are generated depending upon the modifiers.


Monday 16 May 2016

Spring in Hybris Post2:

Spring in Hybris Post2:

Spring Configuration:

Spring configuration of extension uses 3 xml files for your bean definations they are 1.global-<extenstion-name>.xml,2.<extension-name>-spring.xml and 3.web-application-config.xml 

Bean aliasing:

Sometimes desirable to give a single bean multiple names, otherwise known as bean aliasing.Spring provieds a <alias> tag.
Syntax:<alias name="bean-name" alias="alias-name-for-defined-bean"/>
In Hybris using <alias> to avoid overwrting Services.

For example:

ExtensionOne:-  
<alias name="demoservice" alias="demo1Service"/>
<bean name="Demo1Service" class="ABC"/>
ExtensionTwo:-
<alias name="demoService" alias="newDemoService"/>
<bean name="newDemoService" class="XYZ"/> 
 Two are more extensions uses same bean name Services  and one extension depend on another extension it means
<requires-extension name="ExtensionOne"/> from above example. We uses alias name of bean to avoid overwriting Services.

Spring and Hybris Bean scopes:

The Spring Framework supports five scopes they are singleton, prototype,request, session, global-session three of which are available only if you use a web-aware ApplicationContext they are request,session,global-session.
In side the <bean> tag we have an attribute option scope.This is used for which scope is applicable to that bean.

For example:-

<bean id=”…” class=”…” scope=”singleton”>
<!—configuration for this bean and  properties go there-->
</bean>

Spring provides @Scope annotation to keep the bean in desired scope.We need to  Annotate the class with this annotation and provide the bean scope value. 

For example:

@Scope(singleton”)
Public class BeanScopeDemo {}

 Apart from this  spring scopes hybris supports two extra bean scopes they are yrequest and tenant.
        yrequest scope is same as  request scope in spring.The yrequest scope may be used for binding beans to the application context for a single request. The global-spring- core.xml file of the core extension adds a special scope named yrequest to ApplicationContext. The yrequest scope is used out side the web application context. It means that you can access these beans even in absence of a web application.If a session is invalidated, instances are destroyed  the scope quit to exist from the applicationcontext.

Example for yrequest scope:

<bean id="..." class=".." scope="yrequest">
<!—configuration for this bean and  properties go there-->
</bean>
Tenant scope is same as singleton scope of spring. Hybris has deprecated tenant scope in version 5.0.The Tenant scope makes sure that the bean is instantiated once per tanant of the hybris. Whereas singleton would create only one instance for all tenants to use.

Example for tenant scope:

<bean id=”…” class=”…” scope=”tenant”>
<!—configuration for this bean and  properties go there-->
</bean>

Sunday 15 May 2016

Spring Framework in Hybris

 Spring Framework in Hybris:


Spring is a light weight because of its POJO implementation and open source framework.
 The Spring Framework doesn't force the programmer to inherit any class or implement any interface.
 That's why it is said non-invasive. Spring is a complete and a modular framework for Java platform provided and maintained by Spring source.
The Spring frame work is used by hybris.

Spring bean configuring:

<bean id=”mybean” class=”Mybean” parent=”MybeanParent”>
<!--here parent bean to inherit its configuration-->
<property name=”name1” value=”literalValue”/>
<property name=”name2” ref=”bean1”/>
 <!--property value can be literal or references to another bean-->
<property name=”name3”>
<list merge=”true”><ref bean =”bean2”/></list>
</property>
 <property name=”name4”>
<map> <entry key=”key1” value-ref=”bean3”/></map>
<!--lists and maps may be merged with definition in other extenstions--> </property>
 </bean>

Spring provides many components, not all of them are used in Hybris.
Mostly Inversion of control(IOC) and Dependency Injection,Spring MVC,Spring Security,Spring AOP are used by hybris.

Inversion of control(IOC) and Dependency Injection, it makes the code loosely coupled
 so easy to maintain and makes the code easy to test so Inversion of control(IOC) and Dependency Injection used heavily by hybris.

Spring MVC  framework is request-driven, designed around a central servlet that dispatches requests to controllers and offers other functionality that facilitates the development of web applications. Spring MVC. used in presentation layer/Front End in hybris. Mostly Spring MVC used in accelerators.

Spring Security,used for authentication and basic authorization.

Aspect-Oriented Programming (AOP)  hybris not used by default but usable for extending stuff which isn’t customizable by default or implementing cross-cutitng-concerns