import com.liferay.portlet.documentlibrary.model.*; import com.liferay.portal.kernel.search.*; try { String entryClassPK = "192363"; String className = DLFileEntry.class.getName(); SearchEngineUtil.updatePermissionFields(className, entryClassPK); out.println("Reindexed: " + entryClassPK); } catch (Exception e) { out.println("Failed to reindex: " + entryClassPK); e.printStackTrace(); }
So now we definitely knew that the indexing of the permissions was the issue and after creating a JMeter load test, I was even able to consistently reproduce the problem. When I ran the test about 1 or 2 documents in a run of a 1000 would have an incorrect groupRoleId field value (empty or only a groupId without a connecting dash and roleId). This is when we decided to open a support ticket as we couldn't find the cause of the problem and were thinking it might be a possible bug.
With the friendly help of the Liferay support guys (thank you very much again!) we found out that we were actually working under an incorrect assumption about Liferay's inner workings. As it turns out: when you call multiple Liferay APIs after each other, like we were doing in our REST service, outside of Liferay's transactions, you might need to use TransactionCommitCallbackUtil to register a callback that has to run after the initial API call has finished. In our case this was setting the correct permissions after the document was added. Even after working with Liferay all these years you still learn something new!

- A Lucene index directory, in our case the Liferay data/lucene directory (you only need to provide the root, it will find the subdirectories itself). The index will also be opened as read-only and our tests suggest you can run it against a running Liferay's index.
- The Lucene query to run (wildcards are turned on and allowed), e.g.: "entryClassName:com.liferay.portlet.documentlibrary.model.DLFileEntry AND visible:true AND (*:* AND NOT groupRoleId:*-*)"
- The field of the result that you want inspected, e.g.: groupRoleId
- The field values of the matching Lucene docs you want printed in the logs, e.g: "entryClassPK,groupId,title"
be.planetsizebrain.lucene.IndexChecker - Adding index directory '/path/to/liferay/data/lucene/10155' to search be.planetsizebrain.lucene.IndexChecker - Adding index directory '/path/to/liferay/data/lucene/0' to search be.planetsizebrain.lucene.IndexChecker - Found 5 possible incorrect documents, checking 'groupRoleId' field... be.planetsizebrain.lucene.IndexChecker - Found document with empty value for 'groupRoleId': (entryClassPK: 11547), (groupId: 10916), (title: Code Complete 2nd Edition) be.planetsizebrain.lucene.IndexChecker - Found document with empty value for 'groupRoleId': (entryClassPK: 11578), (groupId: 10916), (title: Liferay In Action) be.planetsizebrain.lucene.IndexChecker - Found document with empty value for 'groupRoleId': (entryClassPK: 994268), (groupId: 12301), (title: Javascript - The Good Parts) be.planetsizebrain.lucene.IndexChecker - Found document with empty value for 'groupRoleId': (entryClassPK: 600652), (groupId: 12355), (title: The Mythical Man-Month) be.planetsizebrain.lucene.IndexChecker - Found document with empty value for 'groupRoleId': (entryClassPK: 995458), (groupId: 12355), (title: Effective Java 2nd Edition) be.planetsizebrain.lucene.IndexChecker - Done. Found 0 incorrect and 5 empty entries


