tpiekarski / coupon-engine

Prototype for a Coupon-Engine driven by Easy Rules and Spring Expression Language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coupon Engine Prototype

Build Status Quality Gate Status Coverage Status

A prototype for evaluating coupon rules driven by Easy Rules and Spring Expression Language providing a simple CLI for testing and developing.

  1. Introduction
  2. Prototyped Rules
  3. Build
  4. Dependencies
  5. Usage
  6. JSON Input Examples

Introduction

This prototype leverages Easy Rules and Spring Expression language for evaluation of coupon rules defined in JSON files with an easy and expressive way of defining multiple rules. A set of n rules and their options, like a coupon code, a category of products or a minimum cart value are evaluated based upon a cart defined in another JSON file.

The processing is divided into two distinct scopes. The first scope is validation scope, in which the coupon is checked for validity. For example if the provided code is valid or if a coupon is not yet expired. The second scope is application, in which a valid coupon is checked for application to a cart and its items.

Prototyped Rules

Rule Option Scope Description
Category Name of category Application Rule for evaluating if products are from one category
Exclude Product SKU Application Rule to exclude a product SKU
Expiration Date (YYYY-mm-dd, i.e. 2018-01-01) Validation Rule for an expiration date
MinimumCartValue Minimum Amount (Integer-based price) Validation Rule for a minimum cart value
ValidCode String containing a coupon code Validation Rule for evaluation valid coupon codes

Build

mvn package

Dependencies

# Dependency Version
1. Apache Commons IO 2.6
2. Apache Maven Shade Plugin 3.1.0
3. Maven Coveralls Plugin 4.3.0
4. Easy Rules Core 3.0.0
5. FasterXML Jackson Core 2.9.10.4
6. Google Guice Inject 4.1.0
7. Jacoco 0.7.7.201606060606
8. jUnit 4.12
9. Pitest 1.2.4
10. Spring Expression Language 5.0.1

Usage

General system-independent usage

java -jar target/coupon-prototype-0.2.2-shaded.jar --cart examples/cart.json --coupon examples/coupon.json

U*NIX-based systems launcher

./coupon-cli.sh --cart examples/cart.json --coupon examples/coupon.json

Windows-based systems launcher

coupon-cli.bat --cart examples/cart.json --coupon examples/coupon.json

CLI & Parameters

java -jar target/coupon-prototype-0.2.2-shaded.jar --verbose --cart examples/cart.json --coupon examples/coupon.json

Parameter (Long) Parameter (Short) Parameter (Windows) Input Description
--cart -c /C <cart.json> JSON file defining a cart
--coupon -p /P <coupon.json> JSON file defining a coupon
--verbose -v /V - Optional boolean for silencing easy rules (default is true)

JSON Input Examples

Carts

{
  "value": 100,
  "code": "ABC",
  "items": [
    {
      "sku": "E1000-001",
      "category": "Cheese",
      "price": 50
    },
    {
      "sku": "E1000-010",
      "category": "Cheese",
      "price": 50
    }
  ]
}

Coupons

{
  "discount": 20,
  "type": "percentage",
  "validation": {
      "rules": [
        {
          "rule": "ValidCode",
          "option": "ABC"
        },
        {
          "rule": "MinimumCartValue",
          "option": "35"
        },
        {
          "rule": "Expiration",
          "option": "2018-01-01"
        }
      ],
      "expression": "#ValidCode and #MinimumCartValue and #Expiration"
    },
  "application": {
    "rules": [
      {
        "rule": "Category",
        "option": "Cheese"
      },
      {
        "rule": "Exclude",
        "option": "E1000-020"
      }
    ],
    "expression": "#Category and #Exclude"
  }
}

About

Prototype for a Coupon-Engine driven by Easy Rules and Spring Expression Language


Languages

Language:Java 98.5%Language:Shell 0.9%Language:Batchfile 0.6%