Alfresco - right custom ID generation

18 views Asked by At

I need advice how to properly generate my own unique ID in Alfresco. My ID is created unique for every site, some prefix (created by date and some property) + incremental suffix. I store this values in datalists in every site. I have this already working code as behavior onCreateNode():

public String getInvoiceNextValue(String siteShortName, String prefix) {
       // Find generator for given projectType
       String query = "PATH:\"/app:company_home/st:sites/cm:" + siteShortName + "//*\" AND TYPE:\"test:myDatalist\" AND @test:prefix:\"" + prefix + "\"";
       ResultSet resultSet = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_FTS_ALFRESCO, query);
       // If doesn't exist, creates one, otherwise return next value
       if (resultSet.length() < 1) {
           return createDocumentCounter(siteShortName, prefix);
       } else if (resultSet.length() == 1) {
           NodeRef counterRef = resultSet.getNodeRef(0);
           String newCounterValue = (String) nodeService.getProperty(counterRef, MyDatalistModel.PROP_SUFFIX);
           int newIntValue = Integer.parseInt(newCounterValue) + 1;
           newCounterValue = String.format("%04d", newIntValue);

           nodeService.setProperty(counterRef,  MyDatalistModel.PROP_SUFFIX, newCounterValue);
           return newCounterValue;
       } else {
           throw new AlfrescoRuntimeException("resultSet.length() > 2! Please Fix it!");
       }
   }
   

But i have problem when more documents are created at one time. Specially when no row with my test:prefix exist and then function createDocumentCounter() is called. It takes some time that Alfresco FTS query return my new created row. So it happens that more documents create own row with same values.

I thing that problem is in indexing of solr which take few seconds. So... Is my approach right? Can i somehow configure solr better? Or should i use some another approach? How you are dealing with creating customers ID?

0

There are 0 answers