Search in sources :

Example 16 with EntityViewId

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

the class BaseEntityService method fetchEntityCustomerId.

@Override
public CustomerId fetchEntityCustomerId(TenantId tenantId, EntityId entityId) {
    log.trace("Executing fetchEntityCustomerId [{}]", entityId);
    HasCustomerId hasCustomerId = null;
    switch(entityId.getEntityType()) {
        case TENANT:
        case RULE_CHAIN:
        case RULE_NODE:
        case DASHBOARD:
        case WIDGETS_BUNDLE:
        case WIDGET_TYPE:
        case TENANT_PROFILE:
        case DEVICE_PROFILE:
        case API_USAGE_STATE:
        case TB_RESOURCE:
        case OTA_PACKAGE:
            break;
        case CUSTOMER:
            hasCustomerId = () -> new CustomerId(entityId.getId());
            break;
        case USER:
            hasCustomerId = userService.findUserById(tenantId, new UserId(entityId.getId()));
            break;
        case ASSET:
            hasCustomerId = assetService.findAssetById(tenantId, new AssetId(entityId.getId()));
            break;
        case DEVICE:
            hasCustomerId = deviceService.findDeviceById(tenantId, new DeviceId(entityId.getId()));
            break;
        case ALARM:
            try {
                hasCustomerId = alarmService.findAlarmByIdAsync(tenantId, new AlarmId(entityId.getId())).get();
            } catch (Exception e) {
            }
            break;
        case ENTITY_VIEW:
            hasCustomerId = entityViewService.findEntityViewById(tenantId, new EntityViewId(entityId.getId()));
            break;
        case EDGE:
            hasCustomerId = edgeService.findEdgeById(tenantId, new EdgeId(entityId.getId()));
            break;
    }
    return hasCustomerId != null ? hasCustomerId.getCustomerId() : new CustomerId(NULL_UUID);
}
Also used : AlarmId(org.thingsboard.server.common.data.id.AlarmId) EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) UserId(org.thingsboard.server.common.data.id.UserId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) EdgeId(org.thingsboard.server.common.data.id.EdgeId) HasCustomerId(org.thingsboard.server.common.data.HasCustomerId) HasCustomerId(org.thingsboard.server.common.data.HasCustomerId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) AssetId(org.thingsboard.server.common.data.id.AssetId) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException)

Example 17 with EntityViewId

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

the class EntityViewServiceImpl method findEntityViewsByQuery.

@Override
public ListenableFuture<List<EntityView>> findEntityViewsByQuery(TenantId tenantId, EntityViewSearchQuery query) {
    ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(tenantId, query.toEntitySearchQuery());
    ListenableFuture<List<EntityView>> entityViews = Futures.transformAsync(relations, r -> {
        EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
        List<ListenableFuture<EntityView>> futures = new ArrayList<>();
        for (EntityRelation relation : r) {
            EntityId entityId = direction == EntitySearchDirection.FROM ? relation.getTo() : relation.getFrom();
            if (entityId.getEntityType() == EntityType.ENTITY_VIEW) {
                futures.add(findEntityViewByIdAsync(tenantId, new EntityViewId(entityId.getId())));
            }
        }
        return Futures.successfulAsList(futures);
    }, MoreExecutors.directExecutor());
    entityViews = Futures.transform(entityViews, new Function<List<EntityView>, List<EntityView>>() {

        @Nullable
        @Override
        public List<EntityView> apply(@Nullable List<EntityView> entityViewList) {
            return entityViewList == null ? Collections.emptyList() : entityViewList.stream().filter(entityView -> query.getEntityViewTypes().contains(entityView.getType())).collect(Collectors.toList());
        }
    }, MoreExecutors.directExecutor());
    return entityViews;
}
Also used : EntitySearchDirection(org.thingsboard.server.common.data.relation.EntitySearchDirection) EntityView(org.thingsboard.server.common.data.EntityView) ArrayList(java.util.ArrayList) EntityId(org.thingsboard.server.common.data.id.EntityId) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) Function(com.google.common.base.Function) EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(javax.annotation.Nullable)

