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