use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class BulkUploadController method deleteDraftById.
/**
* Deletes a bulk import draft referenced by a unique identifier. only owners of the bulk import
* or administrators are permitted to delete bulk imports
*
* @param userId account of user making the request
* @param draftId unique identifier for bulk import
* @return deleted bulk import
* @throws PermissionException
*/
public BulkUploadInfo deleteDraftById(String userId, long draftId) throws PermissionException {
BulkUpload draft = dao.get(draftId);
if (draft == null)
return null;
Account draftAccount = draft.getAccount();
if (!userId.equals(draftAccount.getEmail()) && !accountController.isAdministrator(userId))
throw new PermissionException("No permissions to delete draft " + draftId);
BulkUploadDeleteTask task = new BulkUploadDeleteTask(userId, draftId);
IceExecutorService.getInstance().runTask(task);
BulkUploadInfo draftInfo = draft.toDataTransferObject();
AccountTransfer accountTransfer = draft.getAccount().toDataTransferObject();
draftInfo.setAccount(accountTransfer);
return draftInfo;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class TraceSequences method getTraces.
public Results<TraceSequenceAnalysis> getTraces(int start, int limit) {
entryAuthorization.expectRead(userId, entry);
List<TraceSequence> sequences = dao.getByEntry(entry, start, limit);
Results<TraceSequenceAnalysis> results = new Results<>();
if (sequences == null)
return results;
for (TraceSequence traceSequence : sequences) {
TraceSequenceAnalysis analysis = traceSequence.toDataTransferObject();
AccountTransfer accountTransfer = new AccountTransfer();
String depositor = traceSequence.getDepositor();
boolean canEdit = canEdit(userId, depositor, entry);
analysis.setCanEdit(canEdit);
Account account = DAOFactory.getAccountDAO().getByEmail(traceSequence.getDepositor());
if (account != null) {
accountTransfer.setFirstName(account.getFirstName());
accountTransfer.setLastName(account.getLastName());
accountTransfer.setEmail(account.getEmail());
accountTransfer.setId(account.getId());
}
analysis.setDepositor(accountTransfer);
results.getData().add(analysis);
}
// get count
int count = dao.getCountByEntry(entry);
results.setResultCount(count);
return results;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class PlateSamples method setAccountInfo.
protected PartSample setAccountInfo(PartSample partSample, String email) {
Account account = DAOFactory.getAccountDAO().getByEmail(email);
if (account != null)
partSample.setDepositor(account.toDataTransferObject());
else {
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setEmail(email);
partSample.setDepositor(accountTransfer);
}
return partSample;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class BulkUploads method getPendingImports.
/**
* Retrieves list of bulk imports that are owned by the system. System ownership is assigned to
* all bulk imports that are submitted by non-admins and indicates that it is pending approval.
* <p>Administrative privileges are required for making this call
*
* @param userId account for user making request; expected to be an administrator
* @return list of bulk imports pending verification
*/
public HashMap<String, ArrayList<BulkUploadInfo>> getPendingImports(String userId) {
// check for admin privileges
authorization.expectAdmin(userId);
HashMap<String, ArrayList<BulkUploadInfo>> infoList = new HashMap<>();
List<BulkUpload> results;
results = dao.retrieveByStatus(BulkUploadStatus.PENDING_APPROVAL);
if (results == null || results.isEmpty())
return infoList;
for (BulkUpload draft : results) {
BulkUploadInfo info = new BulkUploadInfo();
Account draftAccount = draft.getAccount();
String userEmail = draftAccount.getEmail();
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setEmail(userEmail);
accountTransfer.setFirstName(draftAccount.getFirstName());
accountTransfer.setLastName(draftAccount.getLastName());
info.setAccount(accountTransfer);
info.setId(draft.getId());
info.setLastUpdate(draft.getLastUpdateTime());
int count = draft.getContents().size();
info.setCount(count);
info.setType(draft.getImportType());
info.setCreated(draft.getCreationTime());
info.setName(draft.getName());
// add to list
ArrayList<BulkUploadInfo> userList = infoList.computeIfAbsent(userEmail, k -> new ArrayList<>());
userList.add(info);
}
return infoList;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class AccessTokenResource method create.
/**
* Creates a new access token for the user referenced in the parameter, after the credentials
* (username and password) are validated. If one already exists, it is invalidated
*
* @param transfer wraps username and password
* @return account information including a valid session id if credentials validate
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response create(final AccountTransfer transfer) {
final AccountTransfer info = accountController.authenticate(transfer);
if (info == null) {
Logger.warn("Authentication failed for user " + transfer.getEmail());
return respond(Response.Status.UNAUTHORIZED);
}
Logger.info("User '" + transfer.getEmail() + "' successfully logged in");
return respond(Response.Status.OK, info);
}
Aggregations