Search in sources :

Example 21 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class WebEntries method getSequence.

public FeaturedDNASequence getSequence(String entryId) {
    String recordId;
    try {
        long id = Long.decode(entryId);
        Entry entry = this.entryDAO.get(id);
        if (entry == null)
            recordId = entryId;
        else
            recordId = entry.getRecordId();
    } catch (NumberFormatException ex) {
        recordId = entryId;
    }
    List<RemotePartner> partners = this.remotePartnerDAO.getRegistryPartners();
    for (RemotePartner partner : partners) {
        if (partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
            continue;
        FeaturedDNASequence sequence = this.remoteContact.getPublicEntrySequence(partner.getUrl(), recordId, partner.getApiKey());
        if (sequence != null)
            return sequence;
    }
    return null;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) RemotePartner(org.jbei.ice.storage.model.RemotePartner) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 22 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner 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 23 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class RemoteTransfer method transferFolder.

public FolderDetails transferFolder(long remoteId, FolderDetails folderDetails, List<Long> remoteIds) {
    RemotePartner partner = this.remotePartnerDAO.get(remoteId);
    if (partner == null)
        throw new IllegalArgumentException("Invalid remote host id: " + remoteId);
    FolderDetails details = remoteContact.transferFolder(partner.getUrl(), folderDetails);
    if (folderDetails == null) {
        Logger.error("Could not create remote folder");
        return null;
    }
    if (remoteIds == null || remoteIds.isEmpty()) {
        Logger.info("Skipping transfer of entries. List is empty");
        return details;
    }
    // move entries to the transferred entries
    EntrySelection entrySelection = new EntrySelection();
    entrySelection.getEntries().addAll(remoteIds);
    entrySelection.getDestination().add(details);
    entrySelection.setSelectionType(EntrySelectionType.FOLDER);
    remoteContact.addTransferredEntriesToFolder(partner.getUrl(), entrySelection);
    return details;
}
Also used : EntrySelection(org.jbei.ice.lib.entry.EntrySelection) RemotePartner(org.jbei.ice.storage.model.RemotePartner) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails)

Example 24 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class WoRController method getRegistryPartners.

public WebOfRegistries getRegistryPartners(boolean approvedOnly) {
    WebOfRegistries webOfRegistries = new WebOfRegistries();
    webOfRegistries.setWebEnabled(isWebEnabled());
    // retrieve actual partners
    List<RemotePartner> partners = dao.getRegistryPartners();
    ArrayList<RegistryPartner> registryPartners = new ArrayList<>();
    for (RemotePartner partner : partners) {
        if (approvedOnly && partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
            continue;
        registryPartners.add(partner.toDataTransferObject());
    }
    webOfRegistries.setPartners(registryPartners);
    return webOfRegistries;
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) WebOfRegistries(org.jbei.ice.lib.dto.web.WebOfRegistries) ArrayList(java.util.ArrayList)

Example 25 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class RemoteContact method handleRemoteRemoveRequest.

public boolean handleRemoteRemoveRequest(String worToken, String url) {
    if (StringUtils.isEmpty(worToken) || StringUtils.isEmpty(url))
        return false;
    RemotePartner partner = dao.getByUrl(url);
    if (partner == null)
        return false;
    if (!partner.getAuthenticationToken().equals(tokenHash.encrypt(worToken, partner.getSalt()))) {
        Logger.error("Attempt to remove remote partner " + url + " with invalid worToken " + worToken);
        return false;
    }
    Logger.info("Deleting partner '" + url + "' at their request");
    // todo : contact other instances (if this is a master node)
    dao.delete(partner);
    return true;
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner)

Aggregations

RemotePartner (org.jbei.ice.storage.model.RemotePartner)34 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)10 Account (org.jbei.ice.storage.model.Account)8 PermissionException (org.jbei.ice.lib.access.PermissionException)7 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)6 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)4 Folder (org.jbei.ice.storage.model.Folder)4 RemoteAccessModel (org.jbei.ice.storage.model.RemoteAccessModel)4 Test (org.junit.Test)4 PartData (org.jbei.ice.lib.dto.entry.PartData)3 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)3 Entry (org.jbei.ice.storage.model.Entry)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HibernateException (org.hibernate.HibernateException)2 AccountController (org.jbei.ice.lib.account.AccountController)2 IceRestClient (org.jbei.ice.services.rest.IceRestClient)2 DAOException (org.jbei.ice.storage.DAOException)2 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)2