use of com.arm.mbed.cloud.sdk.devicedirectory.model.Query in project mbed-cloud-sdk-java by ARMmbed.
the class DeviceDirectoryExamples method manageQueries.
/**
* Creates, updates and deletes a query.
*/
@SuppressWarnings("boxing")
@Example
public void manageQueries() {
ConnectionOptions config = Configuration.get();
DeviceDirectory api = new DeviceDirectory(config);
String queryId = null;
try {
// Creating a query.
String queryName = "test-" + UUID.randomUUID().toString();
log("Query name", queryName);
Query myQuery = new Query(queryName, null);
myQuery.addCreatedAtFilter(new Date(), FilterOperator.LESS_THAN);
// Adding the query.
myQuery = api.addQuery(myQuery);
log("Created query", myQuery);
queryId = myQuery.getId();
// Updating the query.
queryName = "test-" + UUID.randomUUID().toString();
log("Updated Query name", queryName);
myQuery.setName(queryName);
myQuery = api.updateQuery(myQuery);
log("Updated query", myQuery);
queryId = myQuery.getId();
// Fetching the query.
myQuery = api.getQuery(queryId);
log("Retrieved query", myQuery);
// Finding the first 5 devices corresponding to the query.
DeviceListOptions options = new DeviceListOptions();
options.setFilters(myQuery.fetchFilters());
options.setLimit(5);
ListResponse<Device> matchingDevices = api.listDevices(options);
for (Device device : matchingDevices.getData()) {
log("Matching device", device);
}
// Deleting the query.
deleteCreatedQuery(queryId, api);
} catch (Exception e) {
logError("last API Metadata", api.getLastApiMetadata());
deleteCreatedQuery(queryId, api);
fail(e.getMessage());
}
}
Aggregations