Thursday, 18 August 2016


Hybris: What is Solr boost in Hybris | How can add more index property in free text search in Hybris ?
Sometime in Hybris interview we get question which I heard first time so obviously unable to give answer of that question
Yesterday i got question about solr boost So first we need understand what is Solr boost
> Suppose you using free text search on storefront in hybris means doing search something text like "123" then at hybris side solr query fire on solr server and display result on screen what he found in result so result willdefinitely happen on some index property of your Solr item type's index property like ean,code,name etc
Lets suppose of text "123" match in all these 3 index property (ean,code,name) and you want display product (Ean match first) top on result so these type of result we can achieve through solr boost where we boost the search result by providing high score (boost) to index property.
 
Before going to solr boost first another question is How can we add more index property in free text search in hybris
 
Technical
 
in hybris there one file name commerceservices-spring-solrfacetsearch.xml(hybris 5.5) where you can founddefaultCommerceSearchTextPopulator where we need to add your index property to apply free text search
suppose there is index property (description) on which you want to apply free text search then you need to add this property as below
<alias name="defaultCommerceSearchTextPopulator" alias="commerceSearchTextPopulator"/>
    <bean id="defaultCommerceSearchTextPopulator"
            class="de.hybris.platform.commerceservices.search.solrfacetsearch.populators.SearchTextPopulator">
        <property name="freeTextQueryBuilders">
            <list>
                <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                    <property name="propertyName" value="ean"/>
                    <property name="boost" value="100"/>
                </bean>
                <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                    <property name="propertyName" value="code"/>
                    <property name="boost" value="90"/>
                </bean>
                <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                    <property name="propertyName" value="name"/>
                    <property name="boost" value="50"/>
                </bean>
                <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                    <property name="propertyName" value="manufacturerName"/>
                    <property name="boost" value="40"/>
                </bean>
                <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.ClassificationFreeTextQueryBuilder">
                    <property name="boost" value="30"/>
                </bean>
                <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                    <property name="propertyName" value="keywords"/>
                    <property name="boost" value="20"/>
                </bean>
                <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                    <property name="propertyName" value="categoryName"/>
                    <property name="boost" value="10"/>
                </bean>
                <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                    <property name="propertyName" value="description"/>
                    <property name="boost" value="10"/>
                </bean>
                
            </list>
        </property>
    </bean>
In above for every indexproperty there is given boost value
So in above boost value score the search result means suppose you want to search text "demo" and result is match in ean, name, description and i want to see description result first then i will give higher boost value for description like below
<bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                    <property name="propertyName" value="description"/>
                    <property name="boost" value="110"/>
</bean>
So Finally, In interview if you get question like suppose search text is match in more than one index propertybut i want to see any specific property result first then you can give answer of Solr boost

Solr boost can achieve
1. index-time boosts
2. Field Based Boosting
In hybris used Field Based Boosting - adding an optional query clause that "boosts" documents for matching an "important:true" query,



Hybris: How to create your own type of CMS restrictions in Hybris | steps by steps to create CMS restrictions


If your project requires custom rules for the visibility of CMS components, you must create your own type of CMS restrictions.
Introduction
There is a requirement to show a banner to a customer who is browsing the eShop with one or more products in the cart and he doesn't update the cart for some minutes. He may need assistance and it would be better if he calls the hotline.

Data Model
We add the extension cms2 as requirement in the extensioninfo.xml of our new custom extension. In this example, we use the extension cmstraining. It already has bean auto scanning.

Then we define a new type in cmstraining-items.xml:

 <itemtypes>
        <itemtype generate="true"
           code="UndecidedShoppingCustomerRestriction"
           jaloclass="org.everyreply.cmstraining.jalo.UndecidedShoppingCustomerRestriction"
           extends="AbstractRestriction"
           autocreate="true"
       >
            <attributes>
                <attribute qualifier="timeToWaitInMinutes" type="java.lang.Integer">
                    <description>The time to wait before triggering this restriction</description>
                    <modifiers optional="false"/>
                    <persistence type="property"/>
                </attribute>
                <attribute qualifier="description" type="java.lang.String" redeclare="true">
                    <persistence type="dynamic" attributeHandler="undecidedShoppingCustomerRestrictionDynamicDescription" />
                    <modifiers write="false" />
                </attribute>
            </attributes>
        </itemtype>
    </itemtypes>

 The jalo property descriptio comes from AbstractRestriction and we declare it as dynamic. Because of this, we have to provide two implementations: A jalo method and a Dynamic Attribute handler.


