Search in sources :

Example 21 with AccountTransfer

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;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 22 with AccountTransfer

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;
}
Also used : TraceSequenceAnalysis(org.jbei.ice.lib.dto.entry.TraceSequenceAnalysis) Results(org.jbei.ice.lib.dto.common.Results) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 23 with AccountTransfer

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;
}
Also used : Account(org.jbei.ice.storage.model.Account) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 24 with AccountTransfer

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;
}
Also used : AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 25 with AccountTransfer

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);
}
Also used : AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Aggregations

AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)31 Account (org.jbei.ice.storage.model.Account)10 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)6 RemotePartner (org.jbei.ice.storage.model.RemotePartner)6 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)5 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Group (org.jbei.ice.storage.model.Group)4 PermissionException (org.jbei.ice.lib.access.PermissionException)3 Results (org.jbei.ice.lib.dto.common.Results)3 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)3 Folder (org.jbei.ice.storage.model.Folder)3 Test (org.junit.Test)3 TraceSequenceAnalysis (org.jbei.ice.lib.dto.entry.TraceSequenceAnalysis)2 Message (org.jbei.ice.storage.model.Message)2 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 RemoteAccess (org.jbei.ice.lib.access.RemoteAccess)1 AccountController (org.jbei.ice.lib.account.AccountController)1