Version 24.1 by Thomas Mortagne on 2011/10/27 18:02

brickGenerates unique identification number for XWiki data types
Typecomponents
Category
Developed by

Stefan Abageru

Rating
0 Votes
LicenseUnknown

Description

Preliminary informations

UniqueIdentificationNumber can be used in the xwiki environment in order to generate a next available number for a group of documents that follow two rules:

  1. Their names is built as follows: anyString.UniqueIdentificationNumber 
  2. They are instantiations of a class specified in xwiki.properties

These numbers will be called UIN from now on. The purpose of this component is to ensure we do not have 2 documents with the same UIN.

A number is considered AVAILABLE when it hasn't been used before. For example, we create documents PIN.12, PIN.13, PIN.14 and after that we delete PIN.13, PIN.14 from the wiki. When generating the next AVAILABLE number we want to avoid numbers 13 and 14 and so we need to keep track of already generated numbers in a table in database.

Methods for velocity

These are the methods that UniqueIdentificationNumber makes available for velocity calls:

  1. To retrieve the next available UIN based on the rules. This method makes sure that the UIN returned hasn't been used before.
    $uin.getNextAvailableUIN()
  2. To check whether a uinValue was used before
    $uin.isUINUsedBefore(long uinValue)
  3. To store this value in the database (This should be used when doing mass import of documents
    $uin.storeUIN(long uinValue)
  4. to retrieve the maximum value cureently used as UIN
    $uin.getCurrentMaxUIN()
  5. To reset the values to starting point. This method deletes all documents that meet the rules above and empties the table with used values. Careful when using this !
    $uin.reset()

Prerequisites & Installation Instructions

  • Add the properties to xwiki.properties according to your needs
    uin.manager.increment = 1
    uin.manager.className=PinCode.PinUsersClass
    uin.manager.initialUinValue=800000 See explanations below. 

    increment - the value used to increment the last used value in order to retrieve the next usable value
    className - the class which is used to instantiate the documents the component searches for
    initialUinValue - the initial value that is returned when there are no documents created with the rules

  • Add this mapping to your hibernate.cfg.xml file
    <mapping resource="hibernate/PINClass.hbm.xml"/>
  • Restart wiki.
Tags: development
    

Get Connected