12-12-2012 12:03 PM
NodeRef parentFolderRef => the NodeRef to an existing folder inside which a subfolder should be created
String subfolderName => the name of the subfolder, i.e. "myFolder"
NodeRef subfolderRef = fileFolderService.searchSimple(parentFolderRef, subfolderName);
if (subfolderRef == null) {
// Add a random delay to prevent both webscript requests from creating the same folder at the same time
Random randomGenerator = new Random();
int randomDelay = randomGenerator.nextInt(60000);
try {
Thread.sleep(randomDelay);
} catch (Exception exc) {
exc.printStackTrace();
}
try {
FileInfo subfolderInfo = fileFolderService.create(parentFolderRef, subfolderName, ContentModel.TYPE_FOLDER);
// An exception is thrown here as the folder has already been created by the first webscript request
} catch (FileExistsException e) {
// try to find the sub folder again as the filefolder service claims it does exist!
subfolderRef = fileFolderService.searchSimple(parentFolderRef, subfolderName);
// Now I do actually get the correct NodeRef as subfolderRef!
FileInfo secondSubfolderInfo = fileFolderService.create(subfolderRef, "anotherSubFolder", ContentModel.TYPE_FOLDER);
NodeRef secondSubfolderRef = secondSubfolderInfo.getNodeRef();
// secondSubfolderInfo is a normal NodeRef and all looks to work ok, but when i check later in the node browser the 'anotherSubFolder' doesn't actually exist!
}
}
12-12-2012 01:37 PM
12-12-2012 01:59 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.