What is Node in Bussiness Process and How many type of Node in Bussiness Process in Hybris

Good Evening Friends,

In my last Hybris interview i got question about Bussiness Process in Hybris and question was "What is Node in Bussiness Process and How many type of Node in Bussiness Process"

Related to what is Bussiness process which i allready discuss so lets discuss about type of Nodes in bussiness process

So what is Node?

After define process in hybris (through XML ) as below

<?xml version="1.0"encoding="utf-8"?>
<process xmlns="http://www.hybris.de/xsd/processdefinition" name="everyReplyProcess"
start="everyReplyStart" onError="onError" processClass="de.hybris.platform.fulfilment.model.ConsignmentProcessModel">
... ...
</process>


Then there is must to add content in process and that content is steps of your process and each step is called Node of process and each Node has tell below
1. Which node has to be invoked next
2. Each Node has ID

In above process definition there is one declare Node that is start node of your process in above case everyReplyStart is declare node


In hybris there is below type of Node and there use

1. Action Node  - Actions are the most important part of the processengine functionality. Normally, they have to implement a logic or call specialized services to execute tasks that are necessary in a process

example

<action id="isEveryReplyProcessCompleted" bean="bprocessesCompleted">       
  <transition name="OK"to="sendNotification"/>       
  <transition name="NOK"to="waitForComplete"/>
</action>


2. Wait Node - Lets during process you need to communicate to external environment or need to wait for complete of subprocess (inside process you can also define subprocess) then we need to define wait node as below

<wait id="waitForEverReplySubprocessEnd" then="isProcessCompleted"> <event>EverReplySubprocessEnd</event>
</wait>

so after wait complete which sense by your event given above call Node ID - isProcessCompleted

3. Split Node -  Suppose during in process you want to execute Actions in parallel then you can do by Split node as below

<split id="splitNode">
  <targetNode name="node1"/> <targetNode name="node2"/>
</split>

4. Notify Node - Lets during process execution you want to notify about status of process to someone then you define Notify Node in process as below

<notify id="notifySomeOne"then="nextNodeID">
  <userGroup name="everyReplyGroup"message="Perform action"/>
</notify>

5. End Node - it is ends the process and stores state and message in a process

<end id="error" state="ERROR">All went wrong.</end>
<end id="success" state="SUCCEEDED">Everything was fine</end>


Impex for Component (banner, image, external link, internal link, category) in Hybris | component tutorial in hybris

Introduction
Adding components to content slots in Hybris pages is relatively straightforward in the WCMS Cockpit; however exporting that data from the WCMS Cockpit to impex files is relatively difficult and can result in exporting more information than necessary. If you are the kind of developer who likes clean impex files and would just rather create them by hand, this document will hopefully help.
The purpose of this document is to outline how to create basic but commonly used components in Hybris by manually adding them to your impex file. This document will only demonstrate the code used to create components.
Organizing the code in terms of best practices – i.e. core vs. initial data or separating your impex file data by page or category – is a good idea, but is out of scope for this document.

General notes:
 Each of the commands below are INSERT_UPDATE commands. An INSERT_UPDATE will do exactly that. If the specified UID already exists in that particular table of the database, this command will update the rest of that UID’s entry. If the UID does not exist in that table, this command will add a new entry for the specified UID. This command will not delete entries from the database.
 Each INSERT_UPDATE command starts with the name of the database table to be modified. This table name relates directly to the type of component you are adding.

Variables in the impex file:
There are several variables used in the examples below. These variables are used to simplify the INSERT_UPDATE header. All variables should be declared at the top of your impex file. (Otherwise, you will get an error.)

Here is a list of variables used in the examples below:
• $contentCV – This is the content catalog version. For example: catalogVersion(CatalogVersion.catalog(Catalog.id[default=$contentCatalog]),C atalogVersion.version[default=Staged])[default=$contentCatalog:Staged]
• $lang – This is the default language for headers, labels, names, etc. The 2-letter code for the default language is used here. For example: English is ‘en’; German is ‘de’.
$siteResource – This is a constant used to point to the path of the content catalog directory in the code repository.

 For example: $siteResource=jar:de.hybris.platform.acceleratorsampledata.constants.Acceler atorSampleDataConstants&/SITENAMEcore/import/contentCatalogs/$contentCatalog

