Search in sources :

Example 1 with BulkUploadController

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;
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) BulkUploadController(org.jbei.ice.lib.bulkupload.BulkUploadController) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Aggregations

PermissionException (org.jbei.ice.lib.access.PermissionException)1 BulkUploadController (org.jbei.ice.lib.bulkupload.BulkUploadController)1 BulkUploadInfo (org.jbei.ice.lib.bulkupload.BulkUploadInfo)1 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)1 Folder (org.jbei.ice.storage.model.Folder)1