BUSINESS PROCESS IN SAP HYBRIS COMMERCE CLOUD

In SAP Hybris Commerce Cloud, a business process is a set of steps or activities aimed at achieving a specific business goal. These processes can cover various aspects of e-commerce, such as order management, customer service, marketing, and more.

For example, a typical business process in SAP Hybris Commerce Cloud might include:

  • Order Management: This process is responsible for creating, process and fulfil orders, as well as handling payments.
  • Customer Service: This process is responsible for addressing customer inquiries, resolving issues, and providing support.
  • Marketing: This process is responsible for creating and managing marketing campaigns, promotions, and customer segmentation.
  • Product Management: This process is responsible for managing product information, catalog management, and pricing.
  • Inventory Management: This process is responsible for managing inventory levels, stock replenishment, and tracking inventory.

In SAP Hybris Commerce Cloud, these business processes are implemented using various of events such as start, action, wait, notify, failure, and end events. We can define the sequence of steps, conditions, and actions needed to complete a process. They can be customized to fit specific business needs.

The Hybris Process Engine is used to define these business processes. It functions like a workflow, with a defined sequence or flow, and uses different types of nodes:

  1. Action: Carries out process logic and allows for alternative actions.
  2. Wait: Pauses the process until a sub-process or external process result is received.
  3. Notify: Informs a user or user group about the process state.
  4. Split: Divides the process into parallel paths.
  5. End: Concludes the process and stores the state in a process item.

Hybris also has a Workflow System, which, while conceptually similar to the Process Engine, is used for different purposes and involves different classes.

It’s important to note that a Business Process in SAP Hybris Commerce Cloud does not involve human intervention, while a Workflow can. Additionally, the Event System in Hybris is used for receiving and sending events, functioning similarly to the Observer design pattern.

Requirement: Define a Business Process to be called when a customer registers using the Registration Form.

How the business process is triggered: Flow Diagram

1 1

Solution:

  1. Create a Process.xml file in the resource folder of your extension

Example: Clavrit-Process.xml.

  1. Write the required actions you want to create.
  2. Add required Transitions for each Action.
  3. Add the end points with the respective state as the final result of the business process.
<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
 @Author :Bhavik Solanki
 @Position: SAP Hybris Commerce Cloud Team Lead.
 @Organisation : Clavrit Digital Solutions
-->
<process xmlns="http://www.hybris.de/xsd/processdefinition" start="clavritAction1" name="clavrit-process"
        processClass="de.hybris.platform.orderprocessing.model.OrderProcessModel">

    <action id="clavritAction1" bean="clavritAction1">
       <transition name="OK" to="clavritAction2"/>
       <transition name="NOK" to="clavritAction3"/>
    </action>

    <action id="clavritAction2" bean="clavritAction2">
       <transition name="OK" to="success"/>
       <transition name="NOK" to="error"/>
    </action>

    <action id="clavritAction3" bean="clavritAction3">
       <transition name="OK" to="success"/>
       <transition name="NOK" to="error"/>
    </action>

    <end id="error" state="ERROR">Error in Clavrit Process</end>
    <end id="failed" state="FAILED">Failed to execute Clavrit Process</end>
    <end id="success" state="SUCCEEDED">Clavrit Process executed Successfully</end>

</process>
  • Create a process-spring.xml file. Example: clarity-process-spring.xml and add all the bean entries of the actions you want to create.
1.  <?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
 @Author : Bhavik Solanki
 @Position : SAP Hybris Commerce Cloud Team Lead.
 @Organisation : Clavrit Digital Solutions
-->
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context.xsd">
    <context:annotation-config/>

    <!-- Clavrit Process Actions -->

    <bean id="clavritAction1" class="com.clavrit.fulfilmentprocess.actions.clavrit.ClavritAction1"
         parent="abstractAction">
    </bean>

    <bean id="clavritAction2" class="com.clavrit.fulfilmentprocess.actions.clavrit.ClavritAction2"
         parent="abstractAction">
    </bean>

    <bean id="clavritAction3" class="com.clavrit.fulfilmentprocess.actions.clavrit.ClavritAction3"
         parent="abstractAction">
    </bean>

</beans>

  • Add the entries of clavrit-process.xml file and clavrit-process-spring.xml file in the <extension>-spring.xml file.
1.  <!-- Process Actions -->

<!-- Adding entry of clavrit-process-spring XML file-->
<import resource="/trainingfulfilmentprocess/process/clavrit-process-spring.xml"/>

<import resource="/trainingfulfilmentprocess/process/order-process-spring.xml"/>
<import resource="/trainingfulfilmentprocess/process/consignment-process-spring.xml"/>
<import resource="/trainingfulfilmentprocess/process/return-process-spring.xml"/>

<!-- Order Check Service -->

  • Write your business logics in the respective Action Classes.
1.  package com.clavrit.fulfilmentprocess.actions.clavrit;

import de.hybris.platform.orderprocessing.model.OrderProcessModel;
import de.hybris.platform.processengine.action.AbstractSimpleDecisionAction;
import org.apache.log4j.Logger;

import java.util.Random;

/***
    @Author         : Bhavik Solanki
    @Position       : SAP Hybris Commerce Cloud Team Lead.
    @Organisation   : Clavrit Digital Solutions
*/

public class ClavritAction1 extends AbstractSimpleDecisionAction<OrderProcessModel> {

    private static final Logger LOG = Logger.getLogger(ClavritAction1.class);
    @Override
    public Transition executeAction(OrderProcessModel orderProcessModel) {

        LOG.info("Inside Clavrit Action 1 in Clavrit Business Process");

        LOG.info("Now we will go to Action 2");
        return Transition.OK;


    }
}

 

