Search in sources :

Example 6 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.

the class DeviceDirectory method listDevicesWithExtraFilters.

protected ListResponse<Device> listDevicesWithExtraFilters(String functionName, DeviceListOptions options, Filter additionalFilter) throws MbedCloudException {
    final DeviceListOptions finalOptions = (options == null) ? new DeviceListOptions() : options;
    finalOptions.addFilter(additionalFilter);
    return CloudCaller.call(this, functionName, DeviceAdapter.getListMapper(), new CloudCall<DevicePage>() {

        @Override
        public Call<DevicePage> call() {
            return endpoint.getDirectory().deviceList(finalOptions.getLimit(), finalOptions.getOrder().toString(), finalOptions.getAfter(), DeviceAdapter.FILTERS_MARSHALLER.encode(finalOptions.getFilter()), finalOptions.encodeInclude());
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) DevicePage(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DevicePage) DeviceListOptions(com.arm.mbed.cloud.sdk.devicedirectory.model.DeviceListOptions)

Example 7 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall 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 8 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall 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 9 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall 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 10 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall 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)

Aggregations

CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)29 Call (retrofit2.Call)29 API (com.arm.mbed.cloud.sdk.annotations.API)26 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)19 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)3 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)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 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)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 ApiKeyInfoResp (com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoResp)2