Class Voucher

All Implemented Interfaces:
Serializable, Comparable
Direct Known Subclasses:
GeneratedPromotionVoucher, GeneratedSerialVoucher

public abstract class Voucher extends GeneratedVoucher
The vouchers are redeemed on the total value of an order.

The calculation of the discount is done on the total value of the applicable product's prices,

inclusive of VAT.

Non-applicable products in the order are not subject to the discount rules.

To discover to which products in the order the voucher is applicable one could assign

various restrictions to the voucher.

See Also:
  • Field Details

  • Constructor Details

    • Voucher

      public Voucher()
  • Method Details

    • createItem

      protected Item createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes) throws JaloBusinessException
      Description copied from class: Item
      Has to be implemented for each concrete subtype of item. This method is responsible for creating a new item instance ( by calling managers, ejb homes, etc. ) during ComposedType.newInstance(Map).

      In case this method uses any of the attribute values during creation it is required to override Item.getNonInitialAttributes(SessionContext, ItemAttributeMap) too.
      Sn example:

      
       public static final String MY_ATTRIBUTE = "someAttribute"; ... protected Item createItem(SessionContext
       ctx, ComposedType type, Map allAttributes ) throws JaloBusinessException { MyManager man = ... return
       man.createMyItem( (String)allAttributes.get(MY_ATTRIBUTE) );
       // here MY_ATTRIBUTE is used for creation, so it must not be set again } protected Map getNonInitialAttributes(
       SessionContext ctx, Map allAttributes ) { // let superclass remove its own initial attributes Map ret =
       super.getNonInitialAttributes( ctx, allAttributes );
       // remove MY_ATTRIBUTE from all attributes since if has already been set ret.remove(MY_ATTRIBUTE); return ret; }
      
       
      Overrides:
      createItem in class Discount
      Parameters:
      ctx - the current session context which this item is created within
      type - the actual item type ( since subtypes may not provide a own jalo class this may be different from the type which this method was implemented for )
      Returns:
      the new item instance
      Throws:
      JaloBusinessException - indicates an error during creation - any changes will be rollbacked
    • remove

      public void remove(SessionContext ctx) throws ConsistencyCheckException
      Description copied from class: Item
      Removes this item.

      This method is using the following attributes of the given SessionContext:

      CacheUsage   Language   StagingMethod
      n/a (this is a setter method)   no, language doesn't matter for removal   yes if called on a StageableItem, no otherwise


      Overrides:
      remove in class Item
      Parameters:
      ctx - A SessionContext object
      Throws:
      ConsistencyCheckException - if this item could not be removed for some reason
    • removeInvalidations

      protected void removeInvalidations(SessionContext ctx)
      Upon voucher removal this method deletes all VoucherInvalidation items which belong to this voucher.
      Parameters:
      ctx -
    • createAndStoreKey

      protected void createAndStoreKey(SessionContext ctx, Discount item)
    • createVoucherInvalidation

      public VoucherInvalidation createVoucherInvalidation(String aVoucherCode, Order anOrder)
    • checkVoucherCode

      public abstract boolean checkVoucherCode(String aVoucherCode)
      Returns true if the specified voucher code is valid for this voucher.
      Parameters:
      aVoucherCode - the voucher code to check validity of.
      Returns:
      true if the specified voucher code is valid for this voucher, false else.
    • getApplicableEntries

      public VoucherEntrySet getApplicableEntries(AbstractOrder anOrder)
      Returns all positions or parts of positions of the specified abstract order that are eligible for this voucher.
      Parameters:
      anOrder - the abstract order to get eligible positions of.
      Returns:
      a VoucherEntrySet containing a VoucherEntry object for every position that is fully or partly eligible for this voucher.
    • getApplicableValue

      protected VoucherValue getApplicableValue(AbstractOrder anOrder)
      Returns a VoucherValue object representing the partial value of the total of the specified abstract order that is eligible for this voucher. Typically this would correspond to the sum of all totals of the applicable entries.
      Parameters:
      anOrder - the abstract order to get applicable value of.
      Returns:
      a VoucherValue representing the partial value of the total of the specified abstract order that is eligible for this voucher.
    • getAppliedValue

      public VoucherValue getAppliedValue(AbstractOrder anOrder)
      Returns a VoucherValue object representing the discount value of this voucher. If the voucher is applicable to the specified abstract order this value is calculated in consideration of the applicable value returned by getApplicableValue(AbstractOrder).
      Parameters:
      anOrder - the abstract order to get discount value of.
      Returns:
      a VoucherValue representing the discount value of this voucher.
    • getComposedType

      protected ComposedType getComposedType(Class aClass)
    • getDiscountValue

      public DiscountValue getDiscountValue(AbstractOrder anOrder)
      Description copied from class: Discount
      Calculates a value which should be applied to the given order during (re)calculation.
      Overrides:
      getDiscountValue in class Discount
      Parameters:
      anOrder - the order which is currently being calculated
    • getInvalidation

      protected VoucherInvalidation getInvalidation(String aVoucherCode, Order anOrder)
      Returns a voucher invalidation object if the specified voucher code was used in the specified order or null else.
      Parameters:
      aVoucherCode - the voucher code to check.
      anOrder - the order to check.
      Returns:
      a VoucherInvalidation object representing the usage of a voucher code in an order.
    • getInvalidations

      protected Collection<VoucherInvalidation> getInvalidations(String aVoucherCode)
      Returns all voucher invalidations representing the usage of the specified voucher code. If voucher code represents a serial voucher the returned collection should not contain more than one item since serial voucher codes can only be used once.
      Parameters:
      aVoucherCode - the voucher code to check
      Returns:
      a Collection containing none, one or more VoucherInvalidation objects.
    • getInvalidations

      protected Collection<VoucherInvalidation> getInvalidations(String aVoucherCode, User anUser)
      Returns all voucher invalidations representing the usage of the specified voucher code by the specified user. If voucher code represents a serial voucher the returned collection should not contain more than one item since serial voucher codes can only be used once.
      Parameters:
      aVoucherCode - the voucher code to check
      anUser - the user to check
      Returns:
      a Collection containing none, one or more VoucherInvalidation objects.
    • getValueString

      public String getValueString(SessionContext ctx)
      Convenience method. Returns a string representation of the value of this voucher, e.g. 5$ or 10%.
      Specified by:
      getValueString in class GeneratedVoucher
      Parameters:
      ctx - the context of the actual session
      Returns:
      a String representing the alue of this voucher.
    • getViolatedRestrictions

      public List<Restriction> getViolatedRestrictions(AbstractOrder anOrder)
      Returns all restrictions that are not fulfilled by the specified abstract order.
      Parameters:
      anOrder - the abstract order to return violated restrictions for.
      Returns:
      a List object containing all Restriction objects associated with this voucher that the specified abstract order does not fulfill.
    • getViolatedRestrictions

      public List<Restriction> getViolatedRestrictions(Product aProduct)
      Returns all restrictions that are not fulfilled by the specified product.
      Parameters:
      aProduct - the product to return violated restrictions for.
      Returns:
      a List object containing all Restriction objects associated with this voucher that the specified product does not fulfill.
    • getViolationMessages

      public List<String> getViolationMessages(AbstractOrder anOrder)
    • getViolationMessages

      public List<String> getViolationMessages(Product aProduct)
    • getVoucherValue

      public VoucherValue getVoucherValue(AbstractOrder anOrder)
    • isApplicable

      public boolean isApplicable(AbstractOrder anOrder)
      Returns true if the specified abstract order is eligible for this voucher. More formally, returns true if the specified abstract order fulfills all restrictions associated with this voucher.
      Parameters:
      anOrder - the abstract order to check whether it is eligible for this voucher.
      Returns:
      true if the specified abstract order is eligible for this voucher, false else.
    • isApplicable

      public boolean isApplicable(Product aProduct)
      Returns true if the specified product is eligible for this voucher. More formally, returns true if the specified product fulfills all restrictions associated with this voucher.
      Parameters:
      aProduct - the product to check whether it is eligible for this voucher.
      Returns:
      true if the specified product is eligible for this voucher, false else.
    • isReservable

      public abstract boolean isReservable(String aVoucherCode, User user)
    • isReservable

      public boolean isReservable(String aVoucherCode, AbstractOrder abstractOrder)
    • redeem

      public boolean redeem(String aVoucherCode, Cart aCart) throws JaloPriceFactoryException
      Throws:
      JaloPriceFactoryException
    • redeem

      public VoucherInvalidation redeem(String aVoucherCode, Order anOrder)
    • release

      public void release(String aVoucherCode, Order anOrder) throws ConsistencyCheckException
      Throws:
      ConsistencyCheckException
    • release

      public void release(String aVoucherCode, Cart aCart) throws JaloPriceFactoryException
      Throws:
      JaloPriceFactoryException
    • reserve

      public VoucherInvalidation reserve(String aVoucherCode, Order anOrder)
    • insertDividers

      protected static String insertDividers(String voucherCode)
    • removeDividers

      protected static String removeDividers(String voucherCode)
    • generateVoucherCode

      public String generateVoucherCode() throws NoSuchAlgorithmException
      Throws:
      NoSuchAlgorithmException
    • getNextVoucherNumber

      protected abstract int getNextVoucherNumber(SessionContext ctx)
    • getVoucherNumber

      protected int getVoucherNumber(String voucherCode) throws Voucher.InvalidVoucherKeyException
      Throws:
      Voucher.InvalidVoucherKeyException
    • threeByteSig

      protected String threeByteSig(String sigText) throws NoSuchAlgorithmException
      Throws:
      NoSuchAlgorithmException