Search in sources :

Example 11 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class BulkUploads 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 if lacking permissions
 */
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 12 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class RemoteAccess method add.

/**
 * // todo : check if already shared
 * Add access privileges for a user on this instance to enable access
 * to a (currently folder only) resource on a remote ICE instance
 *
 * @param partner          remote partner requesting add
 * @param accessPermission details of access privilege, including access token and user on this instance
 *                         that the permission is for
 * @throws IllegalArgumentException if the permission details is missing some required information or has invalid
 *                                  information. e.g. the specified user does not exist on this ICE instance
 * @throws PermissionException      if this instance is not in a web of registries configuration or it is but
 *                                  not with the specified partner
 */
public AccessPermission add(RegistryPartner partner, AccessPermission accessPermission) {
    if (!isInWebOfRegistries())
        throw new PermissionException("This ICE instance doesn't have WoR enabled");
    // person on this site that the permission is for
    String userId = accessPermission.getUserId();
    // verify that it is valid
    Account account = accountDAO.getByEmail(userId);
    if (account == null)
        throw new IllegalArgumentException("Email address " + userId + " not on this registry instance");
    // remote person doing the sharing
    AccountTransfer accountTransfer = accessPermission.getAccount();
    if (accountTransfer == null || StringUtils.isEmpty(accountTransfer.getEmail()))
        throw new IllegalArgumentException("Remote sharer information not available");
    // read or write permission
    if (!accessPermission.isCanRead() && !accessPermission.isCanWrite())
        throw new IllegalArgumentException("Invalid read/write values for permission. Both are false");
    // verify secret token
    if (StringUtils.isEmpty(accessPermission.getSecret()))
        throw new IllegalArgumentException("No access token sent with permission");
    // get the remote partner object
    RemotePartner remotePartner = remotePartnerDAO.getByUrl(partner.getUrl());
    if (remotePartner == null)
        throw new IllegalArgumentException("Cannot retrieve remote partner with url " + partner.getUrl());
    // email of remote user making share request
    String remoteEmail = accountTransfer.getEmail();
    // todo : can also be single entry sharing
    // create a local folder instance that references a remote folder (can also acts like a cache)
    // if remote folder already exists then retrieve it and share that
    Folder folder = getOrCreateRemoteFolder(accessPermission.getDisplay(), Long.toString(accessPermission.getTypeId()), remoteEmail);
    // get or create the client for the remote user who is sharing the folder
    RemoteClientModel remoteClientModel = getOrCreateRemoteClient(remoteEmail, remotePartner);
    // store access permission to remote folder for referenced account
    Permission permission = createPermissionModel(accessPermission, folder, account);
    // remote access model associated with permission and remote client for storing secret
    RemoteAccessModel remoteAccessModel = createRemoteAccessModel(accessPermission, remoteClientModel, permission);
    return remoteAccessModel.toDataTransferObject();
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 13 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class ApiKey method toDataTransferObject.

@Override
public AccessKey toDataTransferObject() {
    AccessKey accessKey = new AccessKey();
    accessKey.setId(this.id);
    accessKey.setSecret(this.secret);
    accessKey.setClientId(this.clientId);
    accessKey.setCreationTime(this.creationTime.getTime());
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setEmail(this.ownerEmail);
    if (this.allowDelegate != null)
        accessKey.setAllowDelegate(this.allowDelegate);
    if (this.readOnly != null)
        accessKey.setReadOnly(this.readOnly);
    accessKey.setAccount(accountTransfer);
    return accessKey;
}
Also used : AccessKey(org.jbei.ice.lib.dto.access.AccessKey) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 14 with AccountTransfer

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

Example 15 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class AccountCreator method createTestAccount.

public static Account createTestAccount(String testName, boolean admin) throws Exception {
    String email = testName + "@TESTER";
    AccountDAO dao = DAOFactory.getAccountDAO();
    Account account = dao.getByEmail(email);
    if (account != null)
        throw new Exception("duplicate account");
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setFirstName("TEST_FNAME");
    accountTransfer.setLastName("TEST");
    accountTransfer.setEmail(email);
    accountTransfer = new AccountController().createNewAccount(accountTransfer, false);
    Assert.assertNotNull(accountTransfer.getPassword());
    account = dao.getByEmail(email);
    Assert.assertNotNull(account);
    if (admin) {
        account.setType(AccountType.ADMIN);
        dao.update(account);
    }
    return account;
}
Also used : Account(org.jbei.ice.storage.model.Account) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) AccountController(org.jbei.ice.lib.account.AccountController)

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