|
|
@ -16,9 +16,7 @@ |
|
|
package org.thingsboard.server.dao.entity; |
|
|
package org.thingsboard.server.dao.entity; |
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.data.util.Pair; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.thingsboard.server.common.data.HasCustomerId; |
|
|
import org.thingsboard.server.common.data.HasCustomerId; |
|
|
@ -26,6 +24,7 @@ import org.thingsboard.server.common.data.HasEmail; |
|
|
import org.thingsboard.server.common.data.HasLabel; |
|
|
import org.thingsboard.server.common.data.HasLabel; |
|
|
import org.thingsboard.server.common.data.HasName; |
|
|
import org.thingsboard.server.common.data.HasName; |
|
|
import org.thingsboard.server.common.data.HasTitle; |
|
|
import org.thingsboard.server.common.data.HasTitle; |
|
|
|
|
|
import org.thingsboard.server.common.data.id.NameLabelAndCustomerDetails; |
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
import org.thingsboard.server.common.data.id.HasId; |
|
|
import org.thingsboard.server.common.data.id.HasId; |
|
|
@ -98,6 +97,12 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe |
|
|
return fetchAndConvert(tenantId, entityId, this::getCustomerId); |
|
|
return fetchAndConvert(tenantId, entityId, this::getCustomerId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Optional<NameLabelAndCustomerDetails> fetchNameLabelAndCustomerDetails(TenantId tenantId, EntityId entityId) { |
|
|
|
|
|
log.trace("Executing fetchNameLabelAndCustomerDetails [{}]", entityId); |
|
|
|
|
|
return fetchAndConvert(tenantId, entityId, this::getNameLabelAndCustomerDetails); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private <T> Optional<T> fetchAndConvert(TenantId tenantId, EntityId entityId, Function<HasId<?>, T> converter) { |
|
|
private <T> Optional<T> fetchAndConvert(TenantId tenantId, EntityId entityId, Function<HasId<?>, T> converter) { |
|
|
EntityDaoService entityDaoService = entityServiceRegistry.getServiceByEntityType(entityId.getEntityType()); |
|
|
EntityDaoService entityDaoService = entityServiceRegistry.getServiceByEntityType(entityId.getEntityType()); |
|
|
Optional<HasId<?>> entityOpt = entityDaoService.findEntity(tenantId, entityId); |
|
|
Optional<HasId<?>> entityOpt = entityDaoService.findEntity(tenantId, entityId); |
|
|
@ -125,9 +130,9 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe |
|
|
return entityLabel; |
|
|
return entityLabel; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private CustomerId getCustomerId(HasId<?> hasId) { |
|
|
private CustomerId getCustomerId(HasId<?> entity) { |
|
|
if (hasId instanceof HasCustomerId) { |
|
|
if (entity instanceof HasCustomerId) { |
|
|
HasCustomerId hasCustomerId = (HasCustomerId) hasId; |
|
|
HasCustomerId hasCustomerId = (HasCustomerId) entity; |
|
|
CustomerId customerId = hasCustomerId.getCustomerId(); |
|
|
CustomerId customerId = hasCustomerId.getCustomerId(); |
|
|
if (customerId == null) { |
|
|
if (customerId == null) { |
|
|
customerId = NULL_CUSTOMER_ID; |
|
|
customerId = NULL_CUSTOMER_ID; |
|
|
@ -137,6 +142,10 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe |
|
|
return NULL_CUSTOMER_ID; |
|
|
return NULL_CUSTOMER_ID; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private NameLabelAndCustomerDetails getNameLabelAndCustomerDetails(HasId<?> entity) { |
|
|
|
|
|
return new NameLabelAndCustomerDetails(getName(entity), getLabel(entity), getCustomerId(entity)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private static void validateEntityCountQuery(EntityCountQuery query) { |
|
|
private static void validateEntityCountQuery(EntityCountQuery query) { |
|
|
if (query == null) { |
|
|
if (query == null) { |
|
|
throw new IncorrectParameterException("Query must be specified."); |
|
|
throw new IncorrectParameterException("Query must be specified."); |
|
|
|