use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class AbstractServiceTest method generateEvent.
protected Event generateEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) throws IOException {
if (tenantId == null) {
tenantId = new TenantId(UUIDs.timeBased());
}
Event event = new Event();
event.setTenantId(tenantId);
event.setEntityId(entityId);
event.setType(eventType);
event.setUid(eventUid);
event.setBody(readFromResource("TestJsonData.json"));
return event;
}
use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class ActorSystemContext method persistError.
public void persistError(TenantId tenantId, EntityId entityId, String method, Exception e) {
Event event = new Event();
event.setTenantId(tenantId);
event.setEntityId(entityId);
event.setType(DataConstants.ERROR);
event.setBody(toBodyJson(discoveryService.getCurrentServer().getServerAddress(), method, toString(e)));
persistEvent(event);
}
use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class StatsActor method onStatsPersistMsg.
public void onStatsPersistMsg(StatsPersistMsg msg) throws Exception {
Event event = new Event();
event.setEntityId(msg.getEntityId());
event.setTenantId(msg.getTenantId());
event.setType(DataConstants.STATS);
event.setBody(toBodyJson(systemContext.getDiscoveryService().getCurrentServer().getServerAddress(), msg.getMessagesProcessed(), msg.getErrorsOccurred()));
systemContext.getEventService().save(event);
}
use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class JpaBaseEventDaoTest method testSaveIfNotExists.
@Test
public void testSaveIfNotExists() {
UUID eventId = UUIDs.timeBased();
UUID tenantId = UUIDs.timeBased();
UUID entityId = UUIDs.timeBased();
Event event = getEvent(eventId, tenantId, entityId);
Optional<Event> optEvent1 = eventDao.saveIfNotExists(event);
assertTrue("Optional is expected to be non-empty", optEvent1.isPresent());
assertEquals(event, optEvent1.get());
Optional<Event> optEvent2 = eventDao.saveIfNotExists(event);
assertFalse("Optional is expected to be empty", optEvent2.isPresent());
}
use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class BaseEventServiceTest method saveEvent.
@Test
public void saveEvent() throws Exception {
DeviceId devId = new DeviceId(UUIDs.timeBased());
Event event = generateEvent(null, devId, "ALARM", UUIDs.timeBased().toString());
Event saved = eventService.save(event);
Optional<Event> loaded = eventService.findEvent(event.getTenantId(), event.getEntityId(), event.getType(), event.getUid());
Assert.assertTrue(loaded.isPresent());
Assert.assertNotNull(loaded.get());
Assert.assertEquals(saved, loaded.get());
}
Aggregations