cancel
Showing results for 
Search instead for 
Did you mean: 

right custom ID generation

Dagoo
Champ on-the-rise
Champ on-the-rise
 

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 testSmiley Tonguerefix 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?

1 REPLY 1

sanjaybandhniya
Elite Collaborator
Elite Collaborator

You can try db-afts instead of full text query.

db-afts is using db instead of solr so it will give result immediately.