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());
}
});
}
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));
}
});
}
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));
}
});
}
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));
}
});
}
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());
}
});
}
Aggregations