Added reading attributes by attribute_key

This commit is contained in:
viktor 2020-06-23 19:20:00 +03:00
parent 1d56a1937b
commit e650cb0c24
6 changed files with 18 additions and 2 deletions

View File

@ -38,10 +38,8 @@ import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo;
import org.thingsboard.server.common.data.security.UserCredentials;
import org.thingsboard.server.dao.audit.AuditLogService;
import org.thingsboard.server.dao.oauth2.OAuth2Service;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository;
import org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails;

View File

@ -35,6 +35,8 @@ public interface AttributesService {
ListenableFuture<List<AttributeKvEntry>> findAll(TenantId tenantId, EntityId entityId, String scope);
ListenableFuture<List<AttributeKvEntry>> findAllByAttributeKey(String attributeKey);
ListenableFuture<List<Void>> save(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes);
ListenableFuture<List<Void>> removeAll(TenantId tenantId, EntityId entityId, String scope, List<String> attributeKeys);

View File

@ -35,6 +35,8 @@ public interface AttributesDao {
ListenableFuture<List<AttributeKvEntry>> findAll(TenantId tenantId, EntityId entityId, String attributeType);
ListenableFuture<List<AttributeKvEntry>> findAllByAttributeKey(String attributeKey);
ListenableFuture<Void> save(TenantId tenantId, EntityId entityId, String attributeType, AttributeKvEntry attribute);
ListenableFuture<List<Void>> removeAll(TenantId tenantId, EntityId entityId, String attributeType, List<String> keys);

View File

@ -59,6 +59,12 @@ public class BaseAttributesService implements AttributesService {
return attributesDao.findAll(tenantId, entityId, scope);
}
@Override
public ListenableFuture<List<AttributeKvEntry>> findAllByAttributeKey(String attributeKey) {
Validator.validateString(attributeKey, "Incorrect attribute key " + attributeKey);
return attributesDao.findAllByAttributeKey(attributeKey);
}
@Override
public ListenableFuture<List<Void>> save(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes) {
validate(entityId, scope);

View File

@ -47,5 +47,7 @@ public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity,
@Param("entityId") String entityId,
@Param("attributeType") String attributeType,
@Param("attributeKey") String attributeKey);
List<AttributeKvEntity> findAllByAttributeKey(String attributeKey);
}

View File

@ -119,6 +119,12 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl
attributeType))));
}
@Override
public ListenableFuture<List<AttributeKvEntry>> findAllByAttributeKey(String attributeKey) {
return Futures.immediateFuture(
DaoUtil.convertDataList(attributeKvRepository.findAllByAttributeKey(attributeKey)));
}
@Override
public ListenableFuture<Void> save(TenantId tenantId, EntityId entityId, String attributeType, AttributeKvEntry attribute) {
AttributeKvEntity entity = new AttributeKvEntity();