use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.
the class RemoteContact method apiKeyValidates.
/**
* Contacts the registry partner at the specified url, to ensure that the API key validates.
*
* @param myURL the url of this ICE instance
* @param registryPartner partner infor
* @return true if the api key validated successfully with the specified url, false otherwise (including when
* the instance cannot be contacted)
*/
public boolean apiKeyValidates(String myURL, RegistryPartner registryPartner) {
if (StringUtils.isEmpty(registryPartner.getApiKey()))
return false;
HashMap<String, Object> queryParams = new HashMap<>();
queryParams.put("url", myURL);
RegistryPartner response = restClient.getWor(registryPartner.getUrl(), "/rest/accesstokens/web", RegistryPartner.class, queryParams, registryPartner.getApiKey());
if (response == null) {
// todo : should retry up to a certain number of times
Logger.error("Could not validate request");
return false;
}
return true;
}
use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.
the class RemoteContact method contactPotentialPartner.
// exchange api key with remote partner
// send to remote in order to trigger an api exchange. Note that the remote partner will
public RegistryPartner contactPotentialPartner(RegistryPartner thisPartner, String remotePartnerUrl) {
AccessTokens.setToken(remotePartnerUrl, thisPartner.getApiKey());
RegistryPartner newPartner = restClient.post(remotePartnerUrl, "/rest/partners", thisPartner, RegistryPartner.class, null);
AccessTokens.removeToken(remotePartnerUrl);
return newPartner;
}
use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.
the class Groups method addGroup.
/**
* Adds group to the list of groups for current user
*
* @param userGroup information about group to be added, including members (local and remote)
* @return added group
*/
public UserGroup addGroup(UserGroup userGroup) {
if (userGroup.getType() == null)
userGroup.setType(GroupType.PRIVATE);
if (userGroup.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
String errMsg = "Non admin '" + userId + "' attempting to create public group";
Logger.error(errMsg);
throw new PermissionException(errMsg);
}
Account account = accountDAO.getByEmail(userId);
Group group = new Group();
group.setUuid(Utils.generateUUID());
group.setLabel(userGroup.getLabel());
group.setDescription(userGroup.getDescription() == null ? "" : userGroup.getDescription());
group.setType(userGroup.getType());
group.setOwner(account);
group.setAutoJoin(userGroup.isAutoJoin());
group.setCreationTime(new Date());
group = dao.create(group);
// add local members
if (userGroup.getMembers() != null && !userGroup.getMembers().isEmpty()) {
for (AccountTransfer accountTransfer : userGroup.getMembers()) {
Account memberAccount = accountDAO.getByEmail(accountTransfer.getEmail());
if (memberAccount == null)
continue;
group.getMembers().add(memberAccount);
memberAccount.getGroups().add(group);
accountDAO.update(memberAccount);
}
}
// add remote members
for (RemoteUser remoteUser : userGroup.getRemoteMembers()) {
RegistryPartner partner = remoteUser.getPartner();
if (partner == null)
continue;
RemotePartner remotePartner = remotePartnerDAO.get(partner.getId());
if (remotePartner == null)
continue;
AccountTransfer accountTransfer = remoteUser.getUser();
if (accountTransfer == null || StringUtils.isEmpty(accountTransfer.getEmail()))
continue;
String email = accountTransfer.getEmail();
RemoteClientModel remoteClientModel = remoteClientModelDAO.getModel(email, remotePartner);
if (remoteClientModel == null) {
remoteClientModel = new RemoteClientModel();
remoteClientModel.setEmail(email);
remoteClientModel.setRemotePartner(remotePartner);
remoteClientModel = remoteClientModelDAO.create(remoteClientModel);
}
remoteClientModel.getGroups().add(group);
remoteClientModelDAO.update(remoteClientModel);
}
return group.toDataTransferObject();
}
use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.
the class FolderResource method addSelectedEntriesToFolders.
/**
* Adds contents referenced in the <code>entrySelection</code> object
* to the folders also referenced in the same object
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/entries")
public Response addSelectedEntriesToFolders(final EntrySelection entrySelection, @QueryParam("token") String remoteUserToken, @QueryParam("userId") String remoteUserId, @QueryParam("folderId") long fid) {
final String userId = getUserId();
final FolderContents folderContents = new FolderContents();
if (StringUtils.isEmpty(userId) && !StringUtils.isEmpty(remoteUserToken)) {
// check others
log(remoteUserId, " remotely adding entries to folders");
RegistryPartner registryPartner = requireWebPartner();
return super.respond(folderContents.remotelyAddEntrySelection(remoteUserId, fid, remoteUserToken, entrySelection, registryPartner));
} else {
log(userId, "adding entries to folders");
folderContents.addEntrySelection(userId, entrySelection);
return super.respond(true);
}
}
use of org.jbei.ice.lib.dto.web.RegistryPartner 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) {
SearchController searchController = new SearchController();
SearchResults results = searchController.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;
}
Aggregations