Search in sources :

Example 6 with Nullable

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

the class DeviceDirectory method updateQuery.

/**
 * Updates a query.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Query query = new Query();
 *     query.setName("NEW Quickstart query");
 *     String queryId = "015f4ac587f500000000000100100249";
 *     query.setId(queryId);
 *
 *     Filters deviceFilter = new Filters();
 *     deviceFilter.add(new Filter("state", FilterOperator.EQUAL, "registered"));
 *     deviceFilter.add(new Filter("deviceClass", FilterOperator.EQUAL, getClassId()));
 *     query.setFilters(deviceFilter);
 *
 *     Calendar date = GregorianCalendar(2017,10,30,10,20,56);
 *     query.addCreatedAtFilter(date.getTime(),FilterOperator.GREATER_THAN);
 *
 *     Query newQuery = deviceDirectoryApi.updateQuery(query);
 *     System.out.println("Update query name: " + newQuery.getName());
 *     assert query.getId() == newQuery.getId();
 *
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param query
 *            The query to update.
 * @return updated query.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Query updateQuery(@NonNull Query query) throws MbedCloudException {
    checkNotNull(query, TAG_QUERY);
    checkNotNull(query.getId(), TAG_QUERY_ID);
    checkModelValidity(query, TAG_QUERY);
    final Query finalQuery = query;
    return CloudCaller.call(this, "updateQuery()", QueryAdapter.getMapper(), new CloudCall<DeviceQuery>() {

        @Override
        public Call<DeviceQuery> call() {
            return endpoint.getDirectory().deviceQueryUpdate(finalQuery.getId(), QueryAdapter.reverseMapUpdate(finalQuery));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) DeviceQuery(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery) Query(com.arm.mbed.cloud.sdk.devicedirectory.model.Query) DeviceQuery(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 7 with Nullable

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

the class DeviceDirectory method updateDevice.

/**
 * Updates a device.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Device device = new Device();
 *     String deviceId = "015f4ac587f500000000000100100249";
 *     device.setId(deviceId);
 *     device.setName("QuickstartDevice");
 *     device.setDescription("Updated quick start device");
 *     device.setDeviceType("quickstart");
 *
 *     Device newDevice = deviceDirectoryApi.updateDevice(device);
 *     System.out.println("Updated device description: " + newDevice.getDescription());
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param device
 *            Device details.
 * @return updated device.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Device updateDevice(@NonNull Device device) throws MbedCloudException {
    checkNotNull(device, TAG_DEVICE);
    checkNotNull(device.getId(), TAG_DEVICE_ID);
    checkModelValidity(device, TAG_DEVICE);
    final Device finalDevice = device;
    return CloudCaller.call(this, "updateDevice()", DeviceAdapter.getMapper(), new CloudCall<DeviceData>() {

        @Override
        public Call<DeviceData> call() {
            return endpoint.getDirectory().deviceUpdate(finalDevice.getId(), DeviceAdapter.reverseMapUpdate(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)

Example 8 with Nullable

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

the class DeviceDirectory method addQuery.

/**
 * Adds a query.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Query query = new Query();
 *     query.setName("Quickstart query");
 *
 *     Filters deviceFilter = new Filters();
 *     deviceFilter.add(new Filter("state", FilterOperator.EQUAL, "registered"));
 *     deviceFilter.add(new Filter("deviceClass", FilterOperator.EQUAL, getClassId()));
 *     query.setFilters(deviceFilter);
 *
 *     Calendar date = GregorianCalendar(2017,10,30,10,20,56);
 *     query.addCreatedAtFilter(date.getTime(),FilterOperator.GREATER_THAN);
 *
 *     Query newQuery = deviceDirectoryApi.addQuery(query);
 *     System.out.println("Query ID: " + newQuery.getId());
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param query
 *            the query to add.
 * @return added query.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Query addQuery(@NonNull Query query) throws MbedCloudException {
    checkNotNull(query, TAG_QUERY);
    checkModelValidity(query, TAG_QUERY);
    final Query finalQuery = query;
    return CloudCaller.call(this, "addQuery()", QueryAdapter.getMapper(), new CloudCall<DeviceQuery>() {

        @Override
        public Call<DeviceQuery> call() {
            return endpoint.getDirectory().deviceQueryCreate(QueryAdapter.reverseMapAdd(finalQuery));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) DeviceQuery(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery) Query(com.arm.mbed.cloud.sdk.devicedirectory.model.Query) DeviceQuery(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 9 with Nullable

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

the class Update method addFirmwareImage.

/**
 * Adds a firmware image.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String fileName = "C:\\Users\\mbedUser\\mbed-cloud-client-example.bin";
 *     FirmwareImage image = new FirmwareImage();
 *     image.setDatafile(fileName);
 *     image.setDescription("Quick start image");
 *     image.setName(fileName.substring(0,fileName.indexOf(".")));
 *
 *     FirmwareImage newImage = updateApi.addFirmwareImage(image);
 *     System.out.println("FirmwareImage URL: " + newImage.getUrl());
 *
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param image
 *            The image to add.
 * @return added image.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public FirmwareImage addFirmwareImage(@NonNull FirmwareImage image) throws MbedCloudException {
    checkNotNull(image, TAG_FIRMWARE_IMAGE);
    checkModelValidity(image, TAG_FIRMWARE_IMAGE);
    final FirmwareImage finalImage = image;
    return CloudCaller.call(this, "addFirmwareImage()", FirmwareImageAdapter.getMapper(), new CloudCall<com.arm.mbed.cloud.sdk.internal.updateservice.model.FirmwareImage>() {

        @Override
        public Call<com.arm.mbed.cloud.sdk.internal.updateservice.model.FirmwareImage> call() {
            return endpoint.getUpdate().firmwareImageCreate(DataFileAdapter.reverseMap(finalImage.getDataFile()), finalImage.getName(), finalImage.getDescription());
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) FirmwareImage(com.arm.mbed.cloud.sdk.update.model.FirmwareImage) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 10 with Nullable

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

the class AccountManagement method updateApiKey.

/**
 * Updates an API key.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     ApiKey apiKey = new ApiKey();
 *     String apiKeyId = "015f4ac587f500000000000100100249";
 *     apiKey.setId(apiKeyId);
 *     apiKey.setName("NewKeyName");
 *
 *     ApiKey newApiKey = accountManagementApi.updateApiKey(apiKey);
 *     System.out.println("New Api Key name: " + newApiKey.getName());
 *     assert apiKeyId == newApiKey.getId();
 *
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param apiKey
 *            The API key to update.
 * @return updated API key.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public ApiKey updateApiKey(@NonNull ApiKey apiKey) throws MbedCloudException {
    checkNotNull(apiKey, TAG_API_KEY);
    checkNotNull(apiKey.getId(), TAG_API_KEY_UUID);
    checkModelValidity(apiKey, TAG_API_KEY);
    ApiKey updatedApiKey = null;
    if (apiKey.hasStatusBeenUpdated()) {
        updatedApiKey = apiKey;
    } else {
        updatedApiKey = apiKey.clone();
        updatedApiKey.setStatus(null);
    }
    final ApiKey finalApiKey = updatedApiKey;
    return CloudCaller.call(this, "updateApiKey()", ApiKeyAdapter.getMapper(), new CloudCall<ApiKeyInfoResp>() {

        @Override
        public Call<ApiKeyInfoResp> call() {
            return endpoint.getDeveloper().updateApiKey(finalApiKey.getId(), ApiKeyAdapter.reverseMapUpdate(finalApiKey));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) ApiKey(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey) ApiKeyInfoResp(com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoResp) 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)23 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)23 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)19 Call (retrofit2.Call)19 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)3 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)3 TrustedCertificateResp (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp)3 ApiKeyListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions)2 GroupListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions)2 UserListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions)2 ListOptions (com.arm.mbed.cloud.sdk.common.listing.ListOptions)2 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)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 LinkedList (java.util.LinkedList)2 Account (com.arm.mbed.cloud.sdk.accountmanagement.model.Account)1 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)1 User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)1 CertificateListOptions (com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions)1