Search in sources :

Example 1 with IceRestClient

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;
    }
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) IceRestClient(org.jbei.ice.services.rest.IceRestClient) AccountController(org.jbei.ice.lib.account.AccountController)

Aggregations

AccountController (org.jbei.ice.lib.account.AccountController)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1 IceRestClient (org.jbei.ice.services.rest.IceRestClient)1 RemotePartner (org.jbei.ice.storage.model.RemotePartner)1