Browse Source

Merge 7c63268d27 into ddbb35a73e

pull/15356/merge
Oleksandra Matviienko 24 hours ago
committed by GitHub
parent
commit
a21dbb0523
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      application/src/main/java/org/thingsboard/server/controller/ControllerConstants.java
  2. 45
      application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java
  3. 10
      ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html
  4. 2
      ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.ts
  5. 10
      ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.html
  6. 2
      ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.ts

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

@ -1435,7 +1435,7 @@ public class ControllerConstants {
"Platform creates an audit log event about entity time series updates with action type 'TIMESERIES_UPDATED' that includes an error stacktrace.";
protected static final String ENTITY_ATTRIBUTE_SCOPES_TEMPLATE = " List of possible attribute scopes depends on the entity type: " +
"\n\n * SERVER_SCOPE - supported for all entity types;" +
"\n\n * SERVER_SCOPE - supported for all entity types, including device profiles and asset profiles;" +
"\n * SHARED_SCOPE - supported for devices";
protected static final String ENTITY_SAVE_ATTRIBUTE_SCOPES = ENTITY_ATTRIBUTE_SCOPES_TEMPLATE + ".\n\n";
protected static final String ENTITY_GET_ATTRIBUTE_SCOPES = ENTITY_ATTRIBUTE_SCOPES_TEMPLATE +

45
application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java

@ -13,8 +13,10 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.asset.AssetProfile;
import org.thingsboard.server.common.data.AttributeScope;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.SaveDeviceWithCredentialsRequest;
import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.audit.AuditLog;
@ -32,6 +34,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.dao.service.DaoSqlTest;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@ -361,6 +364,48 @@ public class TelemetryControllerTest extends AbstractControllerTest {
.until(() -> attributesService.find(tenantId, deviceProfileId, AttributeScope.SERVER_SCOPE, "attr").get().isEmpty());
}
@Test
public void testDeviceProfileServerScopeAttributes() throws Exception {
loginTenantAdmin();
DeviceProfile deviceProfile = createDeviceProfile("Test Device Profile");
DeviceProfile savedProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
verifyServerScopeAttributes("DEVICE_PROFILE", savedProfile.getId().getId().toString());
}
@Test
public void testAssetProfileServerScopeAttributes() throws Exception {
loginTenantAdmin();
AssetProfile assetProfile = createAssetProfile("Test Asset Profile");
AssetProfile savedProfile = doPost("/api/assetProfile", assetProfile, AssetProfile.class);
verifyServerScopeAttributes("ASSET_PROFILE", savedProfile.getId().getId().toString());
}
private void verifyServerScopeAttributes(String entityType, String entityId) throws Exception {
String body = "{\"testKey\": \"testValue\", \"testNumber\": 42}";
doPostAsync("/api/plugins/telemetry/" + entityType + "/" + entityId + "/attributes/SERVER_SCOPE", body, String.class, status().isOk());
List<Map<String, Object>> attributes = doGetAsyncTyped(
"/api/plugins/telemetry/" + entityType + "/" + entityId + "/values/attributes/SERVER_SCOPE?keys=testKey,testNumber",
new TypeReference<>() {});
assertThat(attributes).hasSize(2);
assertThat(attributes).anySatisfy(attr -> {
assertThat(attr.get("key")).isEqualTo("testKey");
assertThat(attr.get("value")).isEqualTo("testValue");
});
assertThat(attributes).anySatisfy(attr -> {
assertThat(attr.get("key")).isEqualTo("testNumber");
assertThat(attr.get("value")).isEqualTo(42);
});
doDeleteAsync("/api/plugins/telemetry/" + entityType + "/" + entityId + "/SERVER_SCOPE?keys=testKey,testNumber", String.class);
List<Map<String, Object>> afterDelete = doGetAsyncTyped(
"/api/plugins/telemetry/" + entityType + "/" + entityId + "/values/attributes/SERVER_SCOPE?keys=testKey,testNumber",
new TypeReference<>() {});
assertThat(afterDelete).isEmpty();
}
private Device createDevice() throws Exception {
String testToken = "TEST_TOKEN";

10
ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html

@ -6,6 +6,16 @@
-->
@if (entity && !isEdit) {
@if (resource.ASSET_PROFILE | hasGenericPermission: operation.READ_ATTRIBUTES) {
<mat-tab label="{{ 'attribute.attributes' | translate }}" #attributesTab="matTab">
<tb-attribute-table [defaultAttributeScope]="attributeScopes.SERVER_SCOPE"
[readonly]="!(resource.ASSET_PROFILE | hasGenericPermission: operation.WRITE_ATTRIBUTES)"
[active]="attributesTab.isActive"
[entityId]="entity.id"
[entityName]="entity.name">
</tb-attribute-table>
</mat-tab>
}
@if (authUser.authority === authorities.TENANT_ADMIN && (resource.ASSET_PROFILE | hasGenericPermission: operation.READ_CALCULATED_FIELD)) {
<mat-tab label="{{ 'entity.type-calculated-fields' | translate }}" #calculatedFieldsTab="matTab">
<tb-calculated-fields-table

2
ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.ts

@ -24,7 +24,7 @@ export class AssetProfileTabsComponent extends EntityTabsComponent<AssetProfile>
resolveTabIndex(tab: string): number {
if (tab === 'cf') {
return 1;
return 2;
} else {
return super.resolveTabIndex(tab);
}

10
ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.html

@ -6,6 +6,16 @@
-->
@if (entity) {
@if (!isEdit && (resource.DEVICE_PROFILE | hasGenericPermission: operation.READ_ATTRIBUTES)) {
<mat-tab label="{{ 'attribute.attributes' | translate }}" #attributesTab="matTab">
<tb-attribute-table [defaultAttributeScope]="attributeScopes.SERVER_SCOPE"
[readonly]="!(resource.DEVICE_PROFILE | hasGenericPermission: operation.WRITE_ATTRIBUTES)"
[active]="attributesTab.isActive"
[entityId]="entity.id"
[entityName]="entity.name">
</tb-attribute-table>
</mat-tab>
}
<mat-tab #transportType="matTab" label="{{ 'device-profile.transport-configuration' | translate }}">
@if (transportType.isActive) {
<div class="mat-padding" [formGroup]="detailsForm">

2
ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.ts

@ -51,7 +51,7 @@ export class DeviceProfileTabsComponent extends EntityTabsComponent<DeviceProfil
resolveTabIndex(tab: string): number {
if (tab === 'cf') {
return 2;
return 3;
} else {
return super.resolveTabIndex(tab);
}

Loading…
Cancel
Save