What is role of jalosession?

The Jalo layer in hybris is depreacted, not the jalosession.

Whenever a request is made to hybris server, it may need current user details, currency, language, timezone etc to serve that request efficiently. Since HttpSession does not hold all these details, hybris came up with the concept of JaloSession.

Whenever a request comes to Hybris, the filter HybrisInitFilter creates an object of JaloSession. Every JaloSession object is associated with a SessionContext object, which has current user, language, currency etc and the current httpSession object.

  • Cron jobs also run in a JaloSession.
  • Each JaloSession is bound to a tenant. This cannot be changed, after the instance of JaloSession is created.
  • JaloSession is never made persistent in database.

What are ModelAttributes?

Some time it is necessary to get few data in many JSPs, and we don’t want to pass them as a part of DTO (data objects). For example, the titles (Mr and Mrs etc). They can be used in many JSPs and tags file, like registration, delivery address etc.

In such cases, what we do is, create a convenient method in Abstract controllers, and use model attribute annotation for them. In this way they are available from all JSPs directly  using model attribute.

modelAttributes

These can be accessed directly in JSPs or even tag files. like

Current Language : ${currentLanguage}

Data model of Hybris

The hybris data model is made up of type systems.

A type system is defined as a collection of different itemtypes declared in items.xml. Each item type is consist of a Java class which gives access to different members through getter methods and set the values in them through setter methods. In addition to that, each item type has a database entity (table) associated with it.

Item type = Table + Java class

Like any other data model defining entity, item types gives us the flexibility of defining various data structures including primitive one. An data model may consist of integers, Strings or an complex data structure, with a mixture of everything.

For example, let’s take the example of a Student table, having name and roll number.

Student
Roll number Name
123 Ram
456 Shyam

The above data structure of Student can be simply defined as a Java class called Student and two member variable roll number and name.

Student

The above class will give us utility method to access Student object. This class also defines the data types of its member variables. The same is also necessary to define, while creating the database table Student.

So essentially, we can say that a java class and a database entity is something very basic, to create a world, where a java program interacts with a database entity.

Hybris data model collaborated these two and made us write a single xml file declaratively. This gives us freedom from writing create statements in database and also keeps us free from writing monotonous pojo classes.

In real world, the data structures are not as simple, as depicted in above example, rather they are very complex involving floats, double, integers, Strings, collections, enums and nested objects to name a few.

Hybris data model also support each one of them, and we can define every possible data structure in our items.xml.

Atomic types: The item types which are primitive in java, are called atomic itemtypes. For example, integer, float, double, boolean, Strings etc. They are defined in items.xml as follows.

<atomictype class=“java.lang.String” extends=“java.lang.Object” autocreate=“true” generate=“false”/>

Collection type: They are analogue of generic types in Java. A collection is a group of similiar type item types. Like a group of language used for a particular application could be stored as LanguageList.

<collectiontype code=”LanguageSet” elementtype=”Language” autocreate=”true” generate=”true” type=”set”/>

 

 

Enum types: The group of fixed constants are defined as enums, like any other language.

<enumtype code=“ExportStatus” autocreate=“true” generate=“true”>

<value code=“NOTEXPORTED”/>

<value code=“EXPORTED”/>

</enumtype>

To define a general data structure, like that of Student from above example, we need to define a new item type.

<itemtype code=“Student” extends=“GenericItem”

autocreate=“true” generate=“true”                                      jaloclass=“com.blog.hybrisdiary.core.jalo.Student”>

<attributes>

<attribute qualifier=“name” type=“localized:java.lang.String”>                                                                                                            <modifiers/>

<persistence type=“property”/>

</attribute>

</attributes>

</itemtype>

Here we defined an new item type extending Generic item, which is parent of all item type. This item type has only one attribute, name.

The jalo class, is the class which creates the item Student. This class is auto generated.

Each of the characteristics of an item type is defined as attribute of item type. The attibute itself could be of any type, i.e an atomic type like here (String) or another item type.

