Consignment Assignment Workflow

The following describes how Order Management leverages the workflow functionality in order to create a workflow for a consignment and assign its actions to a specific employee.

The goal is to allow an employee to have consignments assigned to their inbox. This agent/employee can then act on the assigned consignment by being able to pick, pack, and confirm the shipment right from the inbox. In turn, the system will make sure that this action is synchronized with the process engine.

Overview

The Consignment Assignment Workflow code flow is redirected through the WarehousingShippingService which in turn delegates the flow to the WarehousingConsignmentWorkflowService. Both UI actions in the Backoffice application and web calls made through the REST layer of Order Management now go through the same services. By doing so, the Consignment Workflow is the orchestrating part in the lifecycle of consignments. Workflow Actions defined in the impex below trigger the business process events.

Define and Start a Workflow for a Consignment

Workflow Definition

The definition of the workflow which will be applied to a consignment is made via impex.

common-addon-extra.impex.impex:
# Consginment WORKFLOW
$lang=en
INSERT_UPDATE WorkflowTemplate;code[unique=true];name[lang=$lang];owner(uid);description[lang=$lang];activationscript;visibleForPrincipals(uid)
;ConsignmentTemplate;Consignment Template;admin;;;admingroup,warehouseadministratorgroup,warehousemanagergroup,warehouseagentgroup
 
INSERT_UPDATE WorkflowActionTemplate;code[unique=true];name[lang=$lang];description[lang=$lang];principalAssigned(uid);workflow(code)[unique=true];sendEmail;emailAddress;rendererTemplate(code);actionType(code)
;NPR_Picking;Picking;;warehouseagentgroup;ConsignmentTemplate;false;;;start
;NPR_Packing;Packing;;warehouseagentgroup;ConsignmentTemplate;false;;;normal
;NPR_Shipping;Shipping;;warehouseagentgroup;ConsignmentTemplate;false;;;normal
;NPR_Pickup;Pick up;;warehouseagentgroup;ConsignmentTemplate;false;;;normal
;NPR_End;End of the Workflow;;warehouseagentgroup;ConsignmentTemplate;false;;;end
 
INSERT_UPDATE AutomatedWorkflowActionTemplate;code[unique=true];name[lang=$lang];description[lang=$lang];principalAssigned(uid);workflow(code)[unique=true];sendEmail;emailAddress;rendererTemplate(code);actionType(code);jobHandler
;NPR_Automated_Packing;Automated Packing;;warehouseagentgroup;ConsignmentTemplate;false;;;normal;taskAssignmentPackConsignmentAction
;NPR_Automated_Shipping;Automated Shipping;;warehouseagentgroup;ConsignmentTemplate;false;;;normal;taskAssignmentShipConsignmentAction
;NPR_Automated_Pickup;Automated Pick up;;warehouseagentgroup;ConsignmentTemplate;false;;;normal;taskAssignmentPickupConsignmentAction
 
INSERT_UPDATE WorkflowDecisionTemplate;code[unique=true];name[lang=$lang];actionTemplate(code);description[allownull=true]
;NPR001;Picked;NPR_Picking;
;NPR002;Packed;NPR_Packing;
;NPR003;Redirect to shipping;NPR_Automated_Packing;
;NPR004;Redirect to pick up;NPR_Automated_Packing;
;NPR005;Shipped;NPR_Shipping;
;NPR006;Automated Shipping;NPR_Automated_Shipping;
;NPR007;Picked up;NPR_Pickup;
;NPR008;Automated Pick up;NPR_Automated_Pickup;
 
INSERT_UPDATE WorkflowActionTemplateLinkTemplateRelation;source(code)[unique=true];target(code)[unique=true];andConnectionTemplate;qualifier
;NPR001;NPR_Packing;false;WorkflowActionTemplateLinkTemplateRelation
;NPR002;NPR_Automated_Packing;false;WorkflowActionTemplateLinkTemplateRelation
;NPR003;NPR_Shipping;false;WorkflowActionTemplateLinkTemplateRelation
;NPR004;NPR_Pickup;false;WorkflowActionTemplateLinkTemplateRelation
;NPR005;NPR_Automated_Shipping;false;WorkflowActionTemplateLinkTemplateRelation
;NPR006;NPR_End;false;WorkflowActionTemplateLinkTemplateRelation
;NPR007;NPR_Automated_Pickup;false;WorkflowActionTemplateLinkTemplateRelation
;NPR008;NPR_End;false;WorkflowActionTemplateLinkTemplateRelation

