Class NumberSeriesManager

java.lang.Object
de.hybris.platform.jalo.Manager
de.hybris.platform.jalo.numberseries.NumberSeriesManager
All Implemented Interfaces:
ItemLifecycleListener, Serializable

public class NumberSeriesManager extends Manager
This is the extension manager of the NumberSeries extension.
A number series is a sequence of unique numbers identified by a unique key. Before using a series you have to create it using the createNumberSeries(String, String, int, int) method. With that you create a new series identified by a unique key where the series starts at the specified start value and contains of specified number of digits. The type of a series specified whether it is numeric using NumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERIC (consisting only of digits) or alpha numeric using NumberGenerator.NumberSeriesConstants.TYPES.NUMERIC (consisting of letters too). The digits and start value will be stored persistent for a series.
For getting the next number of a series you can simply call getUniqueNumber(String). For resetting a series to a specific start value you can call resetNumberSeries(String, String, int). The setDigits(String, int) method can be called any time for changing the length of the generated numbers. The setStartValue(String, String) should not be called, the property is only used for storing the original start value of a series and will have no effect after series creation. It only is useful if storing a new start value for a later resetting of the series using the stored start value.
See Also:
  • Field Details

    • BEAN_NAME

      public static final String BEAN_NAME
      Identifier of this manager used at core-spring.xml spring configuration.
      See Also:
    • CONFIG_PARAM_NUMBER_CACHE

      public static final String CONFIG_PARAM_NUMBER_CACHE
      Allows to set number series cache size globally and per series:
       # set global cache size
       numberseries.cache.size=100
      
       # set custom cache size for a single series
       numberseries.cache.size.mySeries=1
       
      See Also:
    • DEFAULT_NUMBER_CACHE_SIZE

      public static final int DEFAULT_NUMBER_CACHE_SIZE
      Default cache size for number series. The cache size specifies the number of numbers fetched at once.
      See Also:
  • Constructor Details

    • NumberSeriesManager

      public NumberSeriesManager()
  • Method Details

    • getInstance

      public static NumberSeriesManager getInstance()
      Gets the instance of this manager.
      Returns:
      instance of this manager
    • checkBeforeItemRemoval

      protected void checkBeforeItemRemoval(SessionContext ctx, Item item) throws ConsistencyCheckException
      Superclass method overridden to avoid calls to ejb layer.
      Overrides:
      checkBeforeItemRemoval in class Manager
      Parameters:
      ctx - the current session context
      item - the item which should be removed
      Throws:
      ConsistencyCheckException - thrown to abort removal due to consistency errors
      Since:
      2.10
    • notifyItemRemoval

      protected void notifyItemRemoval(SessionContext ctx, Item item)
      Superclass method overridden to avoid calls to ejb layer.
      Overrides:
      notifyItemRemoval in class Manager
      Parameters:
      ctx - the currency session context
      item - the item which is going to be removed
      Since:
      2.10
    • getUniqueNumber

      public String getUniqueNumber(String key, int digits) throws JaloInvalidParameterException
      Returns a unique number for a given series key and a digit length. Assure that a number series with given key was created before.
      Parameters:
      key - the key of the number series, e.g. "Order"
      digits - the length of the result number string; if the actual number is smaller it will be filled with leading '0's - but if it is larger it wont be truncated !
      Throws:
      JaloInvalidParameterException - if a number series with given key is unknown
    • checkDigits

      protected int checkDigits(String key, int digits)
      Checks digits and if digits < 0 fetches default digits for given series key.
      Parameters:
      key - the series key
      digits - the given digits
    • getUniqueNumber

      public String getUniqueNumber(String key) throws JaloInvalidParameterException
      Returns a unique number for a given number series key. The digit length is taken from previous value. Assure that a number series with given key was created before.
      Parameters:
      key - the key of the number series, e.g. "Order"
      Throws:
      JaloInvalidParameterException - if a number series with given key is unknown
    • getUniqueNumberUnformatted

      public NumberSeries getUniqueNumberUnformatted(String key) throws JaloInvalidParameterException
      Returns the unique number object rather than its formatted representation (see getUniqueNumber(String, int). Use as follows:
       NumberSeries ns = NumberSeriesManager.getInstance().getUniqueNumberUnformatted("fooSeries");
       // get 10 digits text
       String number10 = ns.getFormatted(10);
       // get real number
       long number = ns.getCurrentNumber();
       
      Parameters:
      key - the number series key
      Throws:
      JaloInvalidParameterException - if no series exists for key
    • removeNumberSeries

      public void removeNumberSeries(String key) throws JaloInvalidParameterException
      Removes a number series and removes the digits and start value setting for this series.
      Parameters:
      key - the key of the number series, e.g. "Order"
      Throws:
      JaloInvalidParameterException
    • createNumberSeries

      @Deprecated(since="5.0", forRemoval=false) public NumberSeries createNumberSeries(String key, String startValue, int type) throws JaloInvalidParameterException
      Deprecated.
      Creates a number series and sets the start value via setStartValue(String, String). Call setDigits(String, int) to assure that the right digits are set or use createNumberSeries(String, String, int, int). Otherwise you may get an exception on other moduls like hybris platform hmc.
      Parameters:
      key - the key of the number series, e.g. "Order"
      startValue - the star value of this serie: numeric series must have a Long parseable value, alphanumeric must match ['0'..'9''A'..'Z']*
      type - one of NumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERIC and NumberGenerator.NumberSeriesConstants.TYPES.NUMERIC
      Throws:
      JaloInvalidParameterException
    • createNumberSeries

      public NumberSeries createNumberSeries(String key, String startValue, int type, int digits, String template) throws JaloInvalidParameterException
      Creates a new number series, sets the given start value via setStartValue(String, String) and the given digits via setDigits(String, int) persistent.
      Parameters:
      key - the number series key.
      startValue - the number series start value.
      type - the number series type NumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERIC or NumberGenerator.NumberSeriesConstants.TYPES.NUMERIC
      digits - the number of digits
      template - the template to be applied on generated value
      Returns:
      A NumberSeries object.
      Throws:
      JaloInvalidParameterException - if there is no series registered for given key
    • createNumberSeries

      @Deprecated(since="5.0", forRemoval=false) public NumberSeries createNumberSeries(String key, String startValue, int type, int digits) throws JaloInvalidParameterException
      Deprecated.
      Creates a new number series, sets the given start value via setStartValue(String, String) and the given digits via setDigits(String, int) persistent.
      Parameters:
      key - the number series key.
      startValue - the number series start value.
      type - the number series type NumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERIC or NumberGenerator.NumberSeriesConstants.TYPES.NUMERIC
      digits - the number of digits
      Returns:
      A NumberSeries object.
      Throws:
      JaloInvalidParameterException - if there is no series registered for given key
    • getAllNumberSeriesKeys

      public Collection<String> getAllNumberSeriesKeys()
      Returns all keys where number series exists.
      Returns:
      A collection of strings.
    • getAllNumberSeries

      public Collection getAllNumberSeries()
      Makes a snapshot of all number series currently existing in the database.
      Returns:
      A collection of NumberSeries objects or an empty list.
    • getNumberSeries

      public NumberSeries getNumberSeries(String key) throws JaloInvalidParameterException
      Makes a snapshot of the number series linked to the given key. If the key doesn't exists an JaloInvalidParameterException will be thrown.
      Parameters:
      key - the series key
      Returns:
      The NumberSeries object for the key.
      Throws:
      JaloInvalidParameterException
    • resetNumberSeries

      @Deprecated(since="5.0", forRemoval=false) public void resetNumberSeries(String key, String startValue, int type) throws JaloInvalidParameterException
      Deprecated.
      Resets the number series with the given key to the given start value and type. The new start value will be saved. The formerly defined digits will be used. The resetting has the effect, that the next gathering of a number will begin at the given start value.
      Parameters:
      key - the number series key, must not be null.
      startValue - the series new startvalue.
      type - the series type
      Throws:
      JaloInvalidParameterException - if no series was found for given key
    • resetNumberSeries

      public void resetNumberSeries(String key, String startValue, int type, String template) throws JaloInvalidParameterException
      Resets the number series with the given key to the given start value and type. The new start value will be saved. The formerly defined digits will be used. The resetting has the effect, that the next gathering of a number will begin at the given start value.
      Parameters:
      key - the number series key, must not be null.
      startValue - the series new startvalue.
      type - the series type
      template - the template to be applied on generated value
      Throws:
      JaloInvalidParameterException - if no series was found for given key
    • setDigits

      public void setDigits(String key, int digits)
      Saves the digits for the given number series. All following gathering of numbers will this new digits length.
      Parameters:
      key - the number series key. key must not be null.
      digits - the digits
    • getDigits

      public int getDigits(String key)
      Returns the configured digits for the given number series.
      Parameters:
      key - the number series key. must not be null.
      Returns:
      the digits or -1 if there is no digit set.
    • removeDigits

      public void removeDigits(String key)
      Removes the digits setting from NumberSeriesManager for the given series.
      Parameters:
      key - the number series key. Must not be null.
    • setStartValue

      public void setStartValue(String key, String startvalue)
      Changes the original start value of the given series. The call of this method will not influence the number generation, it only changes the original start value to the new one. The start value will only be used at series creation. You may change it for later usage at resetting a series. For resetting a number series to a new start value call resetNumberSeries(String, String, int). Therefore you can use the getStartValue(String) method.
      Parameters:
      key - the series key, must not be null
      startvalue - the series start value
    • getStartValue

      public String getStartValue(String key)
      Returns the original start value of the given series. May useful if you like to reset a series using the resetNumberSeries(String, String, int) method.
      Parameters:
      key - the series key, must not be null
      Returns:
      the original start value.
    • removeStartValue

      public void removeStartValue(String key)
      Removes the original start value property and value.
      Parameters:
      key - the series key, must not be null
    • isCreatorDisabled

      public boolean isCreatorDisabled()
      Part of DataCreator interface. Returns true.
      Returns:
      true
    • createEssentialData

      public void createEssentialData(Map params, JspContext jspc)
    • assureCustomerIDSeriesCreated

      @Deprecated(since="ages", forRemoval=false) public void assureCustomerIDSeriesCreated()
      Deprecated.
      since ages - number series is created during init - there is no need to check each time a new number is fetched!
      Assures that the number series with key NumberSeriesConstants.Series.CUSTOMER_ID is created. If not existent it will be created. The series can be used at unique customer id generation.
    • getOrCreateCustomerIDSeries

      public NumberSeries getOrCreateCustomerIDSeries()
      Returns standard number series for customer IDs. If no series exists it will be created automatically.
    • assureOrderCodeSeriesCreated

      @Deprecated(since="ages", forRemoval=false) public void assureOrderCodeSeriesCreated()
      Deprecated.
      since ages - number series are created during init - there is no need to check each time we need a new number !
      Assures that the number series with key NumberSeriesConstants.Series.ORDER_CODE is created. If not existent it will be created. The series can be used at unique customer id generation.
    • getOrCreateOrderCodeSeries

      public NumberSeries getOrCreateOrderCodeSeries()
      Returns standard number series for order codes. If no series exists it will be created automatically.
    • writeReplace

      public Object writeReplace() throws ObjectStreamException
      Specified by:
      writeReplace in class Manager
      Throws:
      ObjectStreamException