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