use of com.arm.mbed.cloud.sdk.devicedirectory.model.DeviceListOptions in project mbed-cloud-sdk-java by ARMmbed.
the class DeviceDirectoryExamples method listDevices.
/**
* Lists the last 5 devices.
*/
@SuppressWarnings("boxing")
@Example
public void listDevices() {
ConnectionOptions config = Configuration.get();
DeviceDirectory api = new DeviceDirectory(config);
try {
// Defining query options.
DeviceListOptions options = new DeviceListOptions();
options.setLimit(5);
options.setOrder(Order.DESC);
// Listing devices.
ListResponse<Device> devices = api.listDevices(options);
for (Device device : devices.getData()) {
log("Device", device);
}
} catch (Exception e) {
logError("last API Metadata", api.getLastApiMetadata());
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.devicedirectory.model.DeviceListOptions in project mbed-cloud-sdk-java by ARMmbed.
the class TestAllListOptions method testDeviceListOptionsClone.
@Test
public void testDeviceListOptionsClone() {
DeviceListOptions opt1 = new DeviceListOptions();
opt1.addEqualFilter("field1", Integer.valueOf(3));
opt1.includeTotalCount();
opt1.setLimit(Integer.valueOf(2));
DeviceListOptions opt2 = new DeviceListOptions();
assertNotEquals(opt2, opt1);
assertNotSame(opt2, opt1);
opt2 = opt1.clone();
assertEquals(opt2, opt1);
assertNotSame(opt2, opt1);
}
use of com.arm.mbed.cloud.sdk.devicedirectory.model.DeviceListOptions in project mbed-cloud-sdk-java by ARMmbed.
the class ConnectExamples method listConnectedDevice.
/**
* Finds all devices currently connected and created in November 2017.
*/
@Example
public void listConnectedDevice() {
ConnectionOptions config = Configuration.get();
Connect api = new Connect(config);
try {
DeviceListOptions options = new DeviceListOptions();
options.addCreatedAtFilter(new GregorianCalendar(2017, 10, 1).getTime(), FilterOperator.GREATER_THAN);
options.addCreatedAtFilter(new GregorianCalendar(2017, 10, 30).getTime(), FilterOperator.LESS_THAN);
Paginator<Device> devices = api.listAllConnectedDevices(options);
for (Device device : devices) {
log("Connected device created in November 2017", device);
}
} catch (Exception e) {
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.devicedirectory.model.DeviceListOptions in project mbed-cloud-sdk-java by ARMmbed.
the class ConnectExamples method getResourceValue.
/**
* Gets a resource value.
*/
@SuppressWarnings("boxing")
@Example
public void getResourceValue() {
ConnectionOptions config = Configuration.get();
Connect api = new Connect(config);
// resource path to get value from
String resourcePath = "/5001/0/1";
try {
// Getting a connected device.
DeviceListOptions options = new DeviceListOptions();
options.setLimit(1);
Paginator<Device> deviceIterator = api.listAllConnectedDevices(options);
if (!deviceIterator.hasNext()) {
fail("No endpoints registered. Aborting.");
}
Device device = deviceIterator.first();
log("Device", device);
Resource resourceToConsider = api.getResource(device, resourcePath);
if (resourceToConsider == null) {
fail("The resource of interest does not exist on this device");
}
log("Resource of interest", resourceToConsider);
// Getting resource value
Object value = api.getResourceValue(resourceToConsider, new TimePeriod(10));
log("Resource value", value);
// Stopping potential daemons running
api.stopNotifications();
api.shutdownConnectService();
} catch (Exception e) {
e.printStackTrace();
logError("last API Metadata", api.getLastApiMetadata());
try {
api.stopNotifications();
} catch (MbedCloudException e1) {
e1.printStackTrace();
}
api.shutdownConnectService();
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.devicedirectory.model.DeviceListOptions 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