Browse Source

Validator: some old method usage replaced with a new ones with functions

pull/10332/head
Sergey Matvienko 3 years ago
parent
commit
93adbd116c
  1. 2
      application/src/main/java/org/thingsboard/server/controller/BaseController.java
  2. 14
      dao/src/main/java/org/thingsboard/server/dao/asset/BaseAssetService.java
  3. 4
      dao/src/main/java/org/thingsboard/server/dao/attributes/AttributeUtils.java
  4. 8
      dao/src/main/java/org/thingsboard/server/dao/attributes/BaseAttributesService.java
  5. 4
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewServiceImpl.java
  6. 4
      dao/src/main/java/org/thingsboard/server/dao/oauth2/OAuth2ServiceImpl.java
  7. 2
      dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java
  8. 4
      dao/src/main/java/org/thingsboard/server/dao/usagerecord/ApiUsageStateServiceImpl.java

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

@ -541,7 +541,7 @@ public abstract class BaseController {
if (entityId == null) {
throw new ThingsboardException("Parameter entityId can't be empty!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
}
validateId(entityId.getId(), "Incorrect entityId " + entityId);
validateId(entityId.getId(), id -> "Incorrect entityId " + id);
switch (entityId.getEntityType()) {
case ALARM:
checkAlarmId(new AlarmId(entityId.getId()), operation);

14
dao/src/main/java/org/thingsboard/server/dao/asset/BaseAssetService.java

@ -239,7 +239,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
public PageData<Asset> findAssetsByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink) {
log.trace("Executing findAssetsByTenantIdAndType, tenantId [{}], type [{}], pageLink [{}]", tenantId, type, pageLink);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateString(type, "Incorrect type " + type);
validateString(type, t -> "Incorrect type " + t);
validatePageLink(pageLink);
return assetDao.findAssetsByTenantIdAndType(tenantId.getId(), type, pageLink);
}
@ -248,7 +248,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
public PageData<AssetInfo> findAssetInfosByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink) {
log.trace("Executing findAssetInfosByTenantIdAndType, tenantId [{}], type [{}], pageLink [{}]", tenantId, type, pageLink);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateString(type, "Incorrect type " + type);
validateString(type, t -> "Incorrect type " + t);
validatePageLink(pageLink);
return assetDao.findAssetInfosByTenantIdAndType(tenantId.getId(), type, pageLink);
}
@ -266,7 +266,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(TenantId tenantId, List<AssetId> assetIds) {
log.trace("Executing findAssetsByTenantIdAndIdsAsync, tenantId [{}], assetIds [{}]", tenantId, assetIds);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateIds(assetIds, "Incorrect assetIds " + assetIds);
validateIds(assetIds, ids -> "Incorrect assetIds " + ids);
return assetDao.findAssetsByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(assetIds));
}
@ -300,7 +300,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
log.trace("Executing findAssetsByTenantIdAndCustomerIdAndType, tenantId [{}], customerId [{}], type [{}], pageLink [{}]", tenantId, customerId, type, pageLink);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
validateString(type, "Incorrect type " + type);
validateString(type, t -> "Incorrect type " + t);
validatePageLink(pageLink);
return assetDao.findAssetsByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);
}
@ -310,7 +310,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
log.trace("Executing findAssetInfosByTenantIdAndCustomerIdAndType, tenantId [{}], customerId [{}], type [{}], pageLink [{}]", tenantId, customerId, type, pageLink);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
validateString(type, "Incorrect type " + type);
validateString(type, t -> "Incorrect type " + t);
validatePageLink(pageLink);
return assetDao.findAssetInfosByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);
}
@ -330,7 +330,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
log.trace("Executing findAssetsByTenantIdAndCustomerIdAndIdsAsync, tenantId [{}], customerId [{}], assetIds [{}]", tenantId, customerId, assetIds);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
validateIds(assetIds, "Incorrect assetIds " + assetIds);
validateIds(assetIds, ids -> "Incorrect assetIds " + ids);
return assetDao.findAssetsByTenantIdAndCustomerIdAndIdsAsync(tenantId.getId(), customerId.getId(), toUUIDs(assetIds));
}
@ -430,7 +430,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
log.trace("Executing findAssetsByTenantIdAndEdgeIdAndType, tenantId [{}], edgeId [{}], type [{}] pageLink [{}]", tenantId, edgeId, type, pageLink);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateId(edgeId, INCORRECT_EDGE_ID + edgeId);
validateString(type, "Incorrect type " + type);
validateString(type, t -> "Incorrect type " + t);
validatePageLink(pageLink);
return assetDao.findAssetsByTenantIdAndEdgeIdAndType(tenantId.getId(), edgeId.getId(), type, pageLink);
}