Creating a new content page
Impex files can be used to define new content pages in the site. Content pages can be defined either in core or initial data; however it feels a little more “correct” to define pages in core.

Code:
 INSERT_UPDATE ContentPage;$contentCV[unique=true];uid[unique=true];name;masterTemplate(uid,$cont entCV);label;defaultPage[default='true'];approvalStatus(code)[default='approved']; homepage[default='false'];previewImage(code, $contentCV)[default='ContentPageModel__function_preview'] ;;about;About Us;ContentPage2Template;/about

Explanation:

The code above will create a new content page, called “About Us”, for the content catalog specified in $contentCV.

uid: The unique system identifier for the content page.
name: The friendly name for the content page.
 • masterTemplate: The JSP template that will be used for this page; these are usually defined in cms-content.impex.
 • label: The URL of the content page. The forward slash preceding the label is important here; this makes it a link relative to the site root. (Otherwise, the link will be relative to the currently displayed page and break for other pages.)

Creating components
A wide variety of component types can be defined in the IMPEX files. The components below are among some of the most common components that are defined in the code. There are certainly other components that can be defined here.

INTERNAL LINK

 Code:
 INSERT_UPDATE CMSLinkComponent;$contentCV[unique=true];uid[unique=true];name;contentPage(uid,$co ntentCV);linkName[lang=$lang];&linkRef;&componentRef;target(code)[default='sameWin dow'];restrictions(uid,$contentCV)[default=''] ;;linkAboutUs;About Us Link;about;About Us;linkAboutUs;linkAboutUs

Explanation:

The code above will create a link to an internal page, in this case the “About Us” content page.
• uid: The unique system identifier for the internal link. • name: The friendly name of the internal link.
 • contentPage: The label of the content page being linked to.
• linkName: The displayed link text (i.e. what the user sees). The language specified is value of the $lang variable. If no language is specified, the system defaults to German.
 • linkRef: Reference to the link; it is simplest if this is identical to the UID.
 • componentRef: Reference to the link’s component; again, it is simplest if this is identical to the UID.

EXTERNAL LINK

Code:
INSERT_UPDATE CMSLinkComponent;$contentCV[unique=true];uid[unique=true];name;url;linkName[lang=$ lang];&linkRef;&componentRef;target(code)[default='sameWindow'];restrictions(uid,$ contentCV)[default=''] ;;linkAccount;Account Link;/my-account;My Account;linkAccount;linkAccount

Explanation:

The code above will create a link to any URL. The example above links to a page within the site by relative URL, in this case the “My Account” page; however this link type can be used to create links to external websites as well.

• uid: The unique system identifier for the external link.
• name: The friendly name of the external link.
• url: The URL of the page being linked to. This can be either a relative link (as in the example above) or an external site.
• linkName: The displayed link text (i.e. what the user sees). The language specified here is value of the $lang variable. If no language is specified, the system defaults to German.
• linkRef: Reference to the link; it is simplest if this is identical to the UID.
componentRef: Reference to the link’s component; again, it is simplest if this is identical to the UID.

CATEGORY LINK

Code:
INSERT_UPDATE CMSLinkComponent;$contentCV[unique=true];uid[unique=true];name;&linkRef;&component Ref;category(code, $productCV);linkName[lang=$lang];target(code)[default='sameWindow'] ;;catAdhesives;Adhesives Category Link;catAdhesives;catAdhesives;pc_child_Adhesives;Adhesives

Explanation:

The code above will create a link to a product category page, in this case the “Adhesives” category page.

