Search in sources :

Example 1 with AffiliationException

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;
    }
}
Also used : AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException)

Example 2 with 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;
    }
}
Also used : AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) JsonObject(javax.json.JsonObject) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException)

Example 3 with 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;
    }
}
Also used : AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException)

Example 4 with 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;
    }
}
Also used : AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException)

Example 5 with 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;
    }
}
Also used : AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) JsonObject(javax.json.JsonObject) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) URISyntaxException(java.net.URISyntaxException) RegistrationException(org.hyperledger.fabric_ca.sdk.exception.RegistrationException) KeyStoreException(java.security.KeyStoreException) AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException) GenerateCRLException(org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException) KeyManagementException(java.security.KeyManagementException) IdentityException(org.hyperledger.fabric_ca.sdk.exception.IdentityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EnrollmentException(org.hyperledger.fabric_ca.sdk.exception.EnrollmentException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) RevocationException(org.hyperledger.fabric_ca.sdk.exception.RevocationException) ParseException(org.apache.http.ParseException) MalformedURLException(java.net.MalformedURLException) InfoException(org.hyperledger.fabric_ca.sdk.exception.InfoException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException)

Aggregations

JsonObject (javax.json.JsonObject)5 AffiliationException (org.hyperledger.fabric_ca.sdk.exception.AffiliationException)5 HTTPException (org.hyperledger.fabric_ca.sdk.exception.HTTPException)5 InvalidArgumentException (org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException)5 HashMap (java.util.HashMap)3 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 ParseException (org.apache.http.ParseException)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 EnrollmentException (org.hyperledger.fabric_ca.sdk.exception.EnrollmentException)1 GenerateCRLException (org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException)1 IdentityException (org.hyperledger.fabric_ca.sdk.exception.IdentityException)1 InfoException (org.hyperledger.fabric_ca.sdk.exception.InfoException)1 RegistrationException (org.hyperledger.fabric_ca.sdk.exception.RegistrationException)1