How to use vocabulary entries to create unique numeric codes

Hello,

I have a bundle in Nuxeo that has to create unique codes depending on some properties of the document, as if they were different kinds of documents. For example, depending on a property called “color”, we could create different sequential codes for each color:

BLUEXXXX : BLUE0001, BLUE0002, …

REDXXXX: RED0001, RED0002, RED0003, …

So I need to have different sequences for each kind of document. And I have decided to use Nuxeo's vocabularies for this. I save information for the code in each entry of the vocabulary:

ID: 1 / PREFIX: “BLUE” / NEXT_VALUE: 3

ID: 2 / PREFIX: “RED” / NEXT_VALUE: 4

(I want the administrators to be able to modify the NEXT_VALUE manually, that's why I thought using vocabularies could be a good idea.)

With this information, when the document is created, I have a listener that will take the next value for the document and save it in a property. Then, it will increase the NEXT_VALUE of the vocabulary entry.

I've done this and it works well when only I am using it. But I want the codes to be unique, and I've seen that if two users create the same kind of document at the same time, the application returns the same code for both documents.

What can I do to avoid this? I've tried with a transaction but it didn't work (perhaps I did something wrong).

I would really appreciate any idea on how to get unique sequences.

Thanks in advance,

0 votes

0 answers

1756 views

ANSWER