4
dao/src/main/java/org/thingsboard/server/dao/attributes/AttributeUtils.java

@ -28,12 +28,12 @@ public class AttributeUtils {
@Deprecated(since = "3.7.0")
public static void validate(EntityId id, String scope) {
Validator.validateId(id.getId(), "Incorrect id " + id);
Validator.validateId(id.getId(), uuid -> "Incorrect id " + uuid);
Validator.validateString(scope, sc -> "Incorrect scope " + sc);
}
public static void validate(EntityId id, AttributeScope scope) {
Validator.validateId(id.getId(), "Incorrect id " + id);
Validator.validateId(id.getId(), uuid -> "Incorrect id " + uuid);
Validator.checkNotNull(scope, "Incorrect scope " + scope);
}

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

@ -58,28 +58,28 @@ public class BaseAttributesService implements AttributesService {
@Override
public ListenableFuture<Optional<AttributeKvEntry>> find(TenantId tenantId, EntityId entityId, String scope, String attributeKey) {
validate(entityId, scope);
Validator.validateString(attributeKey, "Incorrect attribute key " + attributeKey);
Validator.validateString(attributeKey, k -> "Incorrect attribute key " + k);
return Futures.immediateFuture(attributesDao.find(tenantId, entityId, AttributeScope.valueOf(scope), attributeKey));
}
@Override
public ListenableFuture<Optional<AttributeKvEntry>> find(TenantId tenantId, EntityId entityId, AttributeScope scope, String attributeKey) {
validate(entityId, scope);
Validator.validateString(attributeKey, "Incorrect attribute key " + attributeKey);
Validator.validateString(attributeKey, k -> "Incorrect attribute key " + k);
return Futures.immediateFuture(attributesDao.find(tenantId, entityId, scope, attributeKey));
}
@Override
public ListenableFuture<List<AttributeKvEntry>> find(TenantId tenantId, EntityId entityId, String scope, Collection<String> attributeKeys) {
validate(entityId, scope);
attributeKeys.forEach(attributeKey -> Validator.validateString(attributeKey, "Incorrect attribute key " + attributeKey));
attributeKeys.forEach(attributeKey -> Validator.validateString(attributeKey, k -> "Incorrect attribute key " + k));
return Futures.immediateFuture(attributesDao.find(tenantId, entityId, AttributeScope.valueOf(scope), attributeKeys));
}
@Override
public ListenableFuture<List<AttributeKvEntry>> find(TenantId tenantId, EntityId entityId, AttributeScope scope, Collection<String> attributeKeys) {
validate(entityId, scope);
attributeKeys.forEach(attributeKey -> Validator.validateString(attributeKey, "Incorrect attribute key " + attributeKey));
attributeKeys.forEach(attributeKey -> Validator.validateString(attributeKey, k -> "Incorrect attribute key " + k));
return Futures.immediateFuture(attributesDao.find(tenantId, entityId, scope, attributeKeys));
}

4
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewServiceImpl.java

@ -299,7 +299,7 @@ public class EntityViewServiceImpl extends AbstractCachedEntityService<EntityVie
public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(TenantId tenantId, EntityId entityId) {
log.trace("Executing findEntityViewsByTenantIdAndEntityIdAsync, tenantId [{}], entityId [{}]", tenantId, entityId);
validateId(tenantId, id -> INCORRECT_TENANT_ID + id);
validateId(entityId.getId(), "Incorrect entityId" + entityId);
validateId(entityId.getId(), id -> "Incorrect entityId" + id);
return service.submit(() -> cache.getAndPutInTransaction(EntityViewCacheKey.byEntityId(tenantId, entityId),
() -> entityViewDao.findEntityViewsByTenantIdAndEntityId(tenantId.getId(), entityId.getId()),
@ -310,7 +310,7 @@ public class EntityViewServiceImpl extends AbstractCachedEntityService<EntityVie
public List<EntityView> findEntityViewsByTenantIdAndEntityId(TenantId tenantId, EntityId entityId) {
log.trace("Executing findEntityViewsByTenantIdAndEntityId, tenantId [{}], entityId [{}]", tenantId, entityId);
validateId(tenantId, id -> INCORRECT_TENANT_ID + id);
validateId(entityId.getId(), "Incorrect entityId" + entityId);
validateId(entityId.getId(), id -> "Incorrect entityId" + id);
return cache.getAndPutInTransaction(EntityViewCacheKey.byEntityId(tenantId, entityId),
() -> entityViewDao.findEntityViewsByTenantIdAndEntityId(tenantId.getId(), entityId.getId()),

4
dao/src/main/java/org/thingsboard/server/dao/oauth2/OAuth2ServiceImpl.java

@ -142,14 +142,14 @@ public class OAuth2ServiceImpl extends AbstractEntityService implements OAuth2Se
@Override
public OAuth2Registration findRegistration(UUID id) {
log.trace("Executing findRegistration [{}]", id);
validateId(id, INCORRECT_CLIENT_REGISTRATION_ID + id);
validateId(id, uuid -> INCORRECT_CLIENT_REGISTRATION_ID + uuid);
return oauth2RegistrationDao.findById(null, id);
}
@Override
public String findAppSecret(UUID id, String pkgName) {
log.trace("Executing findAppSecret [{}][{}]", id, pkgName);
validateId(id, INCORRECT_CLIENT_REGISTRATION_ID + id);
validateId(id, uuid -> INCORRECT_CLIENT_REGISTRATION_ID + uuid);
validateString(pkgName, "Incorrect package name");
return oauth2RegistrationDao.findAppSecret(id, pkgName);
}

2
dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java

@ -755,7 +755,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
@Override
public List<RuleNode> findAllRuleNodesByIds(List<RuleNodeId> ruleNodeIds) {
log.trace("Executing findAllRuleNodesByIds, ruleNodeIds {}", ruleNodeIds);
validateIds(ruleNodeIds, "Incorrect ruleNodeIds " + ruleNodeIds);
validateIds(ruleNodeIds, ids -> "Incorrect ruleNodeIds " + ids);
assert ruleNodeIds.size() <= 1024;
return ruleNodeDao.findAllRuleNodeByIds(ruleNodeIds);
}

4
dao/src/main/java/org/thingsboard/server/dao/usagerecord/ApiUsageStateServiceImpl.java

@ -79,7 +79,7 @@ public class ApiUsageStateServiceImpl extends AbstractEntityService implements A
@Override
public void deleteApiUsageStateByEntityId(EntityId entityId) {
log.trace("Executing deleteApiUsageStateByEntityId [{}]", entityId);
validateId(entityId.getId(), "Invalid entity id");
validateId(entityId.getId(), id -> "Invalid entity id " + id);
apiUsageStateDao.deleteApiUsageStateByEntityId(entityId);
}
@ -159,7 +159,7 @@ public class ApiUsageStateServiceImpl extends AbstractEntityService implements A
@Override
public ApiUsageState findApiUsageStateByEntityId(EntityId entityId) {
validateId(entityId.getId(), "Invalid entity id");
validateId(entityId.getId(), id -> "Invalid entity id " + id);
return apiUsageStateDao.findApiUsageStateByEntityId(entityId);
}

Loading…
Cancel
Save