Search in sources :

Example 11 with RemotePartner

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

the class GroupsTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    Account account = AccountCreator.createTestAccount("GroupsTest.testUpdate", false);
    // create local test accounts
    Account account1 = AccountCreator.createTestAccount("GroupsTest.testUpdate1", false);
    Account account2 = AccountCreator.createTestAccount("GroupsTest.testUpdate2", false);
    Account account3 = AccountCreator.createTestAccount("GroupsTest.testUpdate3", false);
    // create remote test accounts
    RemotePartner partner = new RemotePartner();
    partner.setUrl("registry-test2.jbei.org");
    partner = DAOFactory.getRemotePartnerDAO().create(partner);
    RemoteUser remoteUser1 = new RemoteUser();
    remoteUser1.setUser(new AccountTransfer("Remote.GroupsTest.testUpdate1", ""));
    remoteUser1.setPartner(partner.toDataTransferObject());
    RemoteUser remoteUser2 = new RemoteUser();
    remoteUser2.setUser(new AccountTransfer("Remote.GroupsTest.testUpdate2", ""));
    remoteUser2.setPartner(partner.toDataTransferObject());
    RemoteUser remoteUser3 = new RemoteUser();
    remoteUser3.setUser(new AccountTransfer("Remote.GroupsTest.testUpdate3", ""));
    remoteUser3.setPartner(partner.toDataTransferObject());
    // create group with account1, account2 and remote1, remote2 as a members
    UserGroup group = new UserGroup();
    group.setLabel("label");
    group.setDescription("description");
    group.getMembers().add(account1.toDataTransferObject());
    group.getMembers().add(account2.toDataTransferObject());
    group.getRemoteMembers().add(remoteUser1);
    group.getRemoteMembers().add(remoteUser2);
    Groups groups = new Groups(account.getEmail());
    UserGroup result = groups.addGroup(group);
    Assert.assertNotNull(result);
    // get members and test
    result = groups.getGroupMembers(result.getId());
    Assert.assertNotNull(result);
    Assert.assertEquals(2, result.getMembers().size());
    Assert.assertEquals(2, result.getRemoteMembers().size());
    // update group to account2 as the only local and 1 remote account
    result.getMembers().clear();
    result.getRemoteMembers().clear();
    result.getMembers().add(account3.toDataTransferObject());
    result.getRemoteMembers().add(remoteUser3);
    // update
    result.setLabel("updated label");
    result.setDescription("updated description");
    Assert.assertTrue(groups.update(result.getId(), result));
    // get members and test
    group = groups.getGroupMembers(result.getId());
    Assert.assertEquals("updated label", group.getLabel());
    Assert.assertEquals("updated description", group.getDescription());
    Assert.assertEquals(1, group.getMembers().size());
    Assert.assertEquals(account3.getEmail(), group.getMembers().get(0).getEmail());
    Assert.assertEquals(1, group.getRemoteMembers().size());
    Assert.assertEquals(remoteUser3.getUser().getEmail(), group.getRemoteMembers().get(0).getUser().getEmail());
}
Also used : Account(org.jbei.ice.storage.model.Account) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Test(org.junit.Test)

Example 12 with RemotePartner

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

the class TokenVerification method verifyPartnerToken.

public RegistryPartner verifyPartnerToken(String url, String token) {
    RemotePartner remotePartner = DAOFactory.getRemotePartnerDAO().getByUrl(url);
    if (remotePartner == null)
        return null;
    String hash = this.tokenHash.encrypt(token + url, remotePartner.getSalt());
    if (!hash.equals(remotePartner.getAuthenticationToken()))
        return null;
    return remotePartner.toDataTransferObject();
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner)

Example 13 with RemotePartner

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

the class WebSearch method run.

/**
 * Searches all registries in the web of registries configuration with this
 * registry. Without some sort of indexing locally or in some central location,
 * this will be slow for large numbers of results
 *
 * @param query               wrapper around search query
 * @param includeThisInstance whether to include results from this instance of ICE
 * @return list of search results
 */
