From e6d4e91e25a529afedd16b5b102684f318c75f8d Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Wed, 20 Jan 2021 19:17:13 +0200 Subject: [PATCH] Lwm2m: front: refactoring n number validators --- .../server/LwM2MTransportServiceImpl.java | 57 ++++++++++--------- .../lwm2m/server/client/LwM2MClient.java | 2 +- ...m-object-add-instances-list.component.html | 16 +++--- ...m2m-object-add-instances-list.component.ts | 4 +- .../device/lwm2m/profile-config.models.ts | 2 +- .../assets/locale/locale.constant-en_US.json | 1 + 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java index 072c7bc402..3255d24760 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java @@ -20,6 +20,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import lombok.extern.slf4j.Slf4j; +import org.eclipse.leshan.core.Link; import org.eclipse.leshan.core.model.ResourceModel; import org.eclipse.leshan.core.node.LwM2mMultipleResource; import org.eclipse.leshan.core.node.LwM2mObject; @@ -153,7 +154,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { lwM2MClient.setLwM2MTransportServiceImpl(this); lwM2MClient.setSessionUuid(UUID.randomUUID()); this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration); -// this.setLwM2MClient(lwServer, registration, lwM2MClient); +// this.setLwM2mFromClientValue(lwServer, registration, lwM2MClient); SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration); if (sessionInfo != null) { lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB())); @@ -164,6 +165,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { transportService.process(sessionInfo, DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN), null); transportService.process(sessionInfo, TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build(), null); this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration); + this.putDelayedUpdateResourcesThingsboard(lwM2MClient); } else { log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null); } @@ -198,7 +200,6 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { }); } - /** * @param registration - Registration LwM2M Client * @param observations - All paths observations before unReg @@ -279,33 +280,33 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { * @param registration - Registration LwM2M Client * @param lwM2MClient - object with All parameters off client */ - private void setLwM2MClient(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient) { -// Arrays.stream(registration.getObjectLinks()).forEach(url -> { -// LwM2mPath pathIds = new LwM2mPath(url.getUrl()); -// if (pathIds.isObjectInstance() && !pathIds.isResource()) { -// // #1 -// lwM2MClient.getPendingRequests().add(url.getUrl()); -// // #2 -// lwM2MTransportRequest.sendAllRequest(lwServer, registration, url.getUrl(), GET_TYPE_OPER_READ, ContentFormat.TLV.getName(), -// lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false); -// } -// }); + private void setLwM2mFromClientValue(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient) { + Arrays.stream(registration.getObjectLinks()).forEach(url -> { + LwM2mPath pathIds = new LwM2mPath(url.getUrl()); + if (pathIds.isObjectInstance() && !pathIds.isResource()) { + // #1 + lwM2MClient.getPendingRequests().add(url.getUrl()); + // #2 + lwM2MTransportRequest.sendAllRequest(lwServer, registration, url.getUrl(), GET_TYPE_OPER_READ, ContentFormat.TLV.getName(), + lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false); + } + }); -// // #1 -// for (Link url : registration.getObjectLinks()) { -// LwM2mPath pathIds = new LwM2mPath(url.getUrl()); -// if (pathIds.isObjectInstance() && !pathIds.isResource()) { -// lwM2MClient.getPendingRequests().add(url.getUrl()); -// } -// } -// // #2 -// for (Link url : registration.getObjectLinks()) { -// LwM2mPath pathIds = new LwM2mPath(url.getUrl()); -// if (pathIds.isObjectInstance() && !pathIds.isResource()) { -// lwM2MTransportRequest.sendAllRequest(lwServer, registration, url.getUrl(), GET_TYPE_OPER_READ, ContentFormat.TLV.getName(), -// lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false); -// } -// } + // #1 + for (Link url : registration.getObjectLinks()) { + LwM2mPath pathIds = new LwM2mPath(url.getUrl()); + if (pathIds.isObjectInstance() && !pathIds.isResource()) { + lwM2MClient.getPendingRequests().add(url.getUrl()); + } + } + // #2 + for (Link url : registration.getObjectLinks()) { + LwM2mPath pathIds = new LwM2mPath(url.getUrl()); + if (pathIds.isObjectInstance() && !pathIds.isResource()) { + lwM2MTransportRequest.sendAllRequest(lwServer, registration, url.getUrl(), GET_TYPE_OPER_READ, ContentFormat.TLV.getName(), + lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false); + } + } // #1 Arrays.stream(registration.getObjectLinks()).forEach(url -> { diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2MClient.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2MClient.java index fdb2055500..f20853299d 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2MClient.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2MClient.java @@ -93,7 +93,7 @@ public class LwM2MClient implements Cloneable { this.pendingRequests.remove(path); if (this.pendingRequests.size() == 0) { this.initValue(); - this.lwM2MTransportServiceImpl.putDelayedUpdateResourcesThingsboard(this); +// this.lwM2MTransportServiceImpl.putDelayedUpdateResourcesThingsboard(this); } } diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.html b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.html index 5a03f3f54d..34d77c299b 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.html @@ -31,9 +31,7 @@ {{ 'device-profile.lwm2m.instances-input' | translate }} - - {{ translate.get('device-profile.lwm2m.valid-id-instance-no-min', { - instance: instanceId, min: instanceIdValueMin + {{ translate.get('device-profile.lwm2m.valid-id-instance', { + count: 2, instance: instanceId, min: instanceIdValueMin }) | async }} - {{ translate.get('device-profile.lwm2m.valid-id-instance-no-max', { - instance: instanceId, max: instanceIdValueMax + {{ translate.get('device-profile.lwm2m.valid-id-instance', { + count: 1, instance: instanceId, max: instanceIdValueMax }) | async }} - {{ translate.get('device-profile.lwm2m.instances-input-holder', { - instance: instanceId, max: instanceIdValueMax + {{ translate.get('device-profile.lwm2m.valid-id-instance', { + count: 0, instance: instanceId, max: instanceIdValueMax }) | async }} diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.ts index 1375b49112..1921db396d 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.ts @@ -80,8 +80,8 @@ export class Lwm2mObjectAddInstancesListComponent implements ControlValueAccesso } add = (): void => { - if (this.instancesListFormGroup.get('instanceIdInput').valid) { - this.instancesId.add(this.instanceId); + if (this.instancesListFormGroup.get('instanceIdInput').valid && Number.isFinite(Number(this.instanceId))) { + this.instancesId.add(Number(this.instanceId)); this.instancesListFormGroup.get('instanceIdInput').setValue(null); this.propagateChange(this.instancesId); this.dirty = true; diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts index 1849fd3279..11c16ac802 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts @@ -33,7 +33,7 @@ export const DEFAULT_BOOTSTRAP_SERVER_ACCOUNT_TIME_OUT = 0; export const LEN_MAX_PUBLIC_KEY_RPK = 182; export const LEN_MAX_PUBLIC_KEY_X509 = 3000; export const KEY_REGEXP_HEX_DEC = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/; -export const KEY_REGEXP_NUMBER = /^\d*$/; +export const KEY_REGEXP_NUMBER = /^(\-?|\+?)\d*$/; export const INSTANCES_ID_VALUE_MIN = 0; export const INSTANCES_ID_VALUE_MAX = 65535; diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 1ff1e0a6e0..b26fb40b1e 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1102,6 +1102,7 @@ "no-objects-matching": "No objects matching '{{object}}' were found.", "valid-id-instance-no-min": "Instance number '{{instance}}' no validated. Min value='{{min}}'", "valid-id-instance-no-max": "Instance number '{{instance}}' no validated. Max value='{{max}}'", + "valid-id-instance": "Instance number '{{instance}}' no validated. { count, plural, 1 {Max value='{{max}}'} 2 {Min value='{{min}}'} other {Must be only number} }", "model-tab": "LWM2M Model", "add-instances-tip": "Add new instances", "instances-list": "Instances list",