How to add a new number pattern to an ID field
This is an older document that requires substantial revision to be brought up to current documentation standards. Some of the instructions in this document are also outdated and require modification.
It is included here as a placeholder, even prior to being revised, as an experienced CollectionSpace implementer may yet be able to obtain the information they need by carefully parsing this document.
How to add a new number pattern
This document requires updating to reflect changes through version 1.8:
- You will now perform substantially equivalent steps to import number patterns into PostgreSQL, rather than MySQL. (PostgreSQL instructions need to be added as the default instructions, before the corresponding MySQL instructions.)
- Within the Application source code tree, you'll now make number pattern changes to a tenant-specific configuration file; for example,
tomcat-main/src/main/resources/tenants/your_tenant_name-tenant.xml
for the tenant namedyour_tenant_name
. Formerly, this file was nameddefault.xml
in the source code tree, and was renamed tocspace-config.xml
when deployed to the server. This needs to be verified first-hand, since ID Generators are currently not tenant-specific. - This document might also refer to a page describing the emerging "mini-build," a simplified build tree in which implementers can make many of their more straightforward customizations.
In version 1.9 and beyond, the name and location of the configuration file you'll change will change again, to reflect a per-record-type overlay mechanism:
- Within the Application source code tree, you'll make number pattern changes to the file
tomcat-main/src/main/resources/tenants/defaults/base-other-idgenerator.xml
, rather thanyour_tenant_name-tenant.xml
,default.xml
orcspace-config.xml
. (When ID Generators become tenant-specific, this may change again to a tenant-specific variant of that file.)
Finally, this document also requires:
- Inclusion of necessary changes to app layer test datafile(s); see https://github.com/aronr/application/commit/5fb06c290e3501ce0f9e607658657d6b1086c9d8 for an example. (Basically, after adding a new number pattern, you will need to send a request to the app layer for its updated uispec, and paste that into the relevant test uispec datafile in the app layer source code tree.)
This document also requires updating to reflect changes introduced in version 3.2:
- Loading of ID number patterns now takes place automatically at system startup, rather than by running an Ant task. It is still possible, however, to manually load custom ID patterns by running a SQL script, for instance via
psql
(for PostgreSQL) or another database client application. - The SQL load file has changed slightly to use
INSERT INTO ... SELECT
statements, rather thanINSERT INTO ... VALUES
. As an example, see the changes made to the SQL load file that loads the default / demonstration ID number patterns, at: http://fisheye.collectionspace.org/viewrep/cspace-service/services/common/src/main/resources/db/postgresql/load_id_generators.sql?r1=8ef2dbec00ffb693d24e95c8f6b52267cf27da15&r2=8cd0579f6c5c7c3df6273ed6cef5149e276c8345
CollectionSpace can automatically generate various types of identification numbers for your cataloging and procedural records. Examples include object numbers, acquisition reference numbers, and loan out numbers.
You can use some or all the predefined number patterns that come with a CollectionSpace system. You can also create new, custom number patterns to automatically generate the types of record numbers specific to your institution.
Task Description
This document describes how to add a new number pattern to CollectionSpace.
Prerequisites
A system administrator with experience editing XML markup and running command line utilities can perform all of the tasks described in this document.
Procedure
To create a new number pattern, follow the next steps:
Create the new number pattern in a SQL load file
- Make a new directory.
- Change into that directory.
- Download the Services source code tree into that directory. See How to check out the Services layer source code for details.
- Within that source code tree, find the .SQL import file for the ID service ; e.g.:
(You can also view and copy an example of this file online.)
services/id/service/src/main/resources/db/mysql/load_id_generators.sql
- Copy the file and rename it. You might name it something like
my_custom_number_pattern.sql
. - Open your new SQL load file,
my_custom_number_pattern.sql
, in a text editor. - Delete all but one of the INSERT statements for existing number patterns. (You'll use the one remaining INSERT statement as a template that you can modify.)
These INSERT statements all begin withINSERT INTO
, contain many lines of text, and end in a semicolon (;). They follow this general pattern:INSERT INTO `id_generators`... VALUES (...);
- Create your new, custom number pattern by editing the one remaining INSERT statement, changing several of its values as follows:
- Change the first value ('csid') to a new 36-character unique ID. (To generate this ID, see the Generating section of /wiki/spaces/collectionspace/pages/666274321.)
- Change the second value ('displayname') to a human-readable name for the number pattern.
- Change the third value ('description') to a description of the number pattern, such as a summary of its purpose and any other relevant information.
- If the fifth value ('last_generated_id') contains a value, remove that value (the quantity between the single quotes). The empty value should simply look like this:
''
- Change the last value ('id_generator_state') to XML markup that reflects the number pattern you'd like to generate. Specifically, within the existing
<parts>
element in this XML markup, you'll add or edit a set of "parts," such as theStringIDGeneratorPart
andYearIDGeneratorPart
. Some of these parts insert static strings, while others insert dynamic numbers, dates, alphabetic values, etc. You'll add one of these parts for each of the distinct portions of your number pattern that is to be generated, from left to right. Each part has initial and/or current values that you may wish to customize as well.
The following example shows a number pattern consisting of four parts, all added as children of the existing<parts>
element: a string part, a current year part, another string part, and an auto-generating numeric part. This pattern will generate numbers likePR2011.1
,PR2011.2
, andPR2011.3
... if the current year is 2011; numbers likePR2012.2
,PR2012.2
,PR2012.3
... if the current year is 2012, and so on:In addition to the parts shown in the example above, which you can mix and match as you wish, there is also an additional part you can include in your custom number pattern that can generate alphabetic sequences; e.g."a, b, c ... z, aa, ab ..." or "Y, Z, AA. ..." as illustrated next:<!-- Always begin numbers with the string "PR" --> <org.collectionspace.services.id.StringIDGeneratorPart> <initialValue>PR</initialValue> <currentValue>PR</currentValue> </org.collectionspace.services.id.StringIDGeneratorPart> <!-- Insert the current, four-digit year; currentValue should be empty --> <org.collectionspace.services.id.YearIDGeneratorPart> <currentValue></currentValue> </org.collectionspace.services.id.YearIDGeneratorPart> <!-- Insert a string consisting of just a period/full stop (".") --> <org.collectionspace.services.id.StringIDGeneratorPart> <initialValue>.</initialValue> <currentValue>.</currentValue> </org.collectionspace.services.id.StringIDGeneratorPart> <!-- Insert an autogenerated number, starting at 1 and ending at 999999 --> <org.collectionspace.services.id.NumericIDGeneratorPart> <maxLength>6</maxLength> <initialValue>1</initialValue> <!-- currentValue should be set to -1 if the first value to be generated is the initial value, shown above --> <currentValue>-1</currentValue> </org.collectionspace.services.id.NumericIDGeneratorPart>
<org.collectionspace.services.id.AlphabeticIDGeneratorPart> <startChar>a</startChar> <!-- When the end character in the sequence, below, is reached, this part --> <!-- will add an additional character at left and roll over to a new sequence; --> <!-- for example, from "zx", "zy", "zz" to "aaa", "aab", etc. --> <endChar>z</endChar> </org.collectionspace.services.id.AlphabeticIDGeneratorPart>
Import the new pattern into the database
- Import the new number pattern into the MySQL database.
- On a computer that has the
mysql
command line client installed, log into a MySQL user account by typing:where 'username' is the name of a MySQL user that can write to tables in the 'cspace' database.mysql -u username -p
- At the password prompt, enter the password of that MySQL user.
- To import the new number pattern(s), at the
mysql>
prompt, type:wheresource pathto/my_custom_number_pattern.sql
pathto
is the filesystem path to the SQL load file containing your custom number pattern(s), if that file is not in your current directory. - To exit MySQL, at the
mysql>
prompt, type:quit
- On a computer that has the
Tip
These instructions will be different if your CollectionSpace deployment is using the PostgreSQL database, rather than MySQL. In that case, you will use the psql
command line utility to run the commands in your SQL load file, and the steps you will follow will differ somewhat from those listed above. (PostgreSQL support is on the roadmap for a future release of CollectionSpace).
On Mac OSX 10.7.3 I ran: psql -h localhost -d nuxeo -U postgres -f pathto/my_custom_number_pattern.sql
where pathto
is the filesystem path to the SQL load file. In OSX Lion, I ran into problems with psql -U postgres
connecting to the server. Specifying -h localhost
solved this problem.
In an even later, future release of CollectionSpace, adding a new number pattern will be performed by sending an HTTP POST request to the ID service, instead of running the commands in a SQL load file via a MySQL or PostgreSQL command line utility.
Modify the main CollectionSpace configuration file to reflect your new number pattern
Reference your newly-created number pattern by editing the main CollectionSpace configuration file, by following the next steps:
- Find this configuration file. You will find it in the following locations:
(Under Linux and other Unix-like systems)(Under Windows)$JBOSS_HOME/server/cspace/conf/cspace-config.xml
%JBOSS_HOME%\server\cspace\conf\cspace-config.xml
- Edit this configuration file in a text editor.
- Within this configuration file, find the
record
block for the ID service. This will start with<record id="id" ...>
; e.g.:"Note"
The ellipses ("...") in the examples below indicate additional markup that isn't displayed, to keep examples brief and uncluttered. They are not literally present in this markup, and you should not add them.
<record id="id" type="id"> ... <section> <field id="accession"><selector>9dd92952-c384-44dc-a736-95e435c1759c</selector></field> <field id="archive"><selector>70586d30-9dca-4a07-a3a2-1976fe898028</selector></field> ... </section>
- For each new number pattern you added to the services, above, add one new
field
element within thesection
block shown above; e.g.<section> <field id="accession"><selector>9dd92952-c384-44dc-a736-95e435c1759c</selector></field> <field id="archive"><selector>70586d30-9dca-4a07-a3a2-1976fe898028</selector></field> ... <field id="mynewnumbertype"><selector>9dd92952-c384-44dc-a736-95e435c1759c</selector></field> </section>
- For the first value ('id'), enter a short name for the type of your new number pattern.
- For the second value ('selector'), enter the 36-character unique ID that you created earlier for your new number pattern in the SQL load file, above.
- Next, within this configuration file, find the block for the record type to which you wish to add this number pattern. It will start with
<record id="...">
and will look something like the following (in the example of an acquisition record):<record id="acquisition" in-findedit="yes" type="record,procedure">
- Find the
field
element within that record that configures which number patterns are presented to the user, via a Number Pattern Chooser widget. It will have achooser="yes"
attribute, as in this example:<record id="acquisition" in-findedit="yes" type="record,procedure"> ... <field id="acquisitionReferenceNumber" in-title="yes" chooser="yes" mini="number,search,list,relate,terms" seperate_ui_container="true"> ... <options> <option id="accession" sample="2009.1">Accession</option> <option id="archive" sample="AR2009.42">Archives</option> <option id="library" sample="LIB2009.1">Library</option> ... </options>
- Within that
field
'soptions
block, add a newoption
element for your new number pattern:<options> <option id="accession" sample="2009.1">Accession</option> <option id="archive" sample="AR2009.42">Archives</option> <option id="library" sample="LIB2009.1">Library</option> ... <option id="mynewnumbertype" sample="MYN.1.9">My New Number Type Here</option> </options>
- For the first value ('id'), enter the same name (e.g.
mynewnumbertype
) you entered previously, when adding your new number pattern to the record block for the ID service. - For the second value ('sample'), enter a representative sample of an ID number that matches your pattern.
- For the third value, enter a display name for your new type of number. This is the name that will be displayed to the user, in the Number Pattern Chooser widget.
- For the first value ('id'), enter the same name (e.g.
Restart the CSpace server
- Shut down the 'cspace' server (only - not the Nuxeo server) by following the instructions in the reference document: Shutting Down the CollectionSpace Server.
- Start the 'cspace' server by following the instructions in the reference document: Starting Up the CollectionSpace Server.
Test
To verify that you have successfully added your new number pattern in the database:
- Make a services call to verify that your new number pattern is now available. In a browser, type:
where 'myserverhostname:myport' is the hostname and port of your CollectionSpace server.
http://myserverhostname:myport/cspace-services/idgenerators?format=full
Example: http://demo.collectionspace.org:8180/cspace-services/idgenerators?format=full - When prompted, authenticate with a username and password for a valid user of the CollectionSpace system.
You should see XML markup displayed in your browser's window that includes an entry for your new number pattern.
To verify that you have successfully added your new number pattern to CollectionSpace's main configuration file:
- Log into the CollectionSpace system.
- Click the Create New tab.
- Click the button next to the record type to which you've added your new number pattern.
- Click Create.
- On the data entry screen for your record type, find the field next to a Select number pattern button.
- Click that button.
A Number Pattern Chooser widget should pop up. This widget will display a list of various types of numbers you can add. You should see your new number pattern in that list.
- Select your new number pattern from that list.
A automatically generated number, following your new number pattern, should appear in the text field next to that button.
Summary
The above procedure describes how to add a new number pattern to CollectionSpace by:
- Creating a custom number pattern in the a SQL load file.
- Importing that number pattern into the CSpace database via the database client's command line utility.
- Editing the main CollectionSpace configuration file in two places:
- Adding an entry for that number pattern.
- Referencing that number pattern within the entry for the appropriate record type and field into which you'll be entering these numbers.
- Shutting down the CSpace server.
- Restarting the CSpace server.
See Also
The following documents can provide additional information on configuring CollectionSpace.
- A set of example number patterns provided 'out of the box' with a new CollectionSpace deployment are listed in the Notes near the bottom of many of the Schemae pages. See Schema.
- See ID Service Contract for information on how to programmatically invoke CollectionSpace's ID service to auto-generate numbers from number patterns.