public WebSearchResults run(SearchQuery query, boolean includeThisInstance) {
    List<RemotePartner> partners = this.remotePartnerDAO.getRegistryPartners();
    if (partners == null)
        return null;
    List<SearchTask> searchTasks = new LinkedList<>();
    // for each approved partner run the search task
    for (RemotePartner partner : partners) {
        if (partner.getUrl() == null || partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
            continue;
        SearchTask task = runSearchThread(partner, query);
        searchTasks.add(task);
    }
    WebSearchResults searchResults = new WebSearchResults(searchTasks.size() + 1);
    // String inWWoR = Utils.getConfigValue(ConfigurationKey.JOIN_WEB_OF_REGISTRIES);
    if (includeThisInstance) {
        SearchIndexes searchIndexes = new SearchIndexes();
        SearchResults results = searchIndexes.runSearch(null, query);
        searchResults.setQuery(query);
        WebResult thisResult = new WebResult();
        thisResult.getResults().addAll(results.getResults());
        thisResult.setCount(results.getResultCount());
        String url = Utils.getConfigValue(ConfigurationKey.URI_PREFIX);
        String projectName = Utils.getConfigValue(ConfigurationKey.PROJECT_NAME);
        RegistryPartner thisPartner = new RegistryPartner();
        thisPartner.setUrl(url);
        thisPartner.setName(projectName);
        thisResult.setPartner(thisPartner);
        searchResults.getResults().add(thisResult);
        searchResults.setTotalCount(thisResult.getCount());
    }
    // go through tasks and check if completed
    while (!searchTasks.isEmpty()) {
        Iterator<SearchTask> iterator = searchTasks.iterator();
        // todo : set time limit and abandon task (shutdown) if exceeded (or after give it till after this instance is searched)
        while (iterator.hasNext()) {
            SearchTask task = iterator.next();
            TaskStatus status = task.getStatus();
            if (status == TaskStatus.COMPLETED || status == TaskStatus.EXCEPTION) {
                iterator.remove();
                if (status == TaskStatus.COMPLETED) {
                    WebResult webResult = new WebResult();
                    webResult.setPartner(task.getPartner().toDataTransferObject());
                    SearchResults partnerResults = task.getResults();
                    webResult.setCount(partnerResults.getResultCount());
                    webResult.getResults().addAll(partnerResults.getResults());
                    searchResults.getResults().add(webResult);
                    searchResults.setTotalCount(searchResults.getTotalCount() + partnerResults.getResultCount());
                }
            }
        }
    }
    return searchResults;
}
Also used : SearchResults(org.jbei.ice.lib.dto.search.SearchResults) TaskStatus(org.jbei.ice.lib.executor.TaskStatus) LinkedList(java.util.LinkedList) RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner)

Example 14 with RemotePartner

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

the class WoRController method removeWebPartner.

/**
 * Removes the web partner uniquely identified by the url
 *
 * @param partnerUrl url identifier for partner
 */
public boolean removeWebPartner(String userId, String partnerUrl) {
    if (!new AccountController().isAdministrator(userId))
        return false;
    RemotePartner partner = dao.getByUrl(partnerUrl);
    if (partner == null)
        return true;
    dao.delete(partner);
    return true;
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccountController(org.jbei.ice.lib.account.AccountController)

Example 15 with RemotePartner

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

the class WoRController method updateWebPartner.

public boolean updateWebPartner(String userId, String url, RegistryPartner partner) {
    if (!new AccountController().isAdministrator(userId))
        return false;
    Logger.info(userId + ": updating partner (" + url + ") to " + partner.toString());
    RemotePartner existing = dao.getByUrl(url);
    if (existing == null)
        return false;
    if (partner.getStatus() == existing.getPartnerStatus())
        return true;
    // contact remote with new api key that allows them to contact this instance
    String apiKey = Utils.generateToken();
    String myURL = Utils.getConfigValue(ConfigurationKey.URI_PREFIX);
    String myName = Utils.getConfigValue(ConfigurationKey.PROJECT_NAME);
    RegistryPartner thisPartner = new RegistryPartner();
    thisPartner.setUrl(myURL);
    thisPartner.setName(myName);
    // key to use in contacting this instance
    thisPartner.setApiKey(apiKey);
    IceRestClient client = new IceRestClient(partner.getUrl(), partner.getApiKey());
    try {
        client.post("/rest/web/partner/remote", thisPartner, RegistryPartner.class);
        existing.setPartnerStatus(partner.getStatus());
        existing.setAuthenticationToken(apiKey);
        dao.update(existing);
        return true;
    } catch (Exception e) {
        Logger.error(e);
        return false;
    }
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) IceRestClient(org.jbei.ice.services.rest.IceRestClient) AccountController(org.jbei.ice.lib.account.AccountController)

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