public class UndecidedShoppingCustomerRestriction extends GeneratedUndecidedShoppingCustomerRestriction
{

  /**
   * @param pSessionContext
   * @deprecated
   */
  @Override public String getDescription(final SessionContext pSessionContext)
  {
    return Localization.getLocalizedString(UndecidedShoppingCustomerRestrictionDynamicDescription.KEY_DESCRIPTION_TEXT,
        new Object[] { this.getTimeToWaitInMinutes(pSessionContext) });
  }
}

@Component
public class UndecidedShoppingCustomerRestrictionDynamicDescription implements DynamicAttributeHandler<String, UndecidedShoppingCustomerRestrictionModel>
{

  public static final String KEY_DESCRIPTION_TEXT = "type.CategoryPageCustomerWaitingTooLong.description.text";

  @Override public String get(final UndecidedShoppingCustomerRestrictionModel pModel)
  {
    return Localization.getLocalizedString(KEY_DESCRIPTION_TEXT,
        new Object[] { pModel.getTimeToWaitInMinutes()});
  }

  @Override public void set(final UndecidedShoppingCustomerRestrictionModel pUndecidedShoppingCustomerRestrictionModel,
      final String s)
  {
    throw new UnsupportedOperationException();
  }
}
Localisation

We add the following lines to the resources/localization/cmstraining-locales_en.properties:
type.CategoryPageCustomerWaitingTooLong.name=Restriction for customers waiting too long
type.CategoryPageCustomerWaitingTooLong.timeToWaitInMinutes.name=Time to wait (min.)
type.CategoryPageCustomerWaitingTooLong.description.text=Shows a component or page if a shopping customer has been waiting for more than {0} minutes

Cockpit Configuration
For our new restriction type we use the default cockpit configuration.
Evaluator
The model contains the configuration of the new restriction. But this isn't enough, we need a bean which takes this model and calculates if the CMS component must be visible or not:
We create a mapping between the restriction type and the evaluator. This mapping is loaded automatically by the default implementation of the CMSRestrictionService:
<bean id="cmsUserGroupRestrictionEvaluatorMapping" class="de.hybris.platform.cms2.servicelayer.services.evaluator.CMSRestrictionEvaluatorMapping">
        <property name="restrictionTypeCode" value="UndecidedShoppingCustomerRestriction" />
        <property name="restrictionEvaluator" ref="undecidedShoppingCustomerRestrictionEvaluator" />
    </bean>
</beans>
Now we can update the system and start the server.
Page Configuration
Each CMS Page has a list of applicable restriction types. We update this list of the type of page which is going to have our new restrictions:
INSERT_UPDATE CmsPageType;code[unique=true];restrictionTypes(code)[mode=append]
;ProductPage;UndecidedShoppingCustomerRestriction


Testing
In the next example the sample data of accelerator B2C is used.
We log in into cmscockpit and we got to a page with the productPageTemplate. We are going to use the "Product List" page.
In the slot "Header Bottom", we create a new paragraph component with the text " If you need advise on any of our products, you could call our hotline. We are here to help you!", we synchronize it and we check if it is visible on the page http://hybrispracticals:9001/yacceleratorstorefront/electronics/en/Open-Catalogue/Components/Power-Supplies/c/816
Evaluator
@Component
public class UndecidedShoppingCustomerRestrictionEvaluator implements CMSRestrictionEvaluator<UndecidedShoppingCustomerRestrictionModel>
{
  /*
    Logger of this class.
   */
  private static final Logger LOG = Logger.getLogger(UndecidedShoppingCustomerRestrictionEvaluator.class);

