Search in sources :

Example 1 with DeviceEvent

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);
}
Also used : DeviceEvent(org.eclipse.kapua.service.device.registry.event.DeviceEvent)

Example 2 with 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;
    });
}
Also used : DeviceEvent(org.eclipse.kapua.service.device.registry.event.DeviceEvent) Ignore(org.junit.Ignore) Test(org.junit.Test) KapuaTest(org.eclipse.kapua.test.KapuaTest)

Example 3 with DeviceEvent

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());
    });
}
Also used : DeviceEvent(org.eclipse.kapua.service.device.registry.event.DeviceEvent)

Example 4 with DeviceEvent

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;
}
Also used : DeviceEvent(org.eclipse.kapua.service.device.registry.event.DeviceEvent) EntityManager(org.eclipse.kapua.commons.jpa.EntityManager) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaException(org.eclipse.kapua.KapuaException)

Example 5 with 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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtDeviceEvent(org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent) DeviceEvent(org.eclipse.kapua.service.device.registry.event.DeviceEvent) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig) ArrayList(java.util.ArrayList) KapuaAndPredicate(org.eclipse.kapua.model.query.predicate.KapuaAndPredicate) AndPredicate(org.eclipse.kapua.commons.model.query.predicate.AndPredicate) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceEventQuery(org.eclipse.kapua.service.device.registry.event.DeviceEventQuery) GwtDeviceEvent(org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent) FieldSortCriteria(org.eclipse.kapua.commons.model.query.FieldSortCriteria) KapuaAndPredicate(org.eclipse.kapua.model.query.predicate.KapuaAndPredicate) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Aggregations

DeviceEvent (org.eclipse.kapua.service.device.registry.event.DeviceEvent)8 KapuaTest (org.eclipse.kapua.test.KapuaTest)3 Test (org.junit.Test)3 BasePagingLoadConfig (com.extjs.gxt.ui.client.data.BasePagingLoadConfig)2 ArrayList (java.util.ArrayList)2 GwtDeviceEvent (org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent)2 FieldSortCriteria (org.eclipse.kapua.commons.model.query.FieldSortCriteria)2 AndPredicate (org.eclipse.kapua.commons.model.query.predicate.AndPredicate)2 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)2 KapuaId (org.eclipse.kapua.model.id.KapuaId)2 KapuaAndPredicate (org.eclipse.kapua.model.query.predicate.KapuaAndPredicate)2 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)2 DeviceEventQuery (org.eclipse.kapua.service.device.registry.event.DeviceEventQuery)2 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)2 Ignore (org.junit.Ignore)2 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)1 KapuaException (org.eclipse.kapua.KapuaException)1 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)1 EntityManager (org.eclipse.kapua.commons.jpa.EntityManager)1 SortOrder (org.eclipse.kapua.commons.model.query.FieldSortCriteria.SortOrder)1