LiveCache.removeAssetFromCache(f);
WorkingCache.removeAssetFromCache(f);
}
}catch (Exception e) {
throw new DotDataException(e.getMessage(),e);
}
} else {
if (UtilMethods.isSet(toParentPath) && !toParentPath.equals("/")) {
try {
if (!perAPI.doesUserHavePermission(toParentFolder, PermissionAPI.PERMISSION_READ, user, false)) {
throw new IOException("User doesn't have permissions to move file to folder");
}
} catch (DotDataException e1) {
Logger.error(DotWebdavHelper.class,e1.getMessage(),e1);
throw new IOException(e1.getMessage());
}
if (getFolderName(fromPath).equals(getFolderName(toPath))) {
Logger.debug(this, "Calling Folderfactory to rename " + fromPath + " to " + toPath);
try{
Folder folder = folderAPI.findFolderByPath(getPath(toPath), host,user,false);
removeObject(toPath, user);
fc.removeFolder(folder,idapi.find(folder));
}catch (Exception e) {
Logger.debug(this, "Unable to delete toPath " + toPath);
}
boolean renamed = false;
try{
Folder folder = folderAPI.findFolderByPath(getPath(fromPath), host,user,false);
renamed = folderAPI.renameFolder(folder, getFileName(toPath),user,false);
fc.removeFolder(folder,idapi.find(folder));
//folderAPI.updateMovedFolderAssets(folder);
}catch (Exception e) {
throw new DotDataException(e.getMessage(), e);
}
if(!renamed){
Logger.error(this, "Unable to remame folder");
throw new IOException("Unable to rename folder");
}
} else {
Logger.debug(this, "Calling folder factory to move from " + fromPath + " to " + toParentPath);
Folder fromFolder;
try {
fromFolder = folderAPI.findFolderByPath(getPath(fromPath), host,user,false);
} catch (Exception e1) {
Logger.error(DotWebdavHelper.class, e1.getMessage(), e1);
throw new DotRuntimeException(e1.getMessage(), e1);
}
if(fromFolder != null){
Logger.debug(this, "Calling folder factory to move from " + idapi.find(fromFolder).getPath() + " to " + toParentPath);
Logger.debug(this, "the from folder inode is " + fromFolder.getInode());
}else{
Logger.debug(this, "The from folder is null");
}
try {
folderAPI.move(fromFolder, toParentFolder,user,false);
fc.removeFolder(fromFolder,idapi.find(fromFolder));
fc.removeFolder(toParentFolder,idapi.find(toParentFolder));
//folderAPI.updateMovedFolderAssets(fromFolder);
} catch (Exception e) {
Logger.error(DotWebdavHelper.class, e.getMessage(), e);
throw new DotDataException(e.getMessage(), e);
}
}
} else {
try {
if (!perAPI.doesUserHavePermission(host,PermissionAPI.PERMISSION_READ, user, false)) {
throw new IOException("User doesn't have permissions to move file to host");
}
} catch (DotDataException e) {
Logger.error(DotWebdavHelper.class,e.getMessage(),e);
throw new IOException(e.getMessage());
}
if (getFolderName(fromPath).equals(getFolderName(toPath))) {
try{
Folder fromfolder = folderAPI.findFolderByPath(getPath(fromPath), host,user,false);
folderAPI.renameFolder(fromfolder, getFileName(toPath),user,false);
fc.removeFolder(fromfolder,idapi.find(fromfolder));
}catch (Exception e) {
throw new DotDataException(e.getMessage(), e);
}
} else {
Folder fromFolder;
try {
fromFolder = folderAPI.findFolderByPath(getPath(fromPath), host,user,false);
folderAPI.move(fromFolder, host,user,false);
fc.removeFolder(fromFolder,idapi.find(fromFolder));
//folderAPI.updateMovedFolderAssets(fromFolder);
} catch (Exception e) {
Logger.error(DotWebdavHelper.class, e.getMessage(), e);
throw new DotDataException(e.getMessage(), e);
}
}
}
}