Commit a5e8cab5e06b166af860412e623f9e10a775638d
Committed by
GitHub
Merge pull request #3700 from YevhenBondarenko/feature/api-usage-state-tmp
api usage state alias improvements
Showing
5 changed files
with
27 additions
and
3 deletions
@@ -210,7 +210,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -210,7 +210,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
210 | entityTableMap.put(EntityType.CUSTOMER, "customer"); | 210 | entityTableMap.put(EntityType.CUSTOMER, "customer"); |
211 | entityTableMap.put(EntityType.USER, "tb_user"); | 211 | entityTableMap.put(EntityType.USER, "tb_user"); |
212 | entityTableMap.put(EntityType.TENANT, "tenant"); | 212 | entityTableMap.put(EntityType.TENANT, "tenant"); |
213 | - entityTableMap.put(EntityType.API_USAGE_STATE, "(select aus.id, aus.created_time, aus.tenant_id, '' as name, '' as additional_info from api_usage_state as aus)"); | 213 | + entityTableMap.put(EntityType.API_USAGE_STATE, "api_usage_state"); |
214 | } | 214 | } |
215 | 215 | ||
216 | public static EntityType[] RELATION_QUERY_ENTITY_TYPES = new EntityType[]{ | 216 | public static EntityType[] RELATION_QUERY_ENTITY_TYPES = new EntityType[]{ |
@@ -80,6 +80,7 @@ public class EntityKeyMapping { | @@ -80,6 +80,7 @@ public class EntityKeyMapping { | ||
80 | public static final List<String> labeledEntityFields = Arrays.asList(CREATED_TIME, ENTITY_TYPE, NAME, TYPE, LABEL, ADDITIONAL_INFO); | 80 | public static final List<String> labeledEntityFields = Arrays.asList(CREATED_TIME, ENTITY_TYPE, NAME, TYPE, LABEL, ADDITIONAL_INFO); |
81 | public static final List<String> contactBasedEntityFields = Arrays.asList(CREATED_TIME, ENTITY_TYPE, EMAIL, TITLE, COUNTRY, STATE, CITY, ADDRESS, ADDRESS_2, ZIP, PHONE, ADDITIONAL_INFO); | 81 | public static final List<String> contactBasedEntityFields = Arrays.asList(CREATED_TIME, ENTITY_TYPE, EMAIL, TITLE, COUNTRY, STATE, CITY, ADDRESS, ADDRESS_2, ZIP, PHONE, ADDITIONAL_INFO); |
82 | 82 | ||
83 | + public static final Set<String> apiUsageStateEntityFields = Collections.singleton(CREATED_TIME); | ||
83 | public static final Set<String> commonEntityFieldsSet = new HashSet<>(commonEntityFields); | 84 | public static final Set<String> commonEntityFieldsSet = new HashSet<>(commonEntityFields); |
84 | public static final Set<String> relationQueryEntityFieldsSet = new HashSet<>(Arrays.asList(CREATED_TIME, ENTITY_TYPE, NAME, TYPE, LABEL, FIRST_NAME, LAST_NAME, EMAIL, REGION, TITLE, COUNTRY, STATE, CITY, ADDRESS, ADDRESS_2, ZIP, PHONE, ADDITIONAL_INFO)); | 85 | public static final Set<String> relationQueryEntityFieldsSet = new HashSet<>(Arrays.asList(CREATED_TIME, ENTITY_TYPE, NAME, TYPE, LABEL, FIRST_NAME, LAST_NAME, EMAIL, REGION, TITLE, COUNTRY, STATE, CITY, ADDRESS, ADDRESS_2, ZIP, PHONE, ADDITIONAL_INFO)); |
85 | 86 | ||
@@ -99,6 +100,7 @@ public class EntityKeyMapping { | @@ -99,6 +100,7 @@ public class EntityKeyMapping { | ||
99 | allowedEntityFieldMap.put(EntityType.RULE_NODE, new HashSet<>(commonEntityFields)); | 100 | allowedEntityFieldMap.put(EntityType.RULE_NODE, new HashSet<>(commonEntityFields)); |
100 | allowedEntityFieldMap.put(EntityType.WIDGET_TYPE, new HashSet<>(widgetEntityFields)); | 101 | allowedEntityFieldMap.put(EntityType.WIDGET_TYPE, new HashSet<>(widgetEntityFields)); |
101 | allowedEntityFieldMap.put(EntityType.WIDGETS_BUNDLE, new HashSet<>(widgetEntityFields)); | 102 | allowedEntityFieldMap.put(EntityType.WIDGETS_BUNDLE, new HashSet<>(widgetEntityFields)); |
103 | + allowedEntityFieldMap.put(EntityType.API_USAGE_STATE, apiUsageStateEntityFields); | ||
102 | 104 | ||
103 | entityFieldColumnMap.put(CREATED_TIME, ModelConstants.CREATED_TIME_PROPERTY); | 105 | entityFieldColumnMap.put(CREATED_TIME, ModelConstants.CREATED_TIME_PROPERTY); |
104 | entityFieldColumnMap.put(ENTITY_TYPE, ModelConstants.ENTITY_TYPE_PROPERTY); | 106 | entityFieldColumnMap.put(ENTITY_TYPE, ModelConstants.ENTITY_TYPE_PROPERTY); |
@@ -17,6 +17,7 @@ package org.thingsboard.server.dao.usagerecord; | @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.usagerecord; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
20 | +import org.thingsboard.server.common.data.ApiFeature; | ||
20 | import org.thingsboard.server.common.data.ApiUsageRecordKey; | 21 | import org.thingsboard.server.common.data.ApiUsageRecordKey; |
21 | import org.thingsboard.server.common.data.ApiUsageState; | 22 | import org.thingsboard.server.common.data.ApiUsageState; |
22 | import org.thingsboard.server.common.data.ApiUsageStateValue; | 23 | import org.thingsboard.server.common.data.ApiUsageStateValue; |
@@ -27,6 +28,7 @@ import org.thingsboard.server.common.data.id.ApiUsageStateId; | @@ -27,6 +28,7 @@ import org.thingsboard.server.common.data.id.ApiUsageStateId; | ||
27 | import org.thingsboard.server.common.data.id.TenantId; | 28 | import org.thingsboard.server.common.data.id.TenantId; |
28 | import org.thingsboard.server.common.data.kv.BasicTsKvEntry; | 29 | import org.thingsboard.server.common.data.kv.BasicTsKvEntry; |
29 | import org.thingsboard.server.common.data.kv.LongDataEntry; | 30 | import org.thingsboard.server.common.data.kv.LongDataEntry; |
31 | +import org.thingsboard.server.common.data.kv.StringDataEntry; | ||
30 | import org.thingsboard.server.common.data.kv.TsKvEntry; | 32 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
31 | import org.thingsboard.server.common.data.tenant.profile.TenantProfileConfiguration; | 33 | import org.thingsboard.server.common.data.tenant.profile.TenantProfileConfiguration; |
32 | import org.thingsboard.server.dao.entity.AbstractEntityService; | 34 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
@@ -83,7 +85,19 @@ public class ApiUsageStateServiceImpl extends AbstractEntityService implements A | @@ -83,7 +85,19 @@ public class ApiUsageStateServiceImpl extends AbstractEntityService implements A | ||
83 | Tenant tenant = tenantDao.findById(tenantId, tenantId.getId()); | 85 | Tenant tenant = tenantDao.findById(tenantId, tenantId.getId()); |
84 | TenantProfile tenantProfile = tenantProfileDao.findById(tenantId, tenant.getTenantProfileId().getId()); | 86 | TenantProfile tenantProfile = tenantProfileDao.findById(tenantId, tenant.getTenantProfileId().getId()); |
85 | TenantProfileConfiguration configuration = tenantProfile.getProfileData().getConfiguration(); | 87 | TenantProfileConfiguration configuration = tenantProfile.getProfileData().getConfiguration(); |
88 | + List<TsKvEntry> apiUsageStates = new ArrayList<>(); | ||
89 | + apiUsageStates.add(new BasicTsKvEntry(apiUsageState.getCreatedTime(), | ||
90 | + new StringDataEntry(ApiFeature.TRANSPORT.getApiStateKey(), ApiUsageStateValue.ENABLED.name()))); | ||
91 | + apiUsageStates.add(new BasicTsKvEntry(apiUsageState.getCreatedTime(), | ||
92 | + new StringDataEntry(ApiFeature.DB.getApiStateKey(), ApiUsageStateValue.ENABLED.name()))); | ||
93 | + apiUsageStates.add(new BasicTsKvEntry(apiUsageState.getCreatedTime(), | ||
94 | + new StringDataEntry(ApiFeature.RE.getApiStateKey(), ApiUsageStateValue.ENABLED.name()))); | ||
95 | + apiUsageStates.add(new BasicTsKvEntry(apiUsageState.getCreatedTime(), | ||
96 | + new StringDataEntry(ApiFeature.JS.getApiStateKey(), ApiUsageStateValue.ENABLED.name()))); | ||
97 | + tsService.save(tenantId, saved.getId(), apiUsageStates, 0L); | ||
98 | + | ||
86 | List<TsKvEntry> profileThresholds = new ArrayList<>(); | 99 | List<TsKvEntry> profileThresholds = new ArrayList<>(); |
100 | + | ||
87 | for (ApiUsageRecordKey key : ApiUsageRecordKey.values()) { | 101 | for (ApiUsageRecordKey key : ApiUsageRecordKey.values()) { |
88 | profileThresholds.add(new BasicTsKvEntry(saved.getCreatedTime(), new LongDataEntry(key.getApiLimitKey(), configuration.getProfileThreshold(key)))); | 102 | profileThresholds.add(new BasicTsKvEntry(saved.getCreatedTime(), new LongDataEntry(key.getApiLimitKey(), configuration.getProfileThreshold(key)))); |
89 | } | 103 | } |
@@ -47,7 +47,8 @@ export enum EntityType { | @@ -47,7 +47,8 @@ export enum EntityType { | ||
47 | RULE_NODE = 'RULE_NODE', | 47 | RULE_NODE = 'RULE_NODE', |
48 | ENTITY_VIEW = 'ENTITY_VIEW', | 48 | ENTITY_VIEW = 'ENTITY_VIEW', |
49 | WIDGETS_BUNDLE = 'WIDGETS_BUNDLE', | 49 | WIDGETS_BUNDLE = 'WIDGETS_BUNDLE', |
50 | - WIDGET_TYPE = 'WIDGET_TYPE' | 50 | + WIDGET_TYPE = 'WIDGET_TYPE', |
51 | + API_USAGE_STATE = 'API_USAGE_STATE' | ||
51 | } | 52 | } |
52 | 53 | ||
53 | export enum AliasEntityType { | 54 | export enum AliasEntityType { |
@@ -239,6 +240,12 @@ export const entityTypeTranslations = new Map<EntityType | AliasEntityType, Enti | @@ -239,6 +240,12 @@ export const entityTypeTranslations = new Map<EntityType | AliasEntityType, Enti | ||
239 | } | 240 | } |
240 | ], | 241 | ], |
241 | [ | 242 | [ |
243 | + EntityType.API_USAGE_STATE, | ||
244 | + { | ||
245 | + type: 'entity.type-api-usage-state' | ||
246 | + } | ||
247 | + ], | ||
248 | + [ | ||
242 | EntityType.WIDGETS_BUNDLE, | 249 | EntityType.WIDGETS_BUNDLE, |
243 | { | 250 | { |
244 | details: 'widgets-bundle.widgets-bundle-details', | 251 | details: 'widgets-bundle.widgets-bundle-details', |
@@ -1099,7 +1099,8 @@ | @@ -1099,7 +1099,8 @@ | ||
1099 | "details": "Entity details", | 1099 | "details": "Entity details", |
1100 | "no-entities-prompt": "No entities found", | 1100 | "no-entities-prompt": "No entities found", |
1101 | "no-data": "No data to display", | 1101 | "no-data": "No data to display", |
1102 | - "columns-to-display": "Columns to Display" | 1102 | + "columns-to-display": "Columns to Display", |
1103 | + "type-api-usage-state": "Api Usage State" | ||
1103 | }, | 1104 | }, |
1104 | "entity-field": { | 1105 | "entity-field": { |
1105 | "created-time": "Created time", | 1106 | "created-time": "Created time", |