Search in sources :

Example 1 with Event

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;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Event(org.thingsboard.server.common.data.Event)

Example 2 with 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);
}
Also used : Event(org.thingsboard.server.common.data.Event) ComponentLifecycleEvent(org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent)

Example 3 with 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);
}
Also used : Event(org.thingsboard.server.common.data.Event)

Example 4 with 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());
}
Also used : Event(org.thingsboard.server.common.data.Event) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 5 with Event

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());
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) Event(org.thingsboard.server.common.data.Event) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Aggregations

Event (org.thingsboard.server.common.data.Event)20 Test (org.junit.Test)8 UUID (java.util.UUID)6 DeviceId (org.thingsboard.server.common.data.id.DeviceId)6 TenantId (org.thingsboard.server.common.data.id.TenantId)6 EventId (org.thingsboard.server.common.data.id.EventId)4 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)4 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)4 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)4 RuleId (org.thingsboard.server.common.data.id.RuleId)2 ComponentLifecycleEvent (org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)1 IOException (java.io.IOException)1 VelocityContext (org.apache.velocity.VelocityContext)1 EntityId (org.thingsboard.server.common.data.id.EntityId)1