• uid: The unique system identifier for the category link.
name: The friendly name of the category link.
linkRef: Reference to the link; it is simplest if this is identical to the UID.
componentRef: Reference to the link component; it is simplest if this is identical to the UID. • category: The UID of the category that is being linked too.
 • linkName: The displayed link text (i.e. what the user sees). The language specified is value of the $lang variable. If no language is specified, the system defaults to German.

 NAVIGATION NODE

Code:

INSERT_UPDATE CMSNavigationNode;uid[unique=true];name;parent(uid, catalogVersion(CatalogVersion.catalog(Catalog.id[default=]),CatalogVersion.version [default=Staged])[default=:Staged]);links(&linkRef);&nodeRef;title[lang=$lang] ;navnodeAccount;Account Navigation Node;;linkResetPassword,linkOrderHistory,linkAddressBook,linkProfile;navnodeAccoun t;My Account

Explanation:

The code above will create a navigation node. A navigation node is a collection of links that are grouped together and are usually used in top navigation bars and footer components.
 • uid: The unique system identifier for the navigation node.
name: The friendly name of the navigation node.
 • parent: The parent node for this navigation node. This can usually be left blank.
 • links: A comma-delimited list of link components to be included in the navigation node. The link components should be identified by their UIDs.
 • nodeRef: Reference to the node; it is simplest if this is identical to the UID.
 • title: The (optional) title of the navigation node, displayed on the page directly above the list of links. The language specified here is value of the $lang variable. If no language is specified, the system defaults to German.

FOOTER COMPONENT
Code:
INSERT_UPDATE FooterComponent;$contentCV[unique=true];uid[unique=true];wrapAfter;&componentRef;n avigationNodes(&nodeRef) ;;siteFooterComponent;6;siteFooterComponent;navnodeResources,navnodeAccount

Explanation:

The code above will create a footer component, which contains a navigation node. The footer component will display the title and all links in the navigation node. It will also automatically display the links in columns, wrapping to a new column after a specified number of links.

• uid: The unique system identifier for the footer component.
• wrapAfter: An integer representing the maximum number of links per column in the component. Extra links will wrap to a new column.
componentRef: Reference to the link’s component. It is simplest if this is identical to the UID.
 • navigationNodes: A comma-delimited list of the UIDs of all navigation nodes to be included in the footer component.

 IMAGE COMPONENT

Code:
INSERT_UPDATE Media;$contentCV[unique=true];code[unique=true];realfilename;@media[translator=de. hybris.platform.impex.jalo.media.MediaDataTranslator];mime[default='image/jpg'];al tText ;;/images/logo.gif;logo.gif;$siteResource/images/logo.gif;image/gif;Site Logo

Explanation:

The code above will create an image component. An image component is generally used within other components that require images; for example site logo or banner components.

code: The relative path and file name of the image, relative to the content catalog directory.
realfilename: The image filename.
 • @media: The full path of the image. You’ll notice that the data includes a variable called $siteResource, which contains the path of the content catalog directory in the code repository.
mime: The mime type of the image.
altText: Alternate text for the image, used just as you would expect alternate image text to be used in the HTML Error! Filename not specified.tag.

BANNER COMPONENT

Code: # Banner Component

INSERT_UPDATE BannerComponent;$contentCV[unique=true];uid[unique=true];name;&componentRef;urlLin k ;;myBanner;My Banner;myBanner;"/" # Banner Components/Image UPDATE BannerComponent;$contentCV[unique=true];uid[unique=true];headline[lang=$lang];$pic ture[lang=$lang] ;;myBanner;My Banner Headline;my-banner.jpg

Explanation:

The code to create a banner component is actually in 2 parts, mostly for simplicity. The first INSERT_UPDATE section defines the component.

• uid: The unique system identifier for the site logo component.
name: The friendly name of the logo component.
componentRef: Reference to the link’s component. It is simplest if this is identical to the UID.
urlLink: The URL that the banner links to when clicked. The next UPDATE section adds an image component to the banner component.
 • uid: The unique system identifier for the site logo component to which you are adding an image component.
