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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
Aggregations