use of org.eclipse.kapua.service.device.registry.event.DeviceEventListResult in project kapua by eclipse.
the class DeviceEventServiceImpl method query.
@Override
public DeviceEventListResult query(KapuaQuery<DeviceEvent> query) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(query, "query");
ArgumentValidator.notNull(query.getScopeId(), "query.scopeId");
//
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(DeviceEventDomain.DEVICE_EVENT, Actions.read, query.getScopeId()));
//
// Do Query
DeviceEventListResult result = null;
EntityManager em = DeviceEntityManagerFactory.getEntityManager();
try {
result = DeviceEventDAO.query(em, query);
} catch (Exception e) {
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return result;
}
use of org.eclipse.kapua.service.device.registry.event.DeviceEventListResult in project kapua by eclipse.
the class Devices method getEvents.
/**
* Returns the events for the device identified by the specified
* ClientID under the account of the currently connected user.
* <p>
* If the flag DeviceEventsResult.limitExceeded is set, the maximum number
* of entries to be returned has been reached, more events exist and can
* be read by moving the offset forward in a new request
*
* @param deviceId
* The client ID of the device requested.
* @param limit
* Maximum number of entries to be returned.
* @param offset
* Starting offset for the entries to be returned.
* @param startDate
* Start date of the date range requested. The parameter
* is expressed as a long counting the number of milliseconds since
* January 1, 1970, 00:00:00 GMT. The default value of 0 means no
* start date. Alternatively, the date can be expressed as a string
* following the ISO 8601 format.
* @param endDate
* End date of the date range requested. The parameter
* is expressed as a long counting the number of milliseconds since
* January 1, 1970, 00:00:00 GMT. The default value of 0 means no
* start date. Alternatively, the date can be expressed as a string
* following the ISO 8601 format.
* @return The list of Events
*/
@GET
@Path("{deviceId}/events")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public DeviceEventListResult getEvents(@PathParam("deviceId") String deviceId, @QueryParam("limit") @DefaultValue("50") int limit, @QueryParam("offset") int offset, @QueryParam("startDate") String startDate, @QueryParam("endDate") String endDate) {
DeviceEventListResult deviceEvents = eventFactory.newDeviceListResult();
try {
KapuaId scopeId = KapuaSecurityUtils.getSession().getScopeId();
KapuaId id = KapuaEid.parseShortId(deviceId);
DeviceEventQuery query = eventFactory.newQuery(scopeId);
KapuaAndPredicate andPredicate = new AndPredicate();
andPredicate.and(new AttributePredicate<>(DeviceEventPredicates.DEVICE_ID, id));
// TODO Date filter not working?
if (startDate != null) {
DateTime parsedStartDate = DateTime.parse(startDate);
andPredicate = andPredicate.and(new AttributePredicate<>(DeviceEventPredicates.RECEIVED_ON, parsedStartDate.toDate(), KapuaAttributePredicate.Operator.GREATER_THAN));
}
if (endDate != null) {
DateTime parsedEndDate = DateTime.parse(endDate);
andPredicate = andPredicate.and(new AttributePredicate<>(DeviceEventPredicates.RECEIVED_ON, parsedEndDate.toDate(), KapuaAttributePredicate.Operator.LESS_THAN));
}
query.setPredicate(andPredicate);
query.setSortCriteria(new FieldSortCriteria(DeviceEventPredicates.RECEIVED_ON, FieldSortCriteria.SortOrder.DESCENDING));
query.setOffset(offset);
query.setLimit(limit);
// query execute
deviceEvents = (DeviceEventListResult) eventService.query(query);
} catch (Throwable t) {
handleException(t);
}
return returnNotNullEntity(deviceEvents);
}
Aggregations