use of org.jbei.ice.lib.entry.Entries in project ice by JBEI.
the class TransferTask method execute.
public void execute() {
RemoteTransfer transfer = new RemoteTransfer();
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
if (account.getType() != AccountType.ADMIN)
return;
Entries retriever = new Entries(account.getEmail());
List<Long> entries = retriever.getEntriesFromSelectionContext(entrySelection);
Logger.info(userId + ": requesting transfer to " + remoteId);
List<PartData> dataList = transfer.getPartsForTransfer(entries);
List<Long> remoteIds = transfer.transferEntries(remoteId, dataList);
// check folder
if (StringUtils.isEmpty(this.entrySelection.getFolderId()))
return;
// create remoteFolder
long folderId = Long.decode(this.entrySelection.getFolderId());
Folder folder = DAOFactory.getFolderDAO().get(folderId);
Logger.info("Adding " + remoteIds.size() + " transferred entries to remote folder");
transfer.transferFolder(remoteId, folder.toDataTransferObject(), remoteIds);
}
use of org.jbei.ice.lib.entry.Entries in project ice by JBEI.
the class FolderContents method addEntrySelection.
/**
* Adds entries in the selection context, to specified folders
*
* @param userId unique identifier for user making request
* @param entryLocation entry selection context which also contains the folders to
* add the entries obtained from the context to
* @return list of folders that the entries where added to. They should correspond to the specified
* folders in the selection context
*/
public List<FolderDetails> addEntrySelection(String userId, EntrySelection entryLocation) {
Entries retriever = new Entries(userId);
if (entryLocation.getRemoteEntries() != null && !entryLocation.getRemoteEntries().isEmpty())
return addRemoteEntries(userId, entryLocation.getRemoteEntries(), entryLocation.getDestination());
List<Long> entries = retriever.getEntriesFromSelectionContext(entryLocation);
if (StringUtils.isEmpty(userId)) {
ArrayList<FolderDetails> destination = entryLocation.getDestination();
// check that folder is transferred before rejecting
if (destination == null || destination.isEmpty())
throw new IllegalArgumentException("Cannot add without valid user id or destination");
Folder folder = folderDAO.get(destination.get(0).getId());
if (folder == null)
throw new IllegalArgumentException("Cannot find folder");
if (folder.getType() != FolderType.TRANSFERRED)
throw new PermissionException("Can only add to transferred folder without id");
FolderDetails details = addEntriesToTransferredFolder(entries, folder);
List<FolderDetails> result = new ArrayList<>();
result.add(details);
return result;
}
return addEntriesToFolders(userId, entries, entryLocation.getDestination());
}
use of org.jbei.ice.lib.entry.Entries in project ice by JBEI.
the class FolderContents method removeFolderContents.
/**
* Removes the specified contents of a folder, optionally adding them to another folder
*
* @param userId unique identifier for user making request
* @param folderId unique identifier for folder whose (specified) entries are being removed
* @param selection wrapper around the selection context for the contents
* @param move true, if the contents are to be added to another (set of) folder(s) (which should be specified in
* <code>selection</code> parameter)
* @return true, if action completed successfully; false otherwise
*/
public boolean removeFolderContents(String userId, long folderId, EntrySelection selection, boolean move) {
// remove entries from specified folder
boolean isAdministrator = accountController.isAdministrator(userId);
Folder folder = folderDAO.get(folderId);
if (folder.getType() == FolderType.PUBLIC && !isAdministrator) {
String errMsg = userId + ": cannot modify folder " + folder.getName();
throw new PermissionException(errMsg);
}
Entries entries = new Entries(userId);
List<Long> entryIds = entries.getEntriesFromSelectionContext(selection);
boolean successRemove = folderDAO.removeFolderEntries(folder, entryIds) != null;
if (!move)
return successRemove;
// add to specified folder
selection.setFolderId(Long.toString(folderId));
List<FolderDetails> details = addEntrySelection(userId, selection);
return !details.isEmpty();
}
Aggregations