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