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 testrefix 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?
You can try db-afts instead of full text query.
db-afts is using db instead of solr so it will give result immediately.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.