  @Autowired
  private CartService cartService;

  @Override public boolean evaluate(final UndecidedShoppingCustomerRestrictionModel pUndecidedShoppingCustomerRestrictionModel,
      final RestrictionData pRestrictionData)
  {
    CartModel cart = cartService.getSessionCart();
    if (cart.getEntries().isEmpty()) {
      return false;
    } else {
      //It is safe to use dates, because all the entries have the same time zone.
      Date newestModifiedTime = null;
      for (AbstractOrderEntryModel anEntry : cart.getEntries()) {
        if (newestModifiedTime == null || newestModifiedTime.compareTo(anEntry.getModifiedtime()) > 0)
        {
          newestModifiedTime = anEntry.getModifiedtime();
        }
      }
      Calendar now = Calendar.getInstance();

      Calendar timeLimit = Calendar.getInstance();
      timeLimit.setTime(newestModifiedTime);
      timeLimit.set(Calendar.MINUTE, pUndecidedShoppingCustomerRestrictionModel.getTimeToWaitInMinutes());
      final boolean resutlEvaluation = now.after(timeLimit);
      if (LOG.isDebugEnabled())
      {
        LOG.debug("Result of evaluation of " + pUndecidedShoppingCustomerRestrictionModel.getUid() + ": " + resutlEvaluation);
      }
      return resutlEvaluation;
    }
  }
}


















Sunday, 31 July 2016

Difference Between String , StringBuilder And StringBuffer Classes With Example : Java
Today we are going to understand the difference between String , StringBuilder and StringBuffer . As you will find that there are minor differences between the above mentioned classes.

String

String is immutable  ( once created can not be changed )object  . The object created as a String is stored in the  Constant String Pool  . 
Every immutable object in Java is thread safe ,that implies String is also thread safe . String can not be used by two threads simultaneously.
String  once assigned can not be changed.

String  demo = " hello " ;
// The above object is stored in constant string pool and its value can not be modified.


demo="Bye" ;     //new "Bye" string is created in constant pool and referenced by the demo variable            
 // "hello" string still exists in string constant pool and its value is not overrided but we lost reference to the  "hello"string  

StringBuffer

StringBuffer is mutable means one can change the value of the object . The object created through StringBuffer is stored in the heap . StringBuffer  has the same methods as the StringBuilder , but each method in StringBuffer is synchronizedthat is StringBuffer is thread safe . 

Due to this it does not allow  two threads to simultaneously access the same method . Each method can be accessed by one thread at a time .

But being thread safe has disadvantages too as the performance of the StringBuffer hits due to thread safe property . Thus  StringBuilder is faster than the StringBuffer when calling the same methods of each class.

StringBuffer value can be changed , it means it can be assigned to the new value . Nowadays its a most common interview question ,the differences between the above classes .
String Buffer can be converted to the string by using 
toString() method.

StringBuffer demo1 = new StringBuffer("Hello") ;
// The above object stored in heap and its value can be changed .

demo1=new StringBuffer("Bye");
// Above statement is right as it modifies the value which is allowed in the StringBuffer

StringBuilder

StringBuilder  is same as the StringBuffer , that is it stores the object in heap and it can also be modified . The main difference between the StringBuffer and StringBuilder is that StringBuilder is also not thread safe. 
StringBuilder is fast as it is not thread safe .  


StringBuilder demo2= new StringBuilder("Hello");
// The above object too is stored in the heap and its value can be modified
demo2=new StringBuilder("Bye"); 
// Above statement is right as it modifies the value which is allowed in the StringBuilder


----------------------------------------------------------------------------------
                          String                    StringBuffer         StringBuilder
----------------------------------------------------------------------------------                 
Storage Area | Constant String Pool           Heap                       Heap 
Modifiable     |  No (immutable)            Yes( mutable )          Yes( mutable )
Thread Safe   |           Yes                                  Yes                              No
 Performance |         Fast                                Very slow                    Fast
-----------------------------------------------------------------------------------


Please mention in the comments in case you have any doubts related to the post: difference between string, stringbuffer  and stringbuilder.