It is required to define a WorkflowTemplate which contains the structure of the actions that the workflow will go through (WorkflowActionTemplate).

The available decisions which could be made at each step are defined by the WorkflowDecisionTemplate. And some automated workflow actions (AutomatedWorkflowActionTemplate) that is defined for synchronization with the process engine.

The flow is defined by the WorkflowActionTemplateLinkTemplateRelation which tells from a decision which next action or automated action to go to.

Start the Workflow

In our case, the workflow of a consignment will start as soon as we create the object. For this reason, the starting point of the workflow is in the DefaultAllocationService.

At the end of the createConsignment method, we call the startConsignmentWorkflow method which will start the workflow in the WarehousingConsignmentWorkflowService.

DefaultWarehousingConsignmentWorkflowService.java:
...
@Override
 
public void startConsignmentWorkflow(final ConsignmentModel consignment)
{
  validateParameterNotNullStandardMessage("consignment", consignment);
  final String consignmentWorkflowName = getConfigurationService().getConfiguration().getString(CONSIGNMENT_TEMPLATE_NAME);
 
  try
  {
    final WorkflowTemplateModel workflowTemplate = getWorkflowTemplateService()
        .getWorkflowTemplateForCode(consignmentWorkflowName);
    if (workflowTemplate != null)
    {
      final WorkflowModel workflow = getWorkflowService()
          .createWorkflow(WORKFLOW_OF_CONSIGNMENT + consignment.getCode(), workflowTemplate,
              Collections.singletonList(consignment), getUserService().getAdminUser());
      getModelService().save(workflow);
      consignment.setTaskAssignmentWorkflow(workflow.getCode());
      getModelService().save(consignment);
      workflow.getActions().forEach(action -> getModelService().save(action));
      getWorkflowProcessingService().startWorkflow(workflow);
      final UserModel finalSelectedUser = getUserSelectionStrategy().getUserForConsignmentAssignment(workflow);
      workflow.setOwner(finalSelectedUser);
      workflow.getActions().forEach(action ->
      {
        action.setPrincipalAssigned(finalSelectedUser);
        getModelService().save(action);
      });
      getModelService().save(workflow);
      LOGGER.info(format(getLocalizedString("warehousing.taskassignment.workflow.employee.is.assigned.to.consignment"),
          finalSelectedUser.getDisplayName(), consignment.getCode()));
    }
    else
    {
      LOGGER.debug(getLocalizedString("warehousing.taskassignment.workflow.no.template.found"));
    }
  }
  catch (final UnknownIdentifierException | IllegalArgumentException e)  //NOSONAR
  {
    LOGGER.debug(format(getLocalizedString("warehousing.taskassignment.workflow.no.template.found.for.code"),
        consignmentWorkflowName));
  }
  catch (final ModelSavingException e)  //NOSONAR
  {
    LOGGER.debug(getLocalizedString("warehousing.taskassignment.workflow.no.principle.assigned"));
  }
}
    ....

Link Employees to Warehouses

To find a proper set of employees to assign the consignment task to, there is some employee data for our sample warehouses. To do so, we populate PoS2WarehouseRel with a set of our warehouses to make sure that all our sample warehouses have a POS assigned. Also, we added a few more StoreEmployeeGroup(s) and a new list of warehouse agents corresponding to the POS. Furthermore, we created some sample employees with login access to the Backoffice Order Fulfillment Cockpit where the consignments will be assigned and shown in the inbox section for assigned employees.

Synchronization from Task Assignment Workflow to Process Engine

The Task Assignment Workflow now synchronizes the Process Engine from both the UI actions in Backoffice and the REST calls available in Order Management. This is achieved by calling the WarehousingShippingService which then calls the WarehousingConsignmentWorkflowService. This service decides the next workflow action to be performed in the workflow. To synchronize with the process engine, an automated workflow template job is used when moving from one state of the workflow to another. For instance, once an employee packs a consignment, the status of this consignment is decided by the action depending on the type of the consignment either shipping or pickup. The status is therefore set to either Ready to be Shipped or Ready to be Picked Up. Here is how this is accomplished:

