Browse Source

Added reading attributes by attribute_key

pull/3557/head
viktor 6 years ago
parent
commit
e650cb0c24
  1. 2
      application/src/main/java/org/thingsboard/server/controller/AuthController.java
  2. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/attributes/AttributesService.java
  3. 2
      dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesDao.java
  4. 6
      dao/src/main/java/org/thingsboard/server/dao/attributes/BaseAttributesService.java
  5. 2
      dao/src/main/java/org/thingsboard/server/dao/sql/attributes/AttributeKvRepository.java
  6. 6
      dao/src/main/java/org/thingsboard/server/dao/sql/attributes/JpaAttributeDao.java

2
application/src/main/java/org/thingsboard/server/controller/AuthController.java

@ -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.ThingsboardErrorCode;
import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.id.TenantId; 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.common.data.security.UserCredentials;
import org.thingsboard.server.dao.audit.AuditLogService; 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.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository; import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository;
import org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails; import org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails;

2
common/dao-api/src/main/java/org/thingsboard/server/dao/attributes/AttributesService.java

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

2
dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesDao.java

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

6
dao/src/main/java/org/thingsboard/server/dao/attributes/BaseAttributesService.java

@ -59,6 +59,12 @@ public class BaseAttributesService implements AttributesService {
return attributesDao.findAll(tenantId, entityId, scope); 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 @Override
public ListenableFuture<List<Void>> save(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes) { public ListenableFuture<List<Void>> save(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes) {
validate(entityId, scope); validate(entityId, scope);

2
dao/src/main/java/org/thingsboard/server/dao/sql/attributes/AttributeKvRepository.java

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

6
dao/src/main/java/org/thingsboard/server/dao/sql/attributes/JpaAttributeDao.java

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

Loading…
Cancel
Save