use of org.hyperledger.fabric_ca.sdk.exception.AffiliationException in project fabric-sdk-java by hyperledger.
the class HFCAAffiliation method delete.
/**
* delete an affiliation
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @param force Forces the deletion of affiliation
* @return Response of request
* @throws AffiliationException if deleting an affiliation fails.
* @throws InvalidArgumentException
*/
public HFCAAffiliationResp delete(User registrar, boolean force) throws AffiliationException, InvalidArgumentException {
if (this.deleted) {
throw new AffiliationException("Affiliation has been deleted");
}
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
String deleteURL = "";
try {
Map<String, String> queryParm = new HashMap<String, String>();
queryParm.put("force", String.valueOf(force));
deleteURL = client.getURL(HFCA_AFFILIATION + "/" + this.name, queryParm);
logger.debug(format("affiliation url: %s, registrar: %s", deleteURL, registrar.getName()));
JsonObject result = client.httpDelete(deleteURL, registrar);
logger.debug(format("identity url: %s, registrar: %s done.", deleteURL, registrar));
this.deleted = true;
return getResponse(result);
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while deleting affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, deleteURL, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
} catch (Exception e) {
String msg = format("Error while deleting affiliation %s url: %s %s ", this.name, deleteURL, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
}
}
use of org.hyperledger.fabric_ca.sdk.exception.AffiliationException in project fabric-sdk-java by hyperledger.
the class HFCAAffiliation method read.
/**
* gets a specific affiliation
*
* @param registrar The identity of the registrar
* @return Returns response
* @throws AffiliationException if getting an affiliation fails.
* @throws InvalidArgumentException
*/
public int read(User registrar) throws AffiliationException, InvalidArgumentException {
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
String readAffURL = "";
try {
readAffURL = HFCA_AFFILIATION + "/" + name;
logger.debug(format("affiliation url: %s, registrar: %s", readAffURL, registrar.getName()));
JsonObject result = client.httpGet(readAffURL, registrar);
logger.debug(format("affiliation url: %s, registrar: %s done.", readAffURL, registrar));
HFCAAffiliationResp resp = getResponse(result);
this.childHFCAAffiliations = resp.getChildren();
this.identities = resp.getIdentities();
this.deleted = false;
return resp.statusCode;
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while getting affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, readAffURL, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
} catch (Exception e) {
String msg = format("Error while getting affiliation %s url: %s %s ", this.name, readAffURL, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
}
}
use of org.hyperledger.fabric_ca.sdk.exception.AffiliationException in project fabric-sdk-java by hyperledger.
the class HFCAAffiliation method update.
/**
* update an affiliation
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @param force Forces updating of child affiliations
* @return Response of request
* @throws AffiliationException If updating an affiliation fails
* @throws InvalidArgumentException
*/
public HFCAAffiliationResp update(User registrar, boolean force) throws AffiliationException, InvalidArgumentException {
if (this.deleted) {
throw new AffiliationException("Affiliation has been deleted");
}
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
if (Utils.isNullOrEmpty(name)) {
throw new InvalidArgumentException("Affiliation name cannot be null or empty");
}
String updateURL = "";
try {
Map<String, String> queryParm = new HashMap<String, String>();
queryParm.put("force", String.valueOf(force));
updateURL = client.getURL(HFCA_AFFILIATION + "/" + this.name, queryParm);
logger.debug(format("affiliation url: %s, registrar: %s", updateURL, registrar.getName()));
String body = client.toJson(affToJsonObject());
JsonObject result = client.httpPut(updateURL, body, registrar);
generateResponse(result);
logger.debug(format("identity url: %s, registrar: %s done.", updateURL, registrar));
HFCAAffiliationResp resp = getResponse(result);
this.childHFCAAffiliations = resp.childHFCAAffiliations;
this.identities = resp.identities;
return getResponse(result);
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while updating affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, updateURL, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
} catch (Exception e) {
String msg = format("Error while updating affiliation %s url: %s %s ", this.name, updateURL, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
}
}
use of org.hyperledger.fabric_ca.sdk.exception.AffiliationException in project fabric-sdk-java by hyperledger.
the class HFCAAffiliation method create.
/**
* create an affiliation
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @param force Forces the creation of parent affiliations
* @return Response of request
* @throws AffiliationException if adding an affiliation fails.
* @throws InvalidArgumentException
*/
public HFCAAffiliationResp create(User registrar, boolean force) throws AffiliationException, InvalidArgumentException {
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
String createURL = "";
try {
createURL = client.getURL(HFCA_AFFILIATION);
logger.debug(format("affiliation url: %s, registrar: %s", createURL, registrar.getName()));
Map<String, String> queryParm = new HashMap<String, String>();
queryParm.put("force", String.valueOf(force));
String body = client.toJson(affToJsonObject());
JsonObject result = client.httpPost(createURL, body, registrar);
logger.debug(format("identity url: %s, registrar: %s done.", createURL, registrar));
this.deleted = false;
return getResponse(result);
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while creating affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, createURL, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
} catch (Exception e) {
String msg = format("Error while creating affiliation %s url: %s %s ", this.name, createURL, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
}
}
use of org.hyperledger.fabric_ca.sdk.exception.AffiliationException in project fabric-sdk-java by hyperledger.
the class HFCAClient method getHFCAAffiliations.
/**
* gets all affiliations that the registrar is allowed to see
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @return The affiliations that were requested
* @throws AffiliationException if getting all affiliations fails
* @throws InvalidArgumentException
*/
public HFCAAffiliation getHFCAAffiliations(User registrar) throws AffiliationException, InvalidArgumentException {
if (cryptoSuite == null) {
throw new InvalidArgumentException("Crypto primitives not set.");
}
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
logger.debug(format("affiliations url: %s, registrar: %s", url, registrar.getName()));
try {
JsonObject result = httpGet(HFCAAffiliation.HFCA_AFFILIATION, registrar);
HFCAAffiliation affiliations = new HFCAAffiliation(result);
logger.debug(format("affiliations url: %s, registrar: %s done.", url, registrar));
return affiliations;
} catch (HTTPException e) {
String msg = format("[HTTP Status Code: %d] - Error while getting all affiliations from url '%s': %s", e.getStatusCode(), url, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
} catch (Exception e) {
String msg = format("Error while getting all affiliations from url '%s': %s", url, e.getMessage());
AffiliationException affiliationException = new AffiliationException(msg, e);
logger.error(msg);
throw affiliationException;
}
}
Aggregations