Saturday, 23 July 2016

Hybris WCMS + Addon:


Accelerator Storefront – Based on Spring MVC framework
  • Model: represents and manages data
  • View: presents the model data
  • Controller: responds to user interaction to control mode state and presentation of the view.
The accelerator is based on view. The accelerator uses JSP for page rendering, JSP files are not used directly, but only as renderers. The JSP files are located under
${HYBRIS_BIN_DIR}/ext-template/yacceleratorstorefront/web/webroot/WEB-INF
Views:

  • The spring MVC controllers specify a view name
  • Spring is configured to look in ${HYBRIS_BIN_DIR}/ext-template/yacceleratorstorefront/web/webroot/WEB-INF/views

JSP Structure



JSP Construction




JSP Review







Friday, 15 July 2016

Jai Sri Ram
Today I started blogging on E-Commerce Domain Hybris. I'll post practical scenarios in the posts.

Welcome to My blog. Hope you will like it.

Welcome to my blog, I would like to take an opportunity to foresee a
beautiful relationship in visiting and getting the best out of this blogkeep-calm-and-write-somethign. We have a multiple and multi things to follow. Stay connect and Stay hungry for knowledge.







Hybris Commerce Development

Hybris Commerce Development is a SCRUM development practice with the Java-based services and applications using Java EE, Spring Framework, and RESTful Webservices. The new interface has changed a lot from the older versions. After the takeover by SAP so many things like licensing, learning and wiki accounts and downloadables have changed a lot.
  • Prerequisites
  • WCMS
    • HY mashups
    • CMS items hierarchy
    • Configure the data model of basestore website
    • Warehouse
    • Point of Sale and their relations
    • Create new and configure existing CMS restrictions
    • Evaluation of CMS restrictions
    • New CMS component types
  • Backoffice and Cockpit Modifications
    • HY mashups
    • Create a new Backoffice application
    • Widgets using the Cockpit NG framework
    • Introduce legacy cockpits modification into hybris accelerator
    • Dynamic forms
  • Commerce and Accelerator
    • HY mashups
    • Create a new Addon
    • OCC Webservice
    • Promotion
    • Order Splitting strategy
    • CMS Navigation bar
    • Configure accelerator based storefront and product converters
    • Extend payment commands and identify payment integration points
    • Internationalization and request handling in accelerator
    • Hot Folder transformation
  • Data Modeling
    • HY mashups
    • Model new data types and extend existing ones incl. localized attributes and enumerations
    • Configure indices and deployments
    • Identify how types are stored in database
    • Create advanced FlexibleSearch queries
    • Determine the consequences of using variants
    • Category variants
    • Classification attributes
  • Order Managment
    • HY mashups
    • Create and start a business process
    • Fulfillment process and subprocesses
    • Shopping cart handling incl. checkout scenarios
    • Identify features available in Assisted Service Module
    • Available Customer Service Operations in hYBRIS Commerce Suite
  • Search and Navigation
    • HY mashups
    • Create a new Solr index
    • Facet, Facet range
    • Solr topology
    • Configure autosuggestions
    • Keywords
    • Stopwords
    • Synonyms
    • hero products
    • boost rules
  • Platform Basics
    • HY mashups
    • Concept of System Initialization
    • Concept of System Update
    • Essential and Project data
    • Session handling
    • Extension structures
    • Configure platform start and change its build procedure
    • Identify caching behavior and model interceptor
    • How transactions work in Hybris Commerce Suite
  • Platform Features
    • HY mashups
    • How to use Events
    • Advanced features of ImpEx
    • Spring Context in Hybris Commerce Suite
    • How Cronjobs and cluster communication work
  • PCM Basics and Price Modeling
    • HY mashups
    • Price Calculation incl. PIQ_CALCULATE
    • Retrieval logic for Pricing
    • Model objects handling
    • Configure synchronization jobs
    • Create Workflow
  • User Management
    • HY mashups
    • Configure user rights and search restrictions
    • Switch user context in a given code
    • B2B hierarchy