Search in sources :

Example 26 with AccountTransfer

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

the class RemoteAccessTest method testAdd.

@Test
public void testAdd() throws Exception {
    new ConfigurationSettings().setPropertyValue(ConfigurationKey.JOIN_WEB_OF_REGISTRIES, "true");
    // this tests the scenario where a WoR partner shares a remote resource (folder or entry) with a user
    // on another instance
    Account account = AccountCreator.createTestAccount("RemoteAccessTest.testAdd", false);
    RemoteAccess remoteAccess = new RemoteAccess();
    // create mock remote partner
    RemotePartner partner = new RemotePartner();
    partner.setUrl("remote-test.jbei.org");
    partner = DAOFactory.getRemotePartnerDAO().create(partner);
    // create permission to share with this user
    AccessPermission permission = new AccessPermission();
    AccountTransfer accountTransfer = new AccountTransfer();
    // person sharing
    accountTransfer.setEmail("I wanna share from far away");
    permission.setAccount(accountTransfer);
    permission.setDisplay("Folder Name");
    permission.setUserId(account.getEmail());
    permission.setType(AccessPermission.Type.READ_FOLDER);
    permission.setTypeId(Integer.MAX_VALUE);
    permission.setSecret("supersekrit");
    AccessPermission accessPermission = remoteAccess.add(partner.toDataTransferObject(), permission);
    Folder folder = DAOFactory.getFolderDAO().get(accessPermission.getTypeId());
    RemoteAccessModel model = DAOFactory.getRemoteAccessModelDAO().getByFolder(account, folder);
    Assert.assertNotNull(model);
    // shared folder should be in list of shared collection
    Collections collections = new Collections(account.getEmail());
    List<FolderDetails> subFolders = collections.getSubFolders(CollectionType.SHARED);
    boolean found = false;
    for (FolderDetails details : subFolders) {
        found = details.getName().equalsIgnoreCase(permission.getDisplay()) && Long.toString(permission.getTypeId()).equals(details.getDescription());
        if (found)
            break;
    }
    Assert.assertTrue(found);
}
Also used : Account(org.jbei.ice.storage.model.Account) RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) ConfigurationSettings(org.jbei.ice.lib.config.ConfigurationSettings) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder) Collections(org.jbei.ice.lib.folder.collection.Collections) RemoteAccessModel(org.jbei.ice.storage.model.RemoteAccessModel) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) Test(org.junit.Test)

Example 27 with AccountTransfer

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

the class Account method toDataTransferObject.

public AccountTransfer toDataTransferObject() {
    AccountTransfer info = new AccountTransfer();
    info.setEmail(email);
    info.setFirstName(firstName);
    info.setLastName(lastName);
    info.setInstitution(institution);
    info.setDescription(description);
    if (lastLoginTime != null)
        info.setLastLogin(lastLoginTime.getTime());
    if (this.type != null)
        info.setAccountType(this.type);
    else
        info.setAccountType(AccountType.NORMAL);
    if (this.creationTime != null)
        info.setRegisterDate(this.creationTime.getTime());
    info.setId(id);
    return info;
}
Also used : AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 28 with AccountTransfer

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

the class FolderController method createTransferredFolder.

public FolderDetails createTransferredFolder(FolderDetails folderDetails) {
    Folder folder = new Folder(folderDetails.getName());
    AccountTransfer owner = folderDetails.getOwner();
    if (owner != null)
        folder.setOwnerEmail(owner.getEmail());
    else
        folder.setOwnerEmail("transferred");
    folder.setType(FolderType.TRANSFERRED);
    folder.setCreationTime(new Date(folderDetails.getCreationTime()));
    folder = dao.create(folder);
    return folder.toDataTransferObject();
}
Also used : Folder(org.jbei.ice.storage.model.Folder) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 29 with AccountTransfer

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

the class FolderContents method getRemoteContents.

/**
 * Retrieves contents of a folder that has been shared remotely with this instance
 *
 * @param userId user folder is shared with
 * @param folder remote shared folder
 * @return wrapper around entries conforming to specified parameters
 * @throws IllegalArgumentException if the folder is not of type <code>REMOTE</code>
 */
private FolderDetails getRemoteContents(String userId, Folder folder, PageParameters pageParameters) {
    if (folder.getType() != FolderType.REMOTE) {
        String errorMessage = "Folder " + folder.getId() + " is not remote and therefore cannot retrieve contents";
        Logger.error(errorMessage);
        throw new IllegalArgumentException(errorMessage);
    }
    // get remote access
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    RemoteAccessModel remoteAccessModel = remoteAccessModelDAO.getByFolder(account, folder);
    if (remoteAccessModel == null) {
        Logger.error("Could not find access model for folder " + folder.getId() + " and user " + userId);
        return null;
    }
    FolderDetails details = folder.toDataTransferObject();
    RemoteClientModel remoteClientModel = remoteAccessModel.getRemoteClientModel();
    AccountTransfer owner = new AccountTransfer();
    owner.setEmail(remoteClientModel.getEmail());
    details.setOwner(owner);
    RemotePartner remotePartner = remoteClientModel.getRemotePartner();
    details.setRemotePartner(remotePartner.toDataTransferObject());
    String token = remoteAccessModel.getToken();
    // todo : currently folder id only
    long remoteFolderId = Long.decode(remoteAccessModel.getIdentifier());
    // retrieve entries from remote partner (ends up in the call below)
    FolderDetails remoteDetails = remoteContact.getRemoteContents(remotePartner.getUrl(), userId, remoteFolderId, token, pageParameters, remotePartner.getApiKey());
    if (remoteDetails == null) {
        Logger.error("Could not retrieve remote shared folder " + remoteFolderId + " from " + remotePartner.getUrl());
        return null;
    }
    details.setCount(remoteDetails.getCount());
    details.setEntries(remoteDetails.getEntries());
    return details;
}
Also used : FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 30 with AccountTransfer

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

the class Folders method getCanEditFolders.

/**
 * Retrieves list of folders that specified user has write privileges on.
 * This excludes folders that are of type <code>SAMPLE</code>
 *
 * @return list of folders
 */
public List<FolderDetails> getCanEditFolders() {
    Account account = this.accountDAO.getByEmail(userId);
    Set<Group> accountGroups = getAccountGroups(account);
    List<Folder> folders = dao.getCanEditFolders(account, accountGroups);
    ArrayList<FolderDetails> result = new ArrayList<>();
    for (Folder folder : folders) {
        FolderDetails details = folder.toDataTransferObject();
        if (folder.getType() == FolderType.REMOTE) {
            RemoteAccessModel model = remoteAccessModelDAO.getByFolder(account, folder);
            if (model == null) {
                result.add(details);
                continue;
            }
            AccountTransfer owner = new AccountTransfer();
            owner.setEmail(model.getRemoteClientModel().getEmail());
            details.setOwner(owner);
            RemotePartner remotePartner = model.getRemoteClientModel().getRemotePartner();
            details.setRemotePartner(remotePartner.toDataTransferObject());
        }
        result.add(details);
    }
    return result;
}
Also used : FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) 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