package com.clavrit.fulfilmentprocess.actions.clavrit;
import de.hybris.platform.orderprocessing.model.OrderProcessModel;
import de.hybris.platform.processengine.action.AbstractSimpleDecisionAction;
import de.hybris.platform.task.RetryLaterException;
import org.apache.log4j.Logger;

/***
    @Author         : Bhavik Solanki
    @Position       : SAP Hybris Commerce Cloud Team Lead.
    @Organisation   : Clavrit Digital Solutions
*/

public class ClavritAction2 extends AbstractSimpleDecisionAction<OrderProcessModel> {

    private static final Logger LOG = Logger.getLogger(ClavritAction2.class);
    @Override
    public Transition executeAction(OrderProcessModel orderProcessModel) throws RetryLaterException {
        
        //Add your business logic here
        LOG.info("ClavritAction2 class : ExecuteAction Method being called");
        return Transition.OK;
        
    }

}

 

 

package com.clavrit.fulfilmentprocess.actions.clavrit;

import de.hybris.platform.orderprocessing.model.OrderProcessModel;
import de.hybris.platform.processengine.action.AbstractSimpleDecisionAction;
import org.apache.log4j.Logger;

import java.util.Random;

/***
    @Author         : Bhavik Solanki
    @Position       : SAP Hybris Commerce Cloud Team Lead.
    @Organisation   : Clavrit Digital Solutions
*/

public class ClavritAction3 extends AbstractSimpleDecisionAction<OrderProcessModel> {

    private static final Logger LOG = Logger.getLogger(ClavritAction3.class);
    @Override
    public Transition executeAction(OrderProcessModel orderProcessModel) {

        LOG.info("Inside Clavrit Action3 in Clavrit Business Process");

        LOG.info("Now we will go to Action 2");
        return Transition.OK;


    }
}

  • Trigger the process from the functionality from where you want the process to start the execution of our business process.

In our example, we are adding the following method in the LoginPageController.java class and calling the createClavritBusinessProcess method inside the doRegister method in the Controller class.

private void createClavritBusinessProcess(final RegisterForm form){
    final String fulfilmentProcessDefinitationName = "clavrit-process";
    final String processCode = fulfilmentProcessDefinitationName + " - " + form.getEmail() + " - " + System.currentTimeMillis();
    final OrderProcessModel businessProcessModel = businessProcessService.createProcess(processCode,fulfilmentProcessDefinitationName);
    businessProcessService.startProcess(businessProcessModel);
    LOG.info("######## Starting Clavrit Business Process ########");
}

  • Run “Ant Clean All” in the command prompt from the platform.
  • Start the SAP Hybris Commerce Cloud Server.
  • Trigger your business process from the functionality where your startProcess() method is getting called.

In our example, go to the Signup page on StoreFront and fill out the registration form.

HYBRIS COMMERCE CLOUD

RESULT: Our Business Process is getting called and we can see the LOGs getting printed in the Command Prompt

3 1

Retry Mechanism in

SAP Hybris Commerce Cloud

OOTB hybris allows to automatically retry business process action after some time. To do this is enough to set delay in RetryLaterException and throw it. But there is no OOTB implementation of limiting amount of such retries in business processes.

 

To implement the Retry Mechanism, the following changes are required.

Step 1: Add the Retry Transaction

<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
 @Author : Bhavik Solanki
 @Position : SAP Hybris Commerce Cloud Team Lead.
 @Organisation : Clavrit Digital Solutions
-->
<process xmlns="http://www.hybris.de/xsd/processdefinition" start="clavritAction1" name="clavrit-process"
        processClass="de.hybris.platform.orderprocessing.model.OrderProcessModel">

    <action id="clavritAction1" bean="clavritAction1">
       <transition name="OK" to="clavritAction2"/>
       <transition name="NOK" to="clavritAction3"/>
    </action>

    <action id="clavritAction2" bean="clavritAction2">
       <transition name="OK" to="success"/>
       <transition name="NOK" to="error"/>
    </action>

    <action id="clavritAction3" bean="clavritAction3">
       <transition name="OK" to="success"/>
       <transition name="NOK" to="error"/>
       <transition name="RETRY" to="clavritAction2"/>
    </action>

    <end id="error" state="ERROR">Error in Clavrit Process</end>
    <end id="failed" state="FAILED">Failed to execute Clavrit Process</end>
    <end id="success" state="SUCCEEDED">Clavrit Process executed Successfully</end>

</process>

Step 2: Throw a RetryLaterException in the Action Class which you want to execute the retry mechanism.

package com.clavrit.fulfilmentprocess.actions.clavrit;
import de.hybris.platform.orderprocessing.model.OrderProcessModel;
import de.hybris.platform.processengine.action.AbstractSimpleDecisionAction;
import de.hybris.platform.task.RetryLaterException;
import org.apache.log4j.Logger;

/***
    @Author         : Bhavik Solanki
    @Position       : SAP Hybris Commerce Cloud Team Lead.
    @Organisation   : Clavrit Digital Solutions
*/

public class ClavritAction2 extends AbstractSimpleDecisionAction<OrderProcessModel> {

    private static final Logger LOG = Logger.getLogger(ClavritAction2.class);
    @Override
    public Transition executeAction(OrderProcessModel orderProcessModel) throws RetryLaterException {

        boolean isResponseSuccess = false;//callingBusinessLogic(); //Add your business logic here.

        if(isResponseSuccess){
            return Transition.OK;
        }else {
            LOG.info("Clavrit Action 2 Throws Retry Later Exception");
            throw new RetryLaterException(" ####### Clavrit Retry Mechanism ########");
        }
    }

}

 

You can also add a custom logic to limit the number of retry attempts for the Business Process.

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top