I'm trying to do findAllByName functionality through OpenCMIS over an Alfresco DMS. Basically it's supposed to find all Documents with a certain name.
Currently I've tried to do a recursive search, which is unfortunately very costly.
private List<Document> traverseAndFind(String name, Folder currentFolder, List<Document> foundDocuments) {
List<Folder> subFolders = new ArrayList<>();
for (CmisObject obj : currentFolder.getChildren()) {
if (obj.getName().equals(name) && obj instanceof Document) {
foundDocuments.add((Document) obj);
} else if (obj instanceof Folder) {
subFolders.add((Folder) obj);
}
}
for (Folder subFolder : subFolders) {
traverseAndFind(name, subFolder, foundDocuments);
}
return foundDocuments;
}
From what I've seen in the implementation of Folder::getChildren()
it keeps working with Session
and makes separate requests to find the children of a certain folder, leading to very long overall time to do a fairly shallow search, which probably means that I am approaching the problem incorrectly.
Is there a better approach to this? How would you for example do a search resulting in a List of absolutely every filename that is stored?
Thanks for any tips!