Search in sources :

Example 1 with DeveloperCertificateResponseData

use of com.arm.mbed.cloud.sdk.internal.connectorca.model.DeveloperCertificateResponseData in project mbed-cloud-sdk-java by ARMmbed.

the class Certificates method addDeveloperCertificate.

/**
 * Adds a new developer certificate.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     final Certificate certificate = new Certificate();
 *     certificate.setName("Test Cert");
 *     certificate.setType(CertificateType.DEVELOPER);
 *     certificate.setSignature("wqEhG6BzgHWAyFXXXX....XXX");
 *     certificate.setCertificateData("rFEr1cRvLS1MmA....XXX");
 *
 *     Certificate newCertificate = certificateApi.addDeveloperCertificate(certificate);
 *     System.out.println("Certificate ID: " + certificates.getId());
 *     assert newCertificate == certificate;
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param certificate
 *            certificate Certificate request.
 * @return added certificate.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Certificate addDeveloperCertificate(@NonNull Certificate certificate) throws MbedCloudException {
    checkNotNull(certificate, TAG_CERTIFICATE);
    // To run this method, the certificate must be a developer certificate.
    certificate.setType(CertificateType.DEVELOPER);
    checkModelValidity(certificate, TAG_CERTIFICATE);
    final Certificate finalCertificate = certificate;
    final Certificate addedPartialCertificate1 = CloudCaller.call(this, "addDeveloperCertificate()", CertificateAdapter.getDeveloperMapper(), new CloudCall<DeveloperCertificateResponseData>() {

        @Override
        public Call<DeveloperCertificateResponseData> call() {
            return endpoint.getCertDeveloper().createDeveloperCertificate(null, CertificateAdapter.reverseDeveloperMap(finalCertificate));
        }
    });
    if (addedPartialCertificate1 == null) {
        return null;
    }
    final Certificate addedPartialCertificate2 = performCertificateAction("addDeveloperCertificate()", new CloudCall<TrustedCertificateResp>() {

        @Override
        public Call<TrustedCertificateResp> call() {
            return endpoint.getAccountDeveloper().getCertificate(addedPartialCertificate1.getId());
        }
    });
    return Certificate.merge(addedPartialCertificate1, addedPartialCertificate2);
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) TrustedCertificateResp(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp) DeveloperCertificateResponseData(com.arm.mbed.cloud.sdk.internal.connectorca.model.DeveloperCertificateResponseData) Certificate(com.arm.mbed.cloud.sdk.certificates.model.Certificate) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Aggregations

API (com.arm.mbed.cloud.sdk.annotations.API)1 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)1 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)1 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)1 DeveloperCertificateResponseData (com.arm.mbed.cloud.sdk.internal.connectorca.model.DeveloperCertificateResponseData)1 TrustedCertificateResp (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp)1 Call (retrofit2.Call)1