Search in sources :

Example 1 with BulkUpload

use of org.jbei.ice.storage.model.BulkUpload in project ice by JBEI.

the class BulkUploadDAO method retrieveDraftEntries.

public List<Entry> retrieveDraftEntries(long id, int start, int limit) {
    try {
        CriteriaQuery<Entry> query = getBuilder().createQuery(Entry.class);
        Root<BulkUpload> from = query.from(BulkUpload.class);
        Join<BulkUpload, Entry> contents = from.join("contents");
        query.select(contents).where(getBuilder().equal(from.get("id"), id)).orderBy(getBuilder().asc(contents.get("id")));
        return currentSession().createQuery(query).setFirstResult(start).setMaxResults(limit).list();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Entry(org.jbei.ice.storage.model.Entry) HibernateException(org.hibernate.HibernateException) BulkUpload(org.jbei.ice.storage.model.BulkUpload)

Example 2 with BulkUpload

use of org.jbei.ice.storage.model.BulkUpload 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 3 with BulkUpload

use of org.jbei.ice.storage.model.BulkUpload in project ice by JBEI.

the class BulkUploadDAO method retrieveSavedDraftCount.

public int retrieveSavedDraftCount(long draftId) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<BulkUpload> from = query.from(BulkUpload.class);
        Join<BulkUpload, Entry> contents = from.join("contents");
        query.select(getBuilder().countDistinct(contents.get("id"))).where(getBuilder().equal(from.get("id"), draftId));
        return currentSession().createQuery(query).uniqueResult().intValue();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Entry(org.jbei.ice.storage.model.Entry) HibernateException(org.hibernate.HibernateException) BulkUpload(org.jbei.ice.storage.model.BulkUpload)

Example 4 with BulkUpload

use of org.jbei.ice.storage.model.BulkUpload in project ice by JBEI.

the class BulkUploadDAO method retrieveByAccount.

public List<BulkUpload> retrieveByAccount(Account account) {
    try {
        CriteriaQuery<BulkUpload> query = getBuilder().createQuery(BulkUpload.class);
        Root<BulkUpload> from = query.from(BulkUpload.class);
        query.where(getBuilder().equal(from.get("account"), account), getBuilder().notEqual(from.get("status"), BulkUploadStatus.PENDING_APPROVAL));
        return currentSession().createQuery(query).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) BulkUpload(org.jbei.ice.storage.model.BulkUpload)

Example 5 with BulkUpload

use of org.jbei.ice.storage.model.BulkUpload 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

BulkUpload (org.jbei.ice.storage.model.BulkUpload)8 HibernateException (org.hibernate.HibernateException)5 DAOException (org.jbei.ice.storage.DAOException)5 Entry (org.jbei.ice.storage.model.Entry)5 BulkUploadDAO (org.jbei.ice.storage.hibernate.dao.BulkUploadDAO)2 Account (org.jbei.ice.storage.model.Account)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