Search in sources :

Example 26 with EntityId

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

the class BaseAlarmService method updateRelations.

private void updateRelations(Alarm alarm, AlarmStatus oldStatus, AlarmStatus newStatus) {
    try {
        List<EntityRelation> relations = relationService.findByToAsync(alarm.getId(), RelationTypeGroup.ALARM).get();
        Set<EntityId> parents = relations.stream().map(EntityRelation::getFrom).collect(Collectors.toSet());
        for (EntityId parentId : parents) {
            updateAlarmRelation(parentId, alarm.getId(), oldStatus, newStatus);
        }
    } catch (ExecutionException | InterruptedException e) {
        log.warn("[{}] Failed to update relations. Old status: [{}], New status: [{}]", alarm.getId(), oldStatus, newStatus);
        throw new RuntimeException(e);
    }
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) ExecutionException(java.util.concurrent.ExecutionException)

Example 27 with EntityId

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

the class JpaBaseEventDaoTest method getEvent.

private Event getEvent(UUID eventId, UUID tenantId, UUID entityId) {
    Event event = new Event();
    event.setId(new EventId(eventId));
    event.setTenantId(new TenantId(tenantId));
    EntityId deviceId = new DeviceId(entityId);
    event.setEntityId(deviceId);
    event.setUid(event.getId().getId().toString());
    event.setType(STATS);
    ObjectMapper mapper = new ObjectMapper();
    try {
        JsonNode jsonNode = mapper.readTree("{\"key\":\"value\"}");
        event.setBody(jsonNode);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }
    return event;
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Event(org.thingsboard.server.common.data.Event) EventId(org.thingsboard.server.common.data.id.EventId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

EntityId (org.thingsboard.server.common.data.id.EntityId)27 Slf4j (lombok.extern.slf4j.Slf4j)12 StringUtils (org.springframework.util.StringUtils)10 java.util (java.util)9 Function (com.google.common.base.Function)8 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)8 Futures (com.google.common.util.concurrent.Futures)8 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 RelationTypeGroup (org.thingsboard.server.common.data.relation.RelationTypeGroup)8 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)7 IOException (java.io.IOException)6 Collectors (java.util.stream.Collectors)6 Service (org.springframework.stereotype.Service)6 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)6 PluginContext (org.thingsboard.server.extensions.api.plugins.PluginContext)6 Nullable (javax.annotation.Nullable)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 ExecutionException (java.util.concurrent.ExecutionException)4