TaskAssignmentPackConsignmentAction.java:
/**
 * Synchronizes the pack consignment action from the Task Assignment Workflow of an employee to the main process engine.
 */
public class TaskAssignmentPackConsignmentAction extends AbstractTaskAssignmentActions
{
  private static final Logger LOGGER = LoggerFactory.getLogger(TaskAssignmentPackConsignmentAction.class);
 
  protected static final String CONSIGNMENT_ACTION_EVENT_NAME = "ConsignmentActionEvent";
  protected static final String PACK_CONSIGNMENT_CHOICE = "packConsignment";
  protected static final String SHIPPING_DECISION = "Shipping";
  protected static final String PACKING_TEMPLATE_CODE = "NPR_Packing";
 
  @Override
  public WorkflowDecisionModel perform(final WorkflowActionModel workflowAction)
  {
    final Optional<ItemModel> attachedConsignmentOptional = getAttachedConsignment(workflowAction);
    WorkflowDecisionModel result = null;
 
    if (attachedConsignmentOptional.isPresent())
    {
      final ConsignmentModel attachedConsignment = (ConsignmentModel) attachedConsignmentOptional.get();
      final WorkflowActionModel packingWorkflowAction = getWarehousingConsignmentWorkflowService()
          .getConsignmentTaskForTemplateCode(PACKING_TEMPLATE_CODE, attachedConsignment);
 
      assignNewPrincipalToAction(workflowAction, packingWorkflowAction);
 
      LOGGER.info("Consignment: " + attachedConsignment.getCode() + " has been packed by: " + packingWorkflowAction
          .getPrincipalAssigned().getDisplayName());
      getConsignmentBusinessProcessService()
          .triggerChoiceEvent(attachedConsignment, CONSIGNMENT_ACTION_EVENT_NAME, PACK_CONSIGNMENT_CHOICE);
 
      final boolean shippingConsignment = attachedConsignment.getDeliveryPointOfService() == null;
 
      // determine which decision to return whether the consignment is a pick up or shipping.
      Optional<WorkflowDecisionModel> decisionModel;
      if (shippingConsignment)
      {
        decisionModel = workflowAction.getDecisions().stream()
            .filter(decision -> SHIPPING_DECISION.equals(decision.getToActions().iterator().next().getName())).findFirst();
      }
      else
      {
        decisionModel = workflowAction.getDecisions().stream()
            .filter(decision -> !SHIPPING_DECISION.equals(decision.getToActions().iterator().next().getName())).findFirst();
      }
 
      result = decisionModel.isPresent() ? decisionModel.get() : null;
    }
    return result;
  }
 
}

Following the packing of a consignment it can then be shipped. Its status is then set to Shipped and the main process engine ends:

TaskAssignmentShipConsignmentAction.java:
/**
 * Synchronizes the ship consignment action from the Task Assignment Workflow of an employee to the main process engine.
 */
public class TaskAssignmentShipConsignmentAction extends AbstractTaskAssignmentActions
{
  private static final Logger LOGGER = LoggerFactory.getLogger(TaskAssignmentShipConsignmentAction.class);
  protected static final String CONSIGNMENT_ACTION_EVENT_NAME = "ConsignmentActionEvent";
  protected static final String CONFIRM_SHIP_CONSIGNMENT_CHOICE = "confirmShipConsignment";
  protected static final String SHIPPING_TEMPLATE_CODE = "NPR_Shipping";
 
  @Override
  public WorkflowDecisionModel perform(final WorkflowActionModel workflowAction)
  {
    WorkflowDecisionModel result = null;
 
    if (getAttachedConsignment(workflowAction).isPresent())
    {
      final ConsignmentModel attachedConsignment = (ConsignmentModel) getAttachedConsignment(workflowAction).get();
      final WorkflowActionModel shippingWorkflowAction = getWarehousingConsignmentWorkflowService()
          .getConsignmentTaskForTemplateCode(SHIPPING_TEMPLATE_CODE, attachedConsignment);
 
      assignNewPrincipalToAction(workflowAction, shippingWorkflowAction);
 
      LOGGER.info(
          "Consignment: " + attachedConsignment.getCode() + " has been shipped by: " + workflowAction.getPrincipalAssigned()
              .getDisplayName());
      getConsignmentBusinessProcessService()
          .triggerChoiceEvent(attachedConsignment, CONSIGNMENT_ACTION_EVENT_NAME, CONFIRM_SHIP_CONSIGNMENT_CHOICE);
 
      result = workflowAction.getDecisions().size() != 0 ? workflowAction.getDecisions().iterator().next() : null;
    }
    return result;
  }
}

Similarly, if a consignment is packed but it is a pick up, another automated action will take care of the synchronization:

TaskAssignmentShipConsignmentAction.java:
/**
 * Synchronizes the ship consignment action from the Task Assignment Workflow of an employee to the main process engine.
 */
public class TaskAssignmentShipConsignmentAction extends AbstractTaskAssignmentActions
{
  private static final Logger LOGGER = LoggerFactory.getLogger(TaskAssignmentShipConsignmentAction.class);
  protected static final String CONSIGNMENT_ACTION_EVENT_NAME = "ConsignmentActionEvent";
  protected static final String CONFIRM_SHIP_CONSIGNMENT_CHOICE = "confirmShipConsignment";
  protected static final String SHIPPING_TEMPLATE_CODE = "NPR_Shipping";
 
  @Override
  public WorkflowDecisionModel perform(final WorkflowActionModel workflowAction)
  {
    WorkflowDecisionModel result = null;
 
    if (getAttachedConsignment(workflowAction).isPresent())
    {
      final ConsignmentModel attachedConsignment = (ConsignmentModel) getAttachedConsignment(workflowAction).get();
      final WorkflowActionModel shippingWorkflowAction = getWarehousingConsignmentWorkflowService()
          .getConsignmentTaskForTemplateCode(SHIPPING_TEMPLATE_CODE, attachedConsignment);
 
      assignNewPrincipalToAction(workflowAction, shippingWorkflowAction);
 
      LOGGER.info(
          "Consignment: " + attachedConsignment.getCode() + " has been shipped by: " + workflowAction.getPrincipalAssigned()
              .getDisplayName());
      getConsignmentBusinessProcessService()
          .triggerChoiceEvent(attachedConsignment, CONSIGNMENT_ACTION_EVENT_NAME, CONFIRM_SHIP_CONSIGNMENT_CHOICE);
 
      result = workflowAction.getDecisions().size() != 0 ? workflowAction.getDecisions().iterator().next() : null;
    }
    return result;
  }
}

Similarly, if a consignment is packed but it is a pick up, another automated action will take care of the synchronization:

TaskAssignmentPickupConsignmentAction.java:
/***
 * Synchronizes the pickup consignment action from the Task Assignment Workflow of an employee to the main process engine.
 */
public class TaskAssignmentPickupConsignmentAction extends AbstractTaskAssignmentActions
{
  private static final Logger LOGGER = LoggerFactory.getLogger(TaskAssignmentPickupConsignmentAction.class);
  protected static final String CONSIGNMENT_ACTION_EVENT_NAME = "ConsignmentActionEvent";
  protected static final String CONFIRM_PICKUP_CONSIGNMENT_CHOICE = "confirmPickupConsignment";
  protected static final String PICKUP_TEMPLATE_CODE = "NPR_Pickup";
 
  @Override
  public WorkflowDecisionModel perform(final WorkflowActionModel workflowAction)
  {
    WorkflowDecisionModel result = null;
 
    if (getAttachedConsignment(workflowAction).isPresent())
    {
      final ConsignmentModel attachedConsignment = (ConsignmentModel) getAttachedConsignment(workflowAction).get();
      final WorkflowActionModel pickupWorkflowAction = getWarehousingConsignmentWorkflowService()
          .getConsignmentTaskForTemplateCode(PICKUP_TEMPLATE_CODE, attachedConsignment);
 
      assignNewPrincipalToAction(workflowAction, pickupWorkflowAction);
 
      LOGGER.info("Consignment: " + attachedConsignment.getCode() + " has been picked up by: " + workflowAction
          .getPrincipalAssigned().getDisplayName());
      getConsignmentBusinessProcessService()
          .triggerChoiceEvent(attachedConsignment, CONSIGNMENT_ACTION_EVENT_NAME, CONFIRM_PICKUP_CONSIGNMENT_CHOICE);
 
      result = workflowAction.getDecisions().size() != 0 ? workflowAction.getDecisions().iterator().next() : null;
    }
 
    return result;
  }
}