Suppose, we have to handle student’s address as well. Now it is not advisable to keep addresses as simple Strings. Since address itself, may consist of house number, street number, town, city, country, and mobile number etc. So we should have a separate entity managing the addresses.

<itemtype code=“Address” extends=“GenericItem”

autocreate=“true” generate=“true”

jaloclass=“com.blog.hybrisdiary.core.jalo.Address”>

<attributes>

<attribute qualifier=“town” type=“localized:java.lang.String”

>

<persistence type=“property”/>

</attribute>

<attribute qualifier=“country” type=“Counry”

>

<persistence type=“property”/>

</attribute>

</attributes>

</itemtype>

Here the attribute country of Address is again of type Country. Since Country can have name, isocodes and regions etc. So we used type as Country for qualifier country.

Now we can modify our Student itemtype to accommodate address as well.

<itemtype code=“Student” extends=“GenericItem”

autocreate=“true” generate=“true”                                      jaloclass=“com.blog.hybrisdiary.core.jalo.Student”>

<attributes>

<attribute qualifier=“name” type=“localized:java.lang.String”>                                                                                                            <modifiers/>

<persistence type=“property”/>

</attribute>

<attribute qualifier=“address” type=“Address”>                                                                                                        <modifiers/>

<persistence type=“property”/>

</attribute>

</attributes>

</itemtype>

What is an attribute?

While defining the various properties for an item type, we need to define many things about the property itself.

For example, for customer, mobile number is a property. Now mobile number itself could have many properties. Like whether it is mandatory property? How many digits it will have? Is customer is allowed to change the mobile number?

So basically we need a data structure again for the properties. In hybris the properties or characteristics of an item type are known as attributes. The attribute itself could be of primitive type (like string, or integer) or it could be of type like that of any other item type.

It is defined within the definition of item type in items.xml

it corresponds to column of database.

What is an item type?

Be it a desktop or web application. Be it java or any other technology. Be it small or big size application. Any application works on some kind of data. The data here could be real time exact data like customers, products, promotions etc, or meta data (data about data).

We need to define a data structure for any application. These definitions of data structure contains the meta data about real data. For example, if Ram is a customer. Then name, email, mobile number could be Ram’s actual data, but some where we need to define, what properties of Ram (Customer) , we are likely to keep or interested in our application scope.

Such definitions of anything in application is defined as item type in Hybris. Possible examples are Customer, Product, Promotions, vendors, Categories, Stores etc.

In hybris, the item types, are basically the XML declaration of various data structures used. They are defined in items.xml.

The item type is not just about defining data structure. Hybris also generates POJO classes for each defined item type. They are known as model classes. This class provides getter and setter method for attributes. instanceThe above table shows the approximate analog of item type with Java and DBMS sysem.

storefront

As the name suggests, its the front of a store.

Storefront is basically the front end for your hybris eco system, which is visible to potential customers. They can browse products, categories offered by business. They can contact the business from here. They can order an item or cancel the purchase from here.

The storefront also allows you to search for physical stores present in your area using store locators. User can search for a product and add it his wishlist.

So basically, the store front is the control panel for the customers to get engaged with business in several ways. We normally call it the web site.

What does ATP means in hybris?

ATP – Available to promise.

ATP is an integer, which defines, the number of stock that is available to promise to customer as sell-able. In real life, the stock present in warehouse doesn’t necessarily means that it is the amount, you can sell. this is because

  • Some stock available at a warehouse, when it start operations (after a reconciliation, typically every morning). it is known as Stock on hand (SOH).
  • some stock at a warehouse, may already be ordered, and waiting to be shipped. we can not sell it again. such stock is known as reserved.
  • We may ask for more stock from other partner/warehouse in a timely manner. such stock is called oversell.
  • an order is cancelled. so it would be available again. we need to subtract ordered quantity from reserved.
  • An order is returned. so it would be available again. we need to subtract ordered quantity from reserved.

so we see, there may be many business rules, which may define the ATP level. A typical definition of ATP may be:

ATP = ( SOH + OverSell ) – reserved