use of org.jbei.ice.services.rest.IceRestClient 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 = IceRestClient.getInstance();
try {
client.post(partner.getUrl(), "/rest/web/partner/remote", thisPartner, RegistryPartner.class, null);
existing.setPartnerStatus(partner.getStatus());
existing.setAuthenticationToken(apiKey);
dao.update(existing);
return true;
} catch (Exception e) {
Logger.error(e);
return false;
}
}
Aggregations