use of org.jbei.ice.lib.bulkupload.BulkUploadController in project ice by JBEI.
the class FolderController method delete.
/**
* Deletes either a user folder or bulk upload (which is represented as a folder to the user)
*
* @param userId unique identifier for user requesting delete action
* @param folderId unique identifier for folder to be deleted
* @param type type of folder to be deleted (either "UPLOAD" or "PRIVATE")
* @return delete folder details
*/
public FolderDetails delete(String userId, long folderId, FolderType type) {
switch(type) {
case UPLOAD:
BulkUploadController controller = new BulkUploadController();
BulkUploadInfo info = controller.deleteDraftById(userId, folderId);
if (info == null) {
Logger.error("Could not locate bulk upload id " + folderId + " for deletion");
return null;
}
FolderDetails details = new FolderDetails();
details.setId(info.getId());
return details;
case PRIVATE:
case TRANSFERRED:
case SHARED:
Folder folder = dao.get(folderId);
if (folder == null)
return null;
if (!accountController.isAdministrator(userId) && !folder.getOwnerEmail().equalsIgnoreCase(userId)) {
String errorMsg = userId + ": insufficient permissions to delete folder " + folderId;
Logger.warn(errorMsg);
throw new PermissionException(errorMsg);
}
details = folder.toDataTransferObject();
long folderSize = dao.getFolderSize(folderId, null, true);
details.setCount(folderSize);
permissionDAO.clearPermissions(folder);
dao.delete(folder);
return details;
default:
Logger.error("Cannot delete folder of type " + type);
return null;
}
}
Aggregations