headline: A text headline for the banner.
picture: The filename of the image component being added; this should match the realfilename of the image component, as specified in the Image Component section of this document. Adding components to a content slot Once a component has been created, it can be added to any defined content slot on any page.

Code:
INSERT_UPDATE ContentSlot;$contentCV[unique=true];uid[unique=true];cmsComponents(&componentRef) ;;FooterContentSlot;linkHomepage,linkAboutUs,linkPrivacy,linkHelp

Explanation:
The example above adds several link components to a pre-defined content slot in the site footer.

 • uid: The unique system identifier for the content slot to which components are being added.

 • cmsComponents: A comma-delimited list of the components being added to the specified content slot. Components are added to the content slot in the order in which they are listed.

What is Promotion evaluation and partially activated promotion in Hybris ?

So Guys,
In every of my Hybris interview I face question related to Promotion, so today let’s start with some of them.

What is Promotion evaluation and partially activated promotion ?

Let’s you have a promotion "Buy 4 get 1 free" means when you buy 4 quantity then you will get 1 free item of same

So there will start evaluate promotion against a shopping cart and order then question will what will evaluate, it could be below

1. Evaluate which of the available promotions have been activated or "fired".
2. Evaluate which of the available promotions have been partially activated or "could fire".

So above both mode of evaluation is performing by Promotion extension.
So from above if User has added 4 quantities then there promotion action will fire i.e. means promotion activated

But suppose user has added 3 products not 4 then it means he very short from to get promotion means if he buy 1 more then he can get promotion. Then this condition called “could fire promotion” i.e. partially activated promotion

So In above case Hybris do associate a single item to this and communicated to customers on a website. For instance, a message such as "Add another item to your basket and 1 free in your order" could be displayed.

Technical:

If you look in Promotion logic (In jalo class) where you will find that below method
public List<PromotionResult> evaluate(final SessionContext ctx, final PromotionEvaluationContext promoContext)
       {
}

Activated Promotion:
       // Create a view of the order containing only the allowed products
                     final PromotionOrderView orderView = promoContext.createView(ctx, this, restrictResult.getAllowedProducts());
                     if (orderView.getTotalQuantity(ctx) >= qualifyingCount)
                     {
                           final long eligibleCountForPromotion = orderView.getTotalQuantity(ctx) / qualifyingCount;
                           final long nonEligibleCount = orderView.getTotalQuantity(ctx) % qualifyingCount;
                           final long totalFreeCount = freeCount * eligibleCountForPromotion;
                           // Begin logging of promotions consuming order entries
                           promoContext.startLoggingConsumed(this);
                           // Get a price comparator
                           final Comparator<PromotionOrderEntry> comparator = PromotionEvaluationContext.createPriceComparator(ctx);
                           // Consume high priced items as these are the ones that will be paid for
                           orderView.consumeFromTail(ctx, comparator, (orderView.getTotalQuantity(ctx) - (totalFreeCount + nonEligibleCount)));
                           // Consume the free items from the cheap end of the list, as these result in the lowest discount
                           final List<PromotionOrderEntryConsumed> freeItems = orderView.consumeFromHead(ctx, comparator, totalFreeCount);
                           // Create the actions to take for this promotion to fire.  In this case an entry level discount is created
                            // for each of the free items.
                           final List<AbstractPromotionAction> actions = new ArrayList<AbstractPromotionAction>();
                           for (final PromotionOrderEntryConsumed poec : freeItems)
                           {
                                  // Set the adjusted unit price to zero, these are free items
                                  poec.setAdjustedUnitPrice(ctx, 0D);
                                  final double adjustment = poec.getEntryPrice(ctx) * -1.0D;
                                  // This action creates an order entry discount.
                                  actions.add(PromotionsManager.getInstance().createPromotionOrderEntryAdjustAction(ctx, poec.getOrderEntry(ctx),
                                                adjustment));
                           }
                           // Put together a the result for this iteration.
                           final PromotionResult result = PromotionsManager.getInstance().createPromotionResult(ctx, this,
                                         promoContext.getOrder(), 1.0F);
                           // Get a list of all the order entries that were consumed during this run
                           final List<PromotionOrderEntryConsumed> consumed = promoContext.finishLoggingAndGetConsumed(this, true);
                           result.setConsumedEntries(ctx, consumed);
                           // Add the actions that this promotion has produced
                           result.setActions(ctx, actions);
                           // Add the result object to the list of results
                           results.add(result);
                     }





