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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations