use of org.eclipse.kapua.service.device.registry.event.DeviceEvent in project kapua by eclipse.
the class DeviceEventDAO method create.
public static DeviceEvent create(EntityManager em, DeviceEventCreator deviceEventCreator) {
DeviceEvent deviceEvent = new DeviceEventImpl(deviceEventCreator.getScopeId());
deviceEvent.setDeviceId(deviceEventCreator.getDeviceId());
deviceEvent.setReceivedOn(deviceEventCreator.getReceivedOn());
deviceEvent.setSentOn(deviceEventCreator.getSentOn());
deviceEvent.setResource(deviceEventCreator.getResource());
deviceEvent.setAction(deviceEventCreator.getAction());
deviceEvent.setResponseCode(deviceEventCreator.getResponseCode());
deviceEvent.setEventMessage(deviceEventCreator.getEventMessage());
deviceEvent.setPosition(deviceEventCreator.getPosition());
return ServiceDAO.create(em, deviceEvent);
}
use of org.eclipse.kapua.service.device.registry.event.DeviceEvent in project kapua by eclipse.
the class DeviceEventServiceTest method shouldDeleteDeviceEvent.
@Test
@Ignore
public void shouldDeleteDeviceEvent() throws Exception {
doPriviledge(() -> {
// Given
DeviceEvent device = deviceEventService.create(deviceEventCreator);
// When
deviceEventService.delete(device.getScopeId(), device.getId());
// Then
DeviceEvent deviceEventFound = deviceEventService.find(scope, device.getId());
Assertions.assertThat(deviceEventFound).isNull();
return null;
});
}
use of org.eclipse.kapua.service.device.registry.event.DeviceEvent in project kapua by eclipse.
the class DeviceEventServiceImpl method create.
// Operations
@Override
public DeviceEvent create(DeviceEventCreator deviceEventCreator) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(deviceEventCreator, "deviceEventCreator");
ArgumentValidator.notNull(deviceEventCreator.getScopeId(), "deviceEventCreator.scopeId");
ArgumentValidator.notNull(deviceEventCreator.getDeviceId(), "deviceEventCreator.deviceId");
ArgumentValidator.notNull(deviceEventCreator.getReceivedOn(), "deviceEventCreator.receivedOn");
ArgumentValidator.notEmptyOrNull(deviceEventCreator.getResource(), "deviceEventCreator.eventType");
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(DeviceEventDomain.DEVICE_EVENT, Actions.write, deviceEventCreator.getScopeId()));
// Create the event
return entityManagerSession.onEntityManagerResult(entityManager -> {
entityManager.beginTransaction();
DeviceEvent deviceEvent = DeviceEventDAO.create(entityManager, deviceEventCreator);
entityManager.commit();
return DeviceEventDAO.find(entityManager, deviceEvent.getId());
});
}
use of org.eclipse.kapua.service.device.registry.event.DeviceEvent in project kapua by eclipse.
the class DeviceEventServiceImpl method find.
@Override
public DeviceEvent find(KapuaId scopeId, KapuaId entityId) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");
ArgumentValidator.notNull(entityId, "entityId");
//
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(DeviceEventDomain.DEVICE_EVENT, Actions.read, scopeId));
//
// Do find
DeviceEvent deviceEvent = null;
EntityManager em = DeviceEntityManagerFactory.getEntityManager();
try {
deviceEvent = DeviceEventDAO.find(em, entityId);
} catch (Exception e) {
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return deviceEvent;
}
use of org.eclipse.kapua.service.device.registry.event.DeviceEvent in project kapua by eclipse.
the class GwtDeviceServiceImpl method findDeviceEvents.
public PagingLoadResult<GwtDeviceEvent> findDeviceEvents(PagingLoadConfig loadConfig, GwtDevice gwtDevice, Date startDate, Date endDate) throws GwtKapuaException {
ArrayList<GwtDeviceEvent> gwtDeviceEvents = new ArrayList<GwtDeviceEvent>();
BasePagingLoadResult<GwtDeviceEvent> gwtResults = null;
KapuaLocator locator = KapuaLocator.getInstance();
DeviceEventService des = locator.getService(DeviceEventService.class);
DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
try {
// prepare the query
BasePagingLoadConfig bplc = (BasePagingLoadConfig) loadConfig;
DeviceEventQuery query = deviceEventFactory.newQuery(KapuaEid.parseShortId(gwtDevice.getScopeId()));
KapuaAndPredicate andPredicate = new AndPredicate();
andPredicate.and(new AttributePredicate<KapuaId>(DeviceEventPredicates.DEVICE_ID, KapuaEid.parseShortId(gwtDevice.getId())));
// .and(new AttributePredicate<Date>(DeviceEventPredicates.RECEIVED_ON, startDate, Operator.GREATER_THAN));
// .and(new AttributePredicate<Date>(DeviceEventPredicates.RECEIVED_ON, startDate, Operator.LESS_THAN));
query.setPredicate(andPredicate);
query.setSortCriteria(new FieldSortCriteria(DeviceEventPredicates.RECEIVED_ON, SortOrder.DESCENDING));
query.setOffset(bplc.getOffset());
query.setLimit(bplc.getLimit());
// query execute
KapuaListResult<DeviceEvent> deviceEvents = des.query(query);
// prepare results
for (DeviceEvent deviceEvent : deviceEvents.getItems()) {
gwtDeviceEvents.add(KapuaGwtConverter.convert(deviceEvent));
}
gwtResults = new BasePagingLoadResult<GwtDeviceEvent>(gwtDeviceEvents);
gwtResults.setOffset(loadConfig.getOffset());
gwtResults.setTotalLength((int) des.count(query));
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtResults;
}
Aggregations