Partially activated promotion:

// Check to see if there are still some qualifying products in the basket
                     final long remainingCount = orderView.getTotalQuantity(ctx);
                     if (orderView.getTotalQuantity(ctx) > 0)
                     {
                           // Start logging the products we could take
                           promoContext.startLoggingConsumed(this);

                           // Consume the products passing false the removeFromOrder.  This means that we noted which products
                           // *could* cause us to fire, but are not actually removing them from the context.
                           orderView.consume(ctx, remainingCount);

                           // The certainty for this is calculated as a percentage based on the qualifying items available versus
                           // the number needed to make this promotion fire.
                           final float certainty = (float) remainingCount / (float) qualifyingCount;

                           // Create the promotion result
                           final PromotionResult result = PromotionsManager.getInstance().createPromotionResult(ctx, this,
                                         promoContext.getOrder(), certainty);

                           // Fill in the entries we could have consumed
                           result.setConsumedEntries(promoContext.finishLoggingAndGetConsumed(this, false));

                           // Add the result to the list of results
                           results.add(result);
                     }



So in partially activated promotion, still Promotion Results (promotion action) return with message “”.


How to configure Jrebel with Hybris | Use of Jrebel with Hybris

Hello Guys ,
Before go to configuration of JRebel with Hybris we need to understand about use of JRebel and Purpose of use of JRebel with Hybris.

So What is JRebel ?
JRebel is a JVM Java Agent that integrates with application servers, making classes reloadable with existing class loaders. Only changed classes are recompiled and instantly reloaded in the running application.
JRebel plugs into IDEs and build systems. Classes and static resources are loaded straight from the workspace.

Now How to Use JRebel in your Hybris project

So follow below steps to configure JRebel in your Hybris project

1.  Download JRebel from https://zeroturnaround.com/software/jrebel/download/
now unzip JRebel . Lets i have unzip in c:\jrebel

2.  Now create conf folder into c:\jrebel as below

3. Create jrebel.properties into conf folder


4. Now set environment variable  REBEL_HOME

5.  After finish all these setting open your Hybris's Local.properties file put below line into there
tomcat.javaoptions=-Xverify:none -javaagent:"C:/jrebel/jrebel.jar=de.hybris.tomcat.HybrisWebappClassLoader60"

tomcat.debugjavaoptions=-Xverify:none -javaagent:"C:/jrebel/jrebel.jar=de.hybris.tomcat.HybrisWebappClassLoader60" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n

6. Now you test whether JRebel successfully configure in your hybris
run hybrisserver.bat and check your console with below

7. Now after successful test create jrebel.xml file into your extension (extension that you want to monitor .class file ) as below . I have added into yacceleratorstorefront extension

in this file we have to give location of your .class file which create after build .



<?xml version="1.0" encoding="UTF-8"?>
<application generated-by="eclipse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">

       <classpath>
              <dir name="E:/HybrisDevelopment23032016/hybrisnew/hybris-commerce-suite-5.1.0.0/hybris/bin/ext-template/yacceleratorstorefront/web/webroot/WEB-INF/classes">
              </dir>
       </classpath>

</application>

8.  Now your JRebel is ready for use
So now how it works lets in login page of your storefront it call LoginPageController.java where i will put a console message
System.out.println("JRebel Test -- Java file change ");
and will test without restart server


now put below line in your controller


after you need to open another cmd and do only ant build
> ant build

after did if you see your hybris running server console you can see the change JRebel message of .class file as below

Now after hit your login url you can see your SOP message will print in console as below