Backoffice Configuration

Below is the Backoffice configuration used to display this newly added Inbox section.

warehousingbackoffice-backoffice-config.xml:
...
    <!-- Explorer Tree-->
   <context component="warehousingbackoffice-explorer-tree">
       <n:explorer-tree xmlns:n="http://www.hybris.com/cockpitng/config/explorertree">
           <n:navigation-node id="warehousing.treenode.taskassignment.inbox"/>
...
        </n:explorer-tree>
    </context>
...
  
<!--Refine By -->
<context type="WorkflowAction" component="warehousingbackoffice-refine-by">
    <rb:refine-by xmlns:rb="http://www.hybris.com/warehousingbackoffice/config/warehousingrefineby">
        <rb:field-list>
            <rb:search-field name="template">
                <rb:search-value uniqueValue="NPR_Picking"/>
                <rb:search-value uniqueValue="NPR_Packing"/>
                <rb:search-value uniqueValue="NPR_Shipping"/>
                <rb:search-value uniqueValue="NPR_Pickup"/>
            </rb:search-field>
        </rb:field-list>
    </rb:refine-by>
</context>
  
...
  
<!--Simple Search & Advanced Search -->
<context merge-by="type" parent="GenericItem" type="WorkflowAction" component="simple-search">
    <simple-search:simple-search xmlns:simple-search="http://www.hybris.com/cockpitng/config/simplesearch">
        <field xmlns="http://www.hybris.com/cockpitng/config/simplesearch" name="name" />
    </simple-search:simple-search>
</context>
 
<context type="WorkflowAction" component="advanced-search" merge-by="type">
    <as:advanced-search xmlns:as="http://www.hybris.com/cockpitng/config/advancedsearch" connection-operator="OR">
        <as:field-list disable-attributes-comparator="false" disable-subtypes-checkbox="false">
            <as:field name="status" selected="true" operator="equals"/>
            <as:field name="workflow" selected="false" operator="equals"/>
            <as:field name="template" selected="true"/>
        </as:field-list>
        <as:sort-field name="attachmentItems[0].shippingDate" asc="true" />
    </as:advanced-search>
</context>
...
  
<!-- List View-->
<context type="WorkflowAction" component="warehousingbackofficetaskassignmentlistview">
    <list:list-view xmlns:list="http://www.hybris.com/cockpitng/component/listView">
        <list:column qualifier="template" label="warehousingbackoffice.taskassignment.action"/>
        <list:column qualifier="attachmentItems[0].code" label="warehousingbackoffice.consignment.consignmentnumber"/>
        <list:column qualifier="attachmentItems[0].order.code" label="warehousingbackoffice.consignment.order.number"/>
        <list:column qualifier="attachmentItems[0].shippingDate" label="warehousingbackoffice.consignment.expectedtoship"
                     sortable="true" spring-bean="nullSafeListCellRenderer"/>
        <list:column qualifier="attachmentItems[0].deliveryMode" label="warehousingbackoffice.warehouses.deliveryMode.code"/>
        <list:column spring-bean="consignmentMenuRenderer" label="warehousingbackoffice.taskassignment.menu"/>
    </list:list-view>
</context>
...
  
<context type="WorkflowAction" component="collection-browser">
    <cb:collection-browser xmlns:cb="http://www.hybris.com/cockpitng/config/collectionbrowser">
        <cb:available-molds>
            <cb:mold spring-bean="listViewCollectionBrowserMoldStrategy"/>
        </cb:available-molds>
    </cb:collection-browser>
</context>
  
...
  
<!-- Quick List -->
<context type="WorkflowAction" component="warehousingbackoffice-quick-list">
    <quick-list:quick-list xmlns:quick-list="http://www.hybris.com/cockpitng/component/quick-list"/>
</context>
  
...
<context component="warehouseListviewActions" type="WorkflowAction">
    <y:actions xmlns:y="http://www.hybris.com/cockpit/config/hybris">
        <y:group qualifier="common">
            <y:label>actiongroup.common</y:label>
            <y:action action-id="com.hybris.cockpitng.listview.action.export.csv" property="exportColumnsAndData"/>
            <y:action action-id="de.hybris.platform.warehousingbackoffice.actions.taskassignment.done.doneaction"
                      property="selectedObjects"/>
        </y:group>
    </y:actions>
</context>