Search in sources :

Example 1 with BulkUploadInfo

use of org.jbei.ice.lib.bulkupload.BulkUploadInfo in project ice by JBEI.

the class Collection method getBulkUploadFolder.

/**
 * Retrieves bulk import and entries associated with it that are referenced by the
 * id in the parameter. Only owners or administrators are allowed to retrieve bulk imports
 *
 * @param id     unique identifier for bulk import
 * @param offset offset for upload entries (start)
 * @param limit  maximum number of entries to return with the upload
 * @return data transfer object with the retrieved bulk import data and associated entries
 * @throws PermissionException
 */
protected AbstractFolder getBulkUploadFolder(long id, int offset, int limit) {
    BulkUploadDAO uploadDAO = DAOFactory.getBulkUploadDAO();
    BulkUploadAuthorization authorization = new BulkUploadAuthorization();
    BulkUpload draft = uploadDAO.get(id);
    if (draft == null)
        return null;
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    authorization.expectRead(account.getEmail(), draft);
    // retrieve the entries associated with the bulk import
    BulkUploadInfo info = draft.toDataTransferObject();
    List<Entry> list = uploadDAO.retrieveDraftEntries(id, offset, limit);
    for (Entry entry : list) {
        PartData partData = setFileData(userId, entry, ModelToInfoFactory.getInfo(entry));
        // check if any links and convert
        if (!entry.getLinkedEntries().isEmpty()) {
            Entry linked = (Entry) entry.getLinkedEntries().toArray()[0];
            PartData linkedData = partData.getLinkedParts().remove(0);
            linkedData = setFileData(userId, linked, linkedData);
            partData.getLinkedParts().add(linkedData);
        }
        info.getEntryList().add(partData);
    }
    info.setCount(uploadDAO.retrieveSavedDraftCount(id));
    return info;
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) BulkUploadAuthorization(org.jbei.ice.lib.bulkupload.BulkUploadAuthorization) PartData(org.jbei.ice.lib.dto.entry.PartData) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo) BulkUpload(org.jbei.ice.storage.model.BulkUpload) BulkUploadDAO(org.jbei.ice.storage.hibernate.dao.BulkUploadDAO)

Example 2 with BulkUploadInfo

use of org.jbei.ice.lib.bulkupload.BulkUploadInfo 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:
            BulkUploads controller = new BulkUploads();
            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) BulkUploads(org.jbei.ice.lib.bulkupload.BulkUploads) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Example 3 with BulkUploadInfo

use of org.jbei.ice.lib.bulkupload.BulkUploadInfo in project ice by JBEI.

the class FolderController method getPendingBulkUploads.

/**
 * Retrieves information about submitted bulk uploads that have status "PENDING". Administrator only function
 *
 * @param userId unique identifier for user performing action. Must have admin privileges
 * @return list of information about pending bulk uploads is user has administrative privileges, null otherwise
 */
public ArrayList<FolderDetails> getPendingBulkUploads(String userId) {
    ArrayList<FolderDetails> folders = new ArrayList<>();
    ArrayList<BulkUploadInfo> list = bulkUploads.getPendingUploads(userId);
    for (BulkUploadInfo info : list) {
        FolderDetails details = new FolderDetails();
        String name = info.getAccount() != null ? info.getAccount().getEmail() : info.getName();
        details.setName(name);
        details.setCount(info.getCount());
        details.setId(info.getId());
        details.setType(FolderType.UPLOAD);
        folders.add(details);
    }
    return folders;
}
Also used : FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo)

Example 4 with BulkUploadInfo

use of org.jbei.ice.lib.bulkupload.BulkUploadInfo in project ice by JBEI.

the class BulkUpload method toDataTransferObject.

public BulkUploadInfo toDataTransferObject() {
    BulkUploadInfo bulkUploadInfo = new BulkUploadInfo();
    bulkUploadInfo.setCreated(creationTime);
    bulkUploadInfo.setId(id);
    bulkUploadInfo.setLastUpdate(lastUpdateTime);
    bulkUploadInfo.setStatus(status);
    bulkUploadInfo.setName(name);
    bulkUploadInfo.setType(this.importType);
    bulkUploadInfo.setLinkType(this.linkType);
    Account draftAccount = getAccount();
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setEmail(draftAccount.getEmail());
    accountTransfer.setFirstName(draftAccount.getFirstName());
    accountTransfer.setLastName(draftAccount.getLastName());
    bulkUploadInfo.setAccount(accountTransfer);
    if (permissions != null) {
        for (Permission permission : permissions) {
            bulkUploadInfo.getPermissions().add(permission.toDataTransferObject());
        }
    }
    return bulkUploadInfo;
}
Also used : BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 5 with BulkUploadInfo

use of org.jbei.ice.lib.bulkupload.BulkUploadInfo in project ice by JBEI.

the class FolderController method getBulkUploadDrafts.

public ArrayList<FolderDetails> getBulkUploadDrafts(String userId) {
    ArrayList<FolderDetails> folders = new ArrayList<>();
    ArrayList<BulkUploadInfo> list = bulkUploads.retrieveByUser(userId, userId);
    for (BulkUploadInfo info : list) {
        FolderDetails details = new FolderDetails();
        details.setName(info.getName());
        details.setCount(info.getCount());
        details.setId(info.getId());
        details.setCanEdit(true);
        details.setType(FolderType.UPLOAD);
        folders.add(details);
    }
    return folders;
}
Also used : FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo)

Aggregations

BulkUploadInfo (org.jbei.ice.lib.bulkupload.BulkUploadInfo)5 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 PermissionException (org.jbei.ice.lib.access.PermissionException)1 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)1 BulkUploadAuthorization (org.jbei.ice.lib.bulkupload.BulkUploadAuthorization)1 BulkUploads (org.jbei.ice.lib.bulkupload.BulkUploads)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 BulkUploadDAO (org.jbei.ice.storage.hibernate.dao.BulkUploadDAO)1 Account (org.jbei.ice.storage.model.Account)1 BulkUpload (org.jbei.ice.storage.model.BulkUpload)1 Entry (org.jbei.ice.storage.model.Entry)1 Folder (org.jbei.ice.storage.model.Folder)1