Class TrackingCodeBuilder

java.lang.Object
com.avoka.tm.svc.TrackingCodeBuilder

public class TrackingCodeBuilder extends Object

Provides a unique random tracking code builder.

The build method will ensure the tracking number is globally unique across both transaction and transaction history tables. If an existing tracking code is found, the build method will continue to generate a new tracking codes until it has created a globally unique value. If a unique value has not been generated after 100 attempts a IllegalArgumentException will be thrown.

Examples

Please find the tracking code builder examples below.

Create Transaction Tracking Code

The example below is creating an unique transaction tracking code and prefixing it with the form code and postfixing it with a test environment indicator.

 class FluentTrackingNumberService {

     String invoke(SvcDef svcDef, Form form, HttpServletRequest request, User user) {

         return new TrackingCodeBuilder()
             .setPrefix(form.formCode + "-")
             .setPostfix("-TEST")
             .build()
     }

 } 
Since:
5.0.0
  • Constructor Details

    • TrackingCodeBuilder

      public TrackingCodeBuilder()
  • Method Details

    • setPrefix

      public TrackingCodeBuilder setPrefix(String prefix)
      Set the tracking code value to prefix random component.
      Parameters:
      prefix - the tracking code prefix
      Returns:
      the tracking code builder
    • setPostfix

      public TrackingCodeBuilder setPostfix(String postfix)
      Set the tracking code value to postfix random component.
      Parameters:
      postfix - the tracking code post
      Returns:
      the tracking code builder
    • setRandomLength

      public TrackingCodeBuilder setRandomLength(int randomLength)
      Set the random component character length. The default length is 7.
      Parameters:
      randomLength - the random component character length
      Returns:
      the tracking code builder
    • setRandomChars

      public TrackingCodeBuilder setRandomChars(String randomChars)
      Set the character values to be used in the random component. The default values include: BCDFGHJKLMNPQRSTVWXYZ23456789
      Parameters:
      randomChars - the character values to be used in the random component.
      Returns:
      the tracking code builder
    • trackingCodeExists

      public boolean trackingCodeExists(String trackingCode)
      Return true if the specified tracking code is already used.
      Parameters:
      trackingCode - the tracking code value to check (must not be null or an empty string)
      Returns:
      true if the tracking code value is already in use or there was an error during lookup
    • build

      public String build()

      Return a new random transaction tracking code (tracking number) for the specified properties.

      This method will ensure the tracking number is globally unique across both transaction and transaction history tables. If an existing tracking code is found, this method will continue to generate a new tracking codes until a globally unique value is found. If this method cannot generate a unique value after 10 attempts it will throw an IllegalArgumentException

      If a unique tracking code is found, the code is also stored in the tracking_number table that records all unique codes.

      Returns:
      new random transaction tracking code (tracking number) for the specified properties.