Example 18 with EntityViewId

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

the class AbstractEntityViewEntity method toEntityView.

protected EntityView toEntityView() {
    EntityView entityView = new EntityView(new EntityViewId(getUuid()));
    entityView.setCreatedTime(createdTime);
    if (entityId != null) {
        entityView.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType.name(), entityId));
    }
    if (tenantId != null) {
        entityView.setTenantId(TenantId.fromUUID(tenantId));
    }
    if (customerId != null) {
        entityView.setCustomerId(new CustomerId(customerId));
    }
    entityView.setType(type);
    entityView.setName(name);
    try {
        entityView.setKeys(mapper.readValue(keys, TelemetryEntityView.class));
    } catch (IOException e) {
        log.error("Unable to read entity view keys!", e);
    }
    entityView.setStartTimeMs(startTs);
    entityView.setEndTimeMs(endTs);
    entityView.setAdditionalInfo(additionalInfo);
    return entityView;
}
Also used : EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) IOException(java.io.IOException)

Example 19 with EntityViewId

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

the class BaseTimeseriesService method findAll.

@Override
public ListenableFuture<List<TsKvEntry>> findAll(TenantId tenantId, EntityId entityId, List<ReadTsKvQuery> queries) {
    validate(entityId);
    queries.forEach(this::validate);
    if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) {
        EntityView entityView = entityViewService.findEntityViewById(tenantId, (EntityViewId) entityId);
        List<String> keys = entityView.getKeys() != null && entityView.getKeys().getTimeseries() != null ? entityView.getKeys().getTimeseries() : Collections.emptyList();
        List<ReadTsKvQuery> filteredQueries = queries.stream().filter(query -> keys.isEmpty() || keys.contains(query.getKey())).collect(Collectors.toList());
        return timeseriesDao.findAllAsync(tenantId, entityView.getEntityId(), updateQueriesForEntityView(entityView, filteredQueries));
    }
    return timeseriesDao.findAllAsync(tenantId, entityId, queries);
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BaseDeleteTsKvQuery(org.thingsboard.server.common.data.kv.BaseDeleteTsKvQuery) Autowired(org.springframework.beans.factory.annotation.Autowired) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) TenantId(org.thingsboard.server.common.data.id.TenantId) Value(org.springframework.beans.factory.annotation.Value) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) EntityId(org.thingsboard.server.common.data.id.EntityId) EntityType(org.thingsboard.server.common.data.EntityType) TsKvLatestRemovingResult(org.thingsboard.server.common.data.kv.TsKvLatestRemovingResult) EntityViewService(org.thingsboard.server.dao.entityview.EntityViewService) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) Function(com.google.common.base.Function) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) Collection(java.util.Collection) Validator(org.thingsboard.server.dao.service.Validator) Collectors(java.util.stream.Collectors) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) EntityView(org.thingsboard.server.common.data.EntityView) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) Collections(java.util.Collections) EntityView(org.thingsboard.server.common.data.EntityView) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery)

Aggregations

EntityViewId (org.thingsboard.server.common.data.id.EntityViewId)19 EntityView (org.thingsboard.server.common.data.EntityView)14 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)11 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)10 ExecutionException (java.util.concurrent.ExecutionException)8 ApiOperation (io.swagger.annotations.ApiOperation)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 EdgeId (org.thingsboard.server.common.data.id.EdgeId)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Customer (org.thingsboard.server.common.data.Customer)5 Futures (com.google.common.util.concurrent.Futures)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Edge (org.thingsboard.server.common.data.edge.Edge)4 AssetId (org.thingsboard.server.common.data.id.AssetId)4 DeviceId (org.thingsboard.server.common.data.id.DeviceId)4