use of com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery 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.internal.devicedirectory.model.DeviceQuery 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.internal.devicedirectory.model.DeviceQuery in project mbed-cloud-sdk-java by ARMmbed.
the class QueryAdapter method map.
/**
* Maps query.
*
* @param deviceQuery
* query to map
* @return a map
*/
public static Query map(DeviceQuery deviceQuery) {
if (deviceQuery == null) {
return null;
}
final Query query = new Query(deviceQuery.getId(), TranslationUtils.toDate(deviceQuery.getCreatedAt()), TranslationUtils.toDate(deviceQuery.getUpdatedAt()));
query.setName(deviceQuery.getName());
query.setFilters(decodeFilters(deviceQuery.getQuery()));
return query;
}
use of com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery in project mbed-cloud-sdk-java by ARMmbed.
the class QueryAdapter method mapList.
/**
* Maps a list of query.
*
* @param list
* query page.
* @return a list of queries
*/
public static ListResponse<Query> mapList(DeviceQueryPage list) {
final DeviceQueryPage queryList = list;
final RespList<DeviceQuery> respList = new RespList<DeviceQuery>() {
@Override
public Boolean getHasMore() {
return (queryList == null) ? null : queryList.isHasMore();
}
@Override
public Integer getTotalCount() {
return (queryList == null) ? null : queryList.getTotalCount();
}
@Override
public String getAfter() {
return (queryList == null) ? null : queryList.getAfter();
}
@Override
public Integer getLimit() {
return (queryList == null) ? null : queryList.getLimit();
}
@Override
public String getOrder() {
return (queryList == null) ? null : queryList.getOrder().toString();
}
@Override
public List<DeviceQuery> getData() {
return (queryList == null) ? null : queryList.getData();
}
};
return GenericAdapter.mapList(respList, getMapper());
}
Aggregations