Search in sources :

Example 1 with EventId

use of org.thingsboard.server.common.data.id.EventId in project thingsboard by thingsboard.

the class CassandraBaseEventDao method saveIfNotExists.

@Override
public Optional<Event> saveIfNotExists(Event event) {
    if (event.getTenantId() == null) {
        log.trace("Save system event with predefined id {}", systemTenantId);
        event.setTenantId(systemTenantId);
    }
    if (event.getId() == null) {
        event.setId(new EventId(UUIDs.timeBased()));
    }
    return save(new EventEntity(event), true);
}
Also used : EventEntity(org.thingsboard.server.dao.model.nosql.EventEntity) EventId(org.thingsboard.server.common.data.id.EventId)

Example 2 with EventId

use of org.thingsboard.server.common.data.id.EventId in project thingsboard by thingsboard.

the class CassandraBaseEventDao method save.

@Override
public Event save(Event event) {
    log.debug("Save event [{}] ", event);
    if (event.getTenantId() == null) {
        log.trace("Save system event with predefined id {}", systemTenantId);
        event.setTenantId(systemTenantId);
    }
    if (event.getId() == null) {
        event.setId(new EventId(UUIDs.timeBased()));
    }
    if (StringUtils.isEmpty(event.getUid())) {
        event.setUid(event.getId().toString());
    }
    return save(new EventEntity(event), false).orElse(null);
}
Also used : EventEntity(org.thingsboard.server.dao.model.nosql.EventEntity) EventId(org.thingsboard.server.common.data.id.EventId)

Example 3 with EventId

use of org.thingsboard.server.common.data.id.EventId in project thingsboard by thingsboard.

the class EventEntity method toData.

@Override
public Event toData() {
    Event event = new Event(new EventId(id));
    event.setCreatedTime(UUIDs.unixTimestamp(id));
    event.setTenantId(new TenantId(tenantId));
    event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId));
    event.setBody(body);
    event.setType(eventType);
    event.setUid(eventUid);
    return event;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Event(org.thingsboard.server.common.data.Event) EventId(org.thingsboard.server.common.data.id.EventId)

Example 4 with EventId

use of org.thingsboard.server.common.data.id.EventId in project thingsboard by thingsboard.

the class EventEntity method toData.

@Override
public Event toData() {
    Event event = new Event(new EventId(getId()));
    event.setCreatedTime(UUIDs.unixTimestamp(getId()));
    event.setTenantId(new TenantId(toUUID(tenantId)));
    event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, toUUID(entityId)));
    event.setBody(body);
    event.setType(eventType);
    event.setUid(eventUid);
    return event;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Event(org.thingsboard.server.common.data.Event) EventId(org.thingsboard.server.common.data.id.EventId)

Example 5 with EventId

use of org.thingsboard.server.common.data.id.EventId in project thingsboard by thingsboard.

the class BaseEventServiceTest method saveEventWithProvidedTime.

private Event saveEventWithProvidedTime(long time, EntityId entityId, TenantId tenantId) throws IOException {
    Event event = generateEvent(tenantId, entityId, DataConstants.STATS, null);
    event.setId(new EventId(UUIDs.startOf(time)));
    return eventService.save(event);
}
Also used : Event(org.thingsboard.server.common.data.Event) EventId(org.thingsboard.server.common.data.id.EventId)

Aggregations

EventId (org.thingsboard.server.common.data.id.EventId)6 Event (org.thingsboard.server.common.data.Event)4 TenantId (org.thingsboard.server.common.data.id.TenantId)3 EventEntity (org.thingsboard.server.dao.model.nosql.EventEntity)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 EntityId (org.thingsboard.server.common.data.id.EntityId)1