Search in sources :

Example 1 with TrustedCertificateResp

use of com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp 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)

Example 2 with TrustedCertificateResp

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

the class Certificates method addCertificate.

/**
 * Adds a new certificate.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Certificate certificate = new Certificate();
 *     certificate.setName("Test Cert");
 *     certificate.setType(CertificateType.BOOTSTRAP);
 *     certificate.setSignature("wqEhG6BzgHWAyFXXXX....XXX");
 *     certificate.setCertificateData("rFEr1cRvLS1MmA....XXX");
 *
 *     Certificate newCertificate = certificateApi.addCertificate(certificate);
 *     System.out.println("Certificate ID: " + certificates.getId());
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param certificate
 *            Certificate request.
 * @return added certificate.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Certificate addCertificate(@NonNull Certificate certificate) throws MbedCloudException {
    checkNotNull(certificate, TAG_CERTIFICATE);
    checkModelValidity(certificate, TAG_CERTIFICATE);
    final Certificate finalCertificate = certificate;
    return performCertificateAction("addCertificate()", new CloudCall<TrustedCertificateResp>() {

        @Override
        public Call<TrustedCertificateResp> call() {
            return endpoint.getAdmin().addCertificate(CertificateAdapter.reverseMapAdd(finalCertificate));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) TrustedCertificateResp(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp) 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)

Example 3 with TrustedCertificateResp

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

the class Certificates method updateCertificate.

/**
 * Updates a certificate.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Certificate certificate = new Certificate();
 *     String certificateId = "015f4ac587f500000000000100100249";
 *     certificate.setId(certificateId);
 *     certificate.setName("Changed Cert name");
 *     certificate.setType(CertificateType.DEVELOPER);
 *
 *     Certificate newCertificate = certificateApi.updateCertificate(certificate);
 *     System.out.println("New cert name: " + newCertificate.getName());
 *     assert certificateId == newCertificate.getId();
 *
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param certificate
 *            certificate to update.
 * @return updated certificate.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Certificate updateCertificate(@NonNull Certificate certificate) throws MbedCloudException {
    checkNotNull(certificate, TAG_CERTIFICATE);
    checkNotNull(certificate.getId(), TAG_CERTIFICATE_ID);
    checkModelValidity(certificate, TAG_CERTIFICATE);
    final Certificate finalCertificate = certificate;
    return performCertificateAction("updateCertificate()", new CloudCall<TrustedCertificateResp>() {

        @Override
        public Call<TrustedCertificateResp> call() {
            return endpoint.getAccountDeveloper().updateCertificate(finalCertificate.getId(), CertificateAdapter.reverseMapUpdate(finalCertificate));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) TrustedCertificateResp(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp) 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)

Example 4 with TrustedCertificateResp

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

the class CertificateAdapter method mapList.

/**
 * Maps list of certificates.
 *
 * @param list
 *            certificate list to map.
 * @return a list of mapped certificates.
 */
public static ListResponse<Certificate> mapList(TrustedCertificateRespList list) {
    final TrustedCertificateRespList certificateList = list;
    final RespList<TrustedCertificateResp> respList = new RespList<TrustedCertificateResp>() {

        @Override
        public Boolean getHasMore() {
            return (certificateList == null) ? null : certificateList.isHasMore();
        }

        @Override
        public Integer getTotalCount() {
            return (certificateList == null) ? null : certificateList.getTotalCount();
        }

        @Override
        public String getAfter() {
            return (certificateList == null) ? null : certificateList.getAfter();
        }

        @Override
        public Integer getLimit() {
            return (certificateList == null) ? null : certificateList.getLimit();
        }

        @Override
        public String getOrder() {
            return (certificateList == null) ? null : certificateList.getOrder().toString();
        }

        @Override
        public List<TrustedCertificateResp> getData() {
            return (certificateList == null) ? null : certificateList.getData();
        }
    };
    return GenericAdapter.mapList(respList, getMapper());
}
Also used : TrustedCertificateRespList(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList) TrustedCertificateResp(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp) TrustedCertificateRespList(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList) RespList(com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)

Aggregations

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