Search in sources :

Example 26 with RegistryPartner

use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.

the class RemotePartner method toDataTransferObject.

@Override
public RegistryPartner toDataTransferObject() {
    RegistryPartner registryPartner = new RegistryPartner();
    registryPartner.setId(this.id);
    registryPartner.setName(this.name);
    if (this.added != null)
        registryPartner.setAddTime(this.added.getTime());
    if (this.lastContact != null)
        registryPartner.setLastContactTime(this.lastContact.getTime());
    registryPartner.setUrl(this.url);
    registryPartner.setStatus(this.partnerStatus);
    registryPartner.setSent(getSent());
    registryPartner.setFetched(fetched);
    //        registryPartner.setApiKey(apiKey);
    return registryPartner;
}
Also used : RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner)

Example 27 with RegistryPartner

use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.

the class WebPartners method addNewPartner.

/**
     * Adds the registry instance specified by the url to the list of existing partners (if not already in there)
     * and sends a request to the remote instance that includes a security token that the remote instance
     * can use to communicate with this instance.
     * <p>
     * Information about the remote instance is still saved even when it cannot be communicated with. This
     * allows a future communication attempt.
     *
     * @param userId  id of user performing action (must have admin privileges)
     * @param partner registry partner object that contains unique uniform resource identifier & name for the registry
     * @return add partner ofr
     */
public RegistryPartner addNewPartner(String userId, RegistryPartner partner) {
    if (!isInWebOfRegistries())
        return null;
    // check for admin privileges before granting request
    if (!accountController.isAdministrator(userId))
        throw new PermissionException("Non admin attempting to add remote partner");
    if (StringUtils.isEmpty(partner.getUrl()))
        throw new IllegalArgumentException("Cannot add partner without valid url");
    // check if there is a partner with that url
    RemotePartner remotePartner = dao.getByUrl(partner.getUrl());
    if (remotePartner != null) {
        // if so just update the api key
        return updateAPIKey(userId, remotePartner.getId());
    }
    Logger.info(userId + ": adding WoR partner [" + partner.getUrl() + "]");
    // create information about this instance to send to potential partner
    // including a random token for use when contacting this instance
    RegistryPartner thisPartner = getThisInstanceWithNewApiKey();
    if (thisPartner == null) {
        // will not contact
        Logger.error("Cannot exchange api token with remote host due to invalid local url");
        partner.setStatus(RemotePartnerStatus.NOT_CONTACTED);
    } else {
        RegistryPartner newPartner = remoteContact.contactPotentialPartner(thisPartner, partner.getUrl());
        if (newPartner == null) {
            // contact failed
            Logger.error("Remote contact of partner " + partner.getUrl() + " failed");
            partner.setStatus(RemotePartnerStatus.CONTACT_FAILED);
        } else {
            // contact succeeded with return of api key
            partner.setStatus(RemotePartnerStatus.APPROVED);
            partner.setApiKey(newPartner.getApiKey());
        }
    }
    // if status is not approved, then the token is irrelevant since it is not stored and was not
    // successfully transmitted
    String apiKey = thisPartner != null ? thisPartner.getApiKey() : null;
    return createRemotePartnerObject(partner, apiKey);
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner)

Example 28 with RegistryPartner

use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.

the class WebPartners method getPartners.

/**
     * Retrieves list of partners for this instance
     *
     * @return list of partners available for this ICE instance or an empty list if this instance is not in web of
     * registries
     */
public List<RegistryPartner> getPartners() {
    if (!isInWebOfRegistries())
        return new ArrayList<>();
    List<RemotePartner> partners = dao.getRegistryPartners();
    List<RegistryPartner> registryPartners = new ArrayList<>();
    if (partners == null)
        return registryPartners;
    for (RemotePartner remotePartner : partners) {
        registryPartners.add(remotePartner.toDataTransferObject());
    }
    return registryPartners;
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) ArrayList(java.util.ArrayList)

Example 29 with RegistryPartner

use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.

the class FolderResource method read.

/**
     * Retrieves the entries for specified folder. Handles request
     * from a local client (ui) or from a remote ice instance
     *
     * @return list of retrieved entries wrapped in folder object
     */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entries")
public FolderDetails read(@PathParam("id") final String folderId, @DefaultValue("0") @QueryParam("offset") final int offset, @DefaultValue("15") @QueryParam("limit") final int limit, @DefaultValue("created") @QueryParam("sort") final String sort, @DefaultValue("false") @QueryParam("asc") final boolean asc, @DefaultValue("") @QueryParam("filter") String filter, // todo: move to headers
@QueryParam("token") String token, // todo : ditto
@QueryParam("userId") String remoteUserId, @QueryParam("fields") List<String> queryParam) {
    try {
        final ColumnField field = ColumnField.valueOf(sort.toUpperCase());
        if (folderId.equalsIgnoreCase("public")) {
            // todo : move to separate rest resource path
            RegistryPartner registryPartner = requireWebPartner();
            // return public entries
            log(registryPartner.getUrl(), "requesting public entries");
            return this.controller.getPublicEntries(field, offset, limit, asc);
        }
        // userId can be empty for public folders
        String userId = super.getUserId();
        try {
            final long id = Long.decode(folderId);
            String message = "retrieving folder " + id + " entries";
            if (filter.length() > 0)
                message += " filtered by \"" + filter + "\"";
            FolderContents folderContents = new FolderContents();
            PageParameters pageParameters = new PageParameters(offset, limit, field, asc, filter);
            if (StringUtils.isEmpty(userId)) {
                if (// todo :verify partner?
                StringUtils.isEmpty(token))
                    return folderContents.getContents(userId, id, pageParameters);
                // get registry partner
                RegistryPartner partner = requireWebPartner();
                log(partner.getUrl(), message);
                return folderContents.getRemotelySharedContents(remoteUserId, token, partner, id, pageParameters);
            } else {
                log(userId, message);
                return folderContents.getContents(userId, id, pageParameters);
            }
        } catch (final NumberFormatException nfe) {
            Logger.error("Passed folder id " + folderId + " is not a number");
            return null;
        }
    } catch (PermissionException e) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) ColumnField(org.jbei.ice.lib.shared.ColumnField) PageParameters(org.jbei.ice.lib.dto.common.PageParameters)

Example 30 with RegistryPartner

use of org.jbei.ice.lib.dto.web.RegistryPartner in project ice by JBEI.

the class AccessTokenResource method getWebPartner.

/**
     * Validates web of registries access token (api key)
     */
@GET
@Path("/web")
public Response getWebPartner(@QueryParam("url") String url) {
    WebPartners partners = new WebPartners();
    RegistryPartner partner = partners.get(worPartnerToken, url);
    return super.respond(partner);
}
Also used : WebPartners(org.jbei.ice.lib.net.WebPartners) 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