Search in sources :

Example 1 with BulkUploadDAO

use of org.jbei.ice.storage.hibernate.dao.BulkUploadDAO 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 BulkUploadDAO

use of org.jbei.ice.storage.hibernate.dao.BulkUploadDAO in project ice by JBEI.

the class BulkUploadDeleteTask method execute.

@Override
public void execute() {
    BulkUploadDAO dao = DAOFactory.getBulkUploadDAO();
    BulkUpload upload = dao.get(bulkUploadId);
    if (upload == null) {
        Logger.error("Could not locate bulk upload " + bulkUploadId + " for deletion");
        return;
    }
    BulkUploadAuthorization authorization = new BulkUploadAuthorization();
    authorization.expectWrite(userId, upload);
    if (upload.getStatus() != BulkUploadStatus.IN_PROGRESS)
        return;
    // delete all associated entries that have a status of draft
    for (Entry entry : upload.getContents()) {
        for (Entry linkedEntry : entry.getLinkedEntries()) {
            if (linkedEntry.getVisibility() != Visibility.DRAFT.getValue())
                continue;
            DAOFactory.getEntryDAO().fullDelete(linkedEntry);
        //                entryController.fullDelete(userId, linkedEntry.getId());
        }
        if (entry.getVisibility() == Visibility.DRAFT.getValue()) {
            DAOFactory.getEntryDAO().fullDelete(entry);
        //                entryController.fullDelete(userId, entry.getId());
        }
    }
    dao.delete(upload);
}
Also used : Entry(org.jbei.ice.storage.model.Entry) BulkUpload(org.jbei.ice.storage.model.BulkUpload) BulkUploadDAO(org.jbei.ice.storage.hibernate.dao.BulkUploadDAO)

Aggregations

BulkUploadDAO (org.jbei.ice.storage.hibernate.dao.BulkUploadDAO)2 BulkUpload (org.jbei.ice.storage.model.BulkUpload)2 Entry (org.jbei.ice.storage.model.Entry)2 BulkUploadAuthorization (org.jbei.ice.lib.bulkupload.BulkUploadAuthorization)1 BulkUploadInfo (org.jbei.ice.lib.bulkupload.BulkUploadInfo)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 Account (org.jbei.ice.storage.model.Account)1