use of org.jbei.ice.storage.model.Account in project ice by JBEI.
the class GroupController method retrieveAccountGroupUUIDs.
public Set<String> retrieveAccountGroupUUIDs(String userId) {
Account account = accountController.getByEmail(userId);
Set<String> uuids = new HashSet<>();
if (account != null) {
uuids.addAll(dao.getMemberGroupUUIDs(account));
}
uuids.add(PUBLIC_GROUP_UUID);
return uuids;
}
use of org.jbei.ice.storage.model.Account in project ice by JBEI.
the class GroupController method createGroup.
// create group without parent
public UserGroup createGroup(String userId, UserGroup info) {
if (info.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
String errMsg = "Non admin " + userId + " attempting to create public group";
Logger.error(errMsg);
return null;
}
if (info.getType() == null)
info.setType(GroupType.PRIVATE);
Account account = accountController.getByEmail(userId);
Group group = new Group();
group.setLabel(info.getLabel());
group.setDescription(info.getDescription() == null ? "" : info.getDescription());
group.setType(info.getType());
group.setOwner(account);
group = save(group);
for (AccountTransfer accountTransfer : info.getMembers()) {
Account memberAccount = accountController.getByEmail(accountTransfer.getEmail());
if (memberAccount == null)
continue;
memberAccount.getGroups().add(group);
accountController.save(memberAccount);
}
info = group.toDataTransferObject();
for (Account addedAccount : group.getMembers()) {
info.getMembers().add(addedAccount.toDataTransferObject());
}
info.setMemberCount(info.getMembers().size());
return info;
}
use of org.jbei.ice.storage.model.Account 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.Account 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.storage.model.Account in project ice by JBEI.
the class UserSessions method getUserAccount.
/**
* Retrieves the account object associated with the session identifier.
* If the requesting user is not the same as the user associated with the session, then the requesting
* user is required to have administrative privileges on their account
*
* @param requestingUser unique identifier for user making request
* @param token unique session identifier
* @return account associated with the session token/identifier or null if no account is located
* @throws PermissionException if the user Id associated with the session token is not the same as the requesting
* user but the requesting user's account does not have administrative privileges
*/
public static AccountTransfer getUserAccount(String requestingUser, String token) {
String userId = getUserIdBySession(token);
if (StringUtils.isEmpty(userId))
return null;
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
if (account == null) {
Logger.error("Account for userId returned by session (\"" + userId + "\") cannot be found");
return null;
}
AccountController accountController = new AccountController();
if (!requestingUser.equalsIgnoreCase(userId) && !accountController.isAdministrator(requestingUser))
throw new PermissionException();
AccountTransfer accountTransfer = account.toDataTransferObject();
accountTransfer.setAdmin(accountController.isAdministrator(userId));
return accountTransfer;
}
Aggregations