Search in sources :

Example 1 with API

use of com.arm.mbed.cloud.sdk.annotations.API 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 API

use of com.arm.mbed.cloud.sdk.annotations.API 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 API

use of com.arm.mbed.cloud.sdk.annotations.API in project mbed-cloud-sdk-java by ARMmbed.

the class Certificates method listCertificates.

/**
 * Lists all certificates according to filter options.
 * <p>
 * Note: This method returns only partially complete certificate objects.
 * <p>
 * In order to see the full information about a particular certificate, use {@link #getCertificate(String)} instead.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     CertificateListOptions options = new CertificateListOptions();
 *     String ownerId = "015f4ac587f500000000000100100249";
 *     options.setOwnerIdFilter(ownerId);
 *     options.setTypeFilter(CertificateType.DEVELOPER);
 *
 *     ListResponse<Certificate> certificates = certificateApi.listCertificates(options);
 *     for (Certificate certificate : certificates) {
 *         System.out.println("Certificate name: " + certificate.getName());
 *         System.out.println("Certificate server URI: " + certificate.getServerUri());
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param options
 *            filter options.
 * @return The list of certificates corresponding to filter options (One page).
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public ListResponse<Certificate> listCertificates(@Nullable CertificateListOptions options) throws MbedCloudException {
    final CertificateListOptions finalOptions = (options == null) ? new CertificateListOptions() : options;
    final String serviceEq = finalOptions.getTypeFilter() == CertificateType.DEVELOPER ? CertificateType.BOOTSTRAP.toString() : finalOptions.encodeSingleEqualFilter(CertificateListOptions.TYPE_FILTER);
    return CloudCaller.call(this, "listCertificates()", CertificateAdapter.getListMapper(), new CloudCall<TrustedCertificateRespList>() {

        @Override
        public Call<TrustedCertificateRespList> call() {
            return endpoint.getAccountDeveloper().getAllCertificates(finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString(), finalOptions.encodeInclude(), finalOptions.encodeSingleEqualFilter(CertificateListOptions.NAME_FILTER), serviceEq, TranslationUtils.convertToInteger(finalOptions.encodeSingleEqualFilter(CertificateListOptions.EXPIRES_FILTER), null), finalOptions.getExecutionModeFilter(), finalOptions.getExecutionModeNotEqualFilter(), finalOptions.encodeSingleEqualFilter(CertificateListOptions.OWNER_ID_FILTER), finalOptions.getEnrollmentFilter(), finalOptions.encodeSingleLikeFilter(CertificateListOptions.ISSUER_FILTER), finalOptions.encodeSingleLikeFilter(CertificateListOptions.SUBJECT_FILTER));
        }
    });
}
Also used : CertificateListOptions(com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) TrustedCertificateRespList(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 4 with API

use of com.arm.mbed.cloud.sdk.annotations.API 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 5 with API

use of com.arm.mbed.cloud.sdk.annotations.API in project mbed-cloud-sdk-java by ARMmbed.

the class DeviceDirectory method addDevice.

/**
 * Adds a device.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Device device = new Device();
 *     device.setId("015f4ac587f500000000000100100249");
 *     device.setName("QuickstartDevice");
 *     device.setDescription("Quick start device");
 *     device.setDeviceType("quickstart");
 *
 *     Device newDevice = deviceDirectoryApi.addDevice(device);
 *     System.out.println("New device state: " + newDevice.getState());
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param device
 *            Device details.
 * @return added device.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Device addDevice(@NonNull Device device) throws MbedCloudException {
    checkNotNull(device, TAG_DEVICE);
    checkModelValidity(device, TAG_DEVICE);
    final Device finalDevice = device;
    return CloudCaller.call(this, "addDevice()", DeviceAdapter.getMapper(), new CloudCall<DeviceData>() {

        @Override
        public Call<DeviceData> call() {
            return endpoint.getDirectory().deviceCreate(DeviceAdapter.reverseMapAdd(finalDevice));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) Device(com.arm.mbed.cloud.sdk.devicedirectory.model.Device) DeviceData(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData) 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)34 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)26 Call (retrofit2.Call)26 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)23 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)5 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)4 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)3 TrustedCertificateResp (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp)3 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)2 ApiKeyListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions)2 GroupListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions)2 User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)2 UserListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions)2 NonNull (com.arm.mbed.cloud.sdk.annotations.NonNull)2 MbedCloudException (com.arm.mbed.cloud.sdk.common.MbedCloudException)2 ListOptions (com.arm.mbed.cloud.sdk.common.listing.ListOptions)2 Webhook (com.arm.mbed.cloud.sdk.connect.model.Webhook)2 Query (com.arm.mbed.cloud.sdk.devicedirectory.model.Query)2 DeviceData (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData)2 DeviceQuery (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery)2