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());
}
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();
}
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;
}
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;
}
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;
}
}
Aggregations