Search in sources :

Example 1 with HasCustomerId

use of org.thingsboard.server.common.data.HasCustomerId 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)

Aggregations

HasCustomerId (org.thingsboard.server.common.data.HasCustomerId)1 AlarmId (org.thingsboard.server.common.data.id.AlarmId)1 AssetId (org.thingsboard.server.common.data.id.AssetId)1 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 EdgeId (org.thingsboard.server.common.data.id.EdgeId)1 EntityViewId (org.thingsboard.server.common.data.id.EntityViewId)1 UserId (org.thingsboard.server.common.data.id.UserId)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1