Search in sources :

Example 1 with RegistryPartner

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;
}
Also used : HashMap(java.util.HashMap) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner)

Example 2 with RegistryPartner

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;
}
Also used : RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner)

Example 3 with RegistryPartner

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();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) RemotePartner(org.jbei.ice.storage.model.RemotePartner) RemoteClientModel(org.jbei.ice.storage.model.RemoteClientModel) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 4 with RegistryPartner

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);
    }
}
Also used : RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner)

Example 5 with RegistryPartner

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

Aggregations

RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)33 RemotePartner (org.jbei.ice.storage.model.RemotePartner)11 PermissionException (org.jbei.ice.lib.access.PermissionException)6 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)3 Account (org.jbei.ice.storage.model.Account)3 ArrayList (java.util.ArrayList)2 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 RemoteAccess (org.jbei.ice.lib.access.RemoteAccess)1 TokenVerification (org.jbei.ice.lib.access.TokenVerification)1 AccountController (org.jbei.ice.lib.account.AccountController)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)1