...
|
...
|
@@ -21,11 +21,10 @@ import com.google.gson.JsonElement; |
21
|
21
|
import com.google.gson.JsonObject;
|
22
|
22
|
import lombok.extern.slf4j.Slf4j;
|
23
|
23
|
import org.eclipse.leshan.core.model.ResourceModel;
|
24
|
|
-import org.eclipse.leshan.core.node.LwM2mMultipleResource;
|
25
|
24
|
import org.eclipse.leshan.core.node.LwM2mObject;
|
26
|
25
|
import org.eclipse.leshan.core.node.LwM2mObjectInstance;
|
27
|
26
|
import org.eclipse.leshan.core.node.LwM2mPath;
|
28
|
|
-import org.eclipse.leshan.core.node.LwM2mSingleResource;
|
|
27
|
+import org.eclipse.leshan.core.node.LwM2mResource;
|
29
|
28
|
import org.eclipse.leshan.core.observation.Observation;
|
30
|
29
|
import org.eclipse.leshan.core.request.ContentFormat;
|
31
|
30
|
import org.eclipse.leshan.core.request.WriteRequest;
|
...
|
...
|
@@ -47,8 +46,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent; |
47
|
46
|
import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
|
48
|
47
|
import org.thingsboard.server.gen.transport.TransportProtos.ToTransportUpdateCredentialsProto;
|
49
|
48
|
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCredentialsResponseMsg;
|
50
|
|
-import org.thingsboard.server.transport.lwm2m.server.client.AttrTelemetryObserveValue;
|
51
|
49
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClient;
|
|
50
|
+import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientProfile;
|
52
|
51
|
import org.thingsboard.server.transport.lwm2m.server.client.ResourceValue;
|
53
|
52
|
import org.thingsboard.server.transport.lwm2m.server.client.ResultsAnalyzerParameters;
|
54
|
53
|
import org.thingsboard.server.transport.lwm2m.server.secure.LwM2mInMemorySecurityStore;
|
...
|
...
|
@@ -71,7 +70,6 @@ import java.util.concurrent.ConcurrentMap; |
71
|
70
|
import java.util.concurrent.ExecutorService;
|
72
|
71
|
import java.util.concurrent.Executors;
|
73
|
72
|
import java.util.concurrent.TimeUnit;
|
74
|
|
-import java.util.concurrent.atomic.AtomicBoolean;
|
75
|
73
|
import java.util.concurrent.locks.Lock;
|
76
|
74
|
import java.util.concurrent.locks.ReadWriteLock;
|
77
|
75
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
...
|
...
|
@@ -153,8 +151,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
153
|
151
|
lwM2MClient.setLwM2MTransportServiceImpl(this);
|
154
|
152
|
lwM2MClient.setSessionUuid(UUID.randomUUID());
|
155
|
153
|
this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration);
|
156
|
|
- this.setLwM2mFromClientValue(lwServer, registration, lwM2MClient);
|
157
|
|
- lwM2MClient.setClientUpdateValueAfterConnect(this.context.getCtxServer().isClientUpdateValueAfterConnect());
|
|
154
|
+ LwM2MClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore.getProfile(registration.getId());
|
|
155
|
+ this.setLwM2mFromClientValue(lwServer, registration, lwM2MClient, lwM2MClientProfile);
|
158
|
156
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
159
|
157
|
if (sessionInfo != null) {
|
160
|
158
|
lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
|
...
|
...
|
@@ -165,7 +163,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
165
|
163
|
transportService.process(sessionInfo, DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN), null);
|
166
|
164
|
transportService.process(sessionInfo, TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build(), null);
|
167
|
165
|
this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration);
|
168
|
|
- if (this.context.getCtxServer().isClientUpdateValueAfterConnect()) {
|
|
166
|
+ if (LwM2MTransportHandler.getClientUpdateValueAfterConnect(lwM2MClientProfile)) {
|
169
|
167
|
this.putDelayedUpdateResourcesThingsboard(lwM2MClient);
|
170
|
168
|
}
|
171
|
169
|
} else {
|
...
|
...
|
@@ -255,7 +253,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
255
|
253
|
* Removes a profile if not used in sessions
|
256
|
254
|
*/
|
257
|
255
|
private void syncSessionsAndProfiles() {
|
258
|
|
- Map<UUID, AttrTelemetryObserveValue> profilesClone = lwM2mInMemorySecurityStore.getProfiles().entrySet()
|
|
256
|
+ Map<UUID, LwM2MClientProfile> profilesClone = lwM2mInMemorySecurityStore.getProfiles().entrySet()
|
259
|
257
|
.stream()
|
260
|
258
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
261
|
259
|
profilesClone.forEach((k, v) -> {
|
...
|
...
|
@@ -285,9 +283,26 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
285
|
283
|
* @param registration - Registration LwM2M Client
|
286
|
284
|
* @param lwM2MClient - object with All parameters off client
|
287
|
285
|
*/
|
288
|
|
- private void setLwM2mFromClientValue(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient) {
|
|
286
|
+ private void setLwM2mFromClientValue(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient, LwM2MClientProfile lwM2MClientProfile) {
|
289
|
287
|
// #1.1
|
290
|
288
|
// get all instances in client
|
|
289
|
+ Set<String> clientInstances = this.getAllInstancesInClient(registration);
|
|
290
|
+ if (clientInstances != null && LwM2MTransportHandler.getClientUpdateValueAfterConnect(lwM2MClientProfile)) {
|
|
291
|
+ lwM2MClient.getPendingRequests().addAll(clientInstances);
|
|
292
|
+ // #2
|
|
293
|
+ clientInstances.forEach(path -> {
|
|
294
|
+ lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, GET_TYPE_OPER_READ, ContentFormat.TLV.getName(),
|
|
295
|
+ lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false);
|
|
296
|
+ });
|
|
297
|
+ } else {
|
|
298
|
+ // #1.2
|
|
299
|
+ this.onSentObserveToClient(lwServer, registration);
|
|
300
|
+ }
|
|
301
|
+
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ // get all instances in client
|
|
305
|
+ private Set<String> getAllInstancesInClient(Registration registration) {
|
291
|
306
|
Set<String> clientInstances = ConcurrentHashMap.newKeySet();
|
292
|
307
|
Arrays.stream(registration.getObjectLinks()).forEach(url -> {
|
293
|
308
|
LwM2mPath pathIds = new LwM2mPath(url.getUrl());
|
...
|
...
|
@@ -295,27 +310,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
295
|
310
|
clientInstances.add(url.getUrl());
|
296
|
311
|
}
|
297
|
312
|
});
|
298
|
|
- if (this.context.getCtxServer().isClientUpdateValueAfterConnect()) {
|
299
|
|
- lwM2MClient.getPendingRequests().addAll(clientInstances);
|
300
|
|
- } else {
|
301
|
|
- // #1.2
|
302
|
|
- UUID profileUUid = lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getProfileUuid();
|
303
|
|
- JsonArray observeValue = lwM2mInMemorySecurityStore.getProfiles().get(profileUUid).getPostObserveProfile();
|
304
|
|
- observeValue.forEach(path -> {
|
305
|
|
- String[] resPath = path.getAsString().split("/");
|
306
|
|
- String instance = "/" + resPath[1] + "/" + resPath[2];
|
307
|
|
- if (clientInstances.contains(instance)) {
|
308
|
|
- lwM2MClient.getPendingRequests().add(path.getAsString());
|
309
|
|
- }
|
310
|
|
- }
|
311
|
|
- );
|
312
|
|
- }
|
313
|
|
-
|
314
|
|
- // #2
|
315
|
|
- lwM2MClient.getPendingRequests().forEach(path -> {
|
316
|
|
- lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, GET_TYPE_OPER_READ, ContentFormat.TLV.getName(),
|
317
|
|
- lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false);
|
318
|
|
- });
|
|
313
|
+ return (clientInstances.size() > 0) ? clientInstances : null;
|
319
|
314
|
}
|
320
|
315
|
|
321
|
316
|
/**
|
...
|
...
|
@@ -463,7 +458,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
463
|
458
|
* @return ArrayList keyNames from profile attr resources shared!!!! && IsWritable
|
464
|
459
|
*/
|
465
|
460
|
private List<String> getNamesAttrFromProfileIsWritable(LwM2MClient lwM2MClient) {
|
466
|
|
- AttrTelemetryObserveValue profile = lwM2mInMemorySecurityStore.getProfile(lwM2MClient.getProfileUuid());
|
|
461
|
+ LwM2MClientProfile profile = lwM2mInMemorySecurityStore.getProfile(lwM2MClient.getProfileUuid());
|
467
|
462
|
Set attrSet = new Gson().fromJson(profile.getPostAttributeProfile(), Set.class);
|
468
|
463
|
ConcurrentMap<String, String> keyNamesMap = new Gson().fromJson(profile.getPostKeyNameProfile().toString(), ConcurrentHashMap.class);
|
469
|
464
|
|
...
|
...
|
@@ -484,7 +479,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
484
|
479
|
* #1 - get AttrName/TelemetryName with value:
|
485
|
480
|
* #1.1 from Client
|
486
|
481
|
* #1.2 from LwM2MClient:
|
487
|
|
- * -- resourceId == path from AttrTelemetryObserveValue.postAttributeProfile/postTelemetryProfile/postObserveProfile
|
|
482
|
+ * -- resourceId == path from LwM2MClientProfile.postAttributeProfile/postTelemetryProfile/postObserveProfile
|
488
|
483
|
* -- AttrName/TelemetryName == resourceName from ModelObject.objectModel, value from ModelObject.instance.resource(resourceId)
|
489
|
484
|
* #2 - set Attribute/Telemetry
|
490
|
485
|
*
|
...
|
...
|
@@ -539,8 +534,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
539
|
534
|
* (attributes/telemetry): new {name(Attr/Telemetry):value}
|
540
|
535
|
*/
|
541
|
536
|
private void getParametersFromProfile(JsonObject attributes, JsonObject telemetry, Registration registration, Set<String> path) {
|
542
|
|
- AttrTelemetryObserveValue attrTelemetryObserveValue = lwM2mInMemorySecurityStore.getProfiles().get(lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getProfileUuid());
|
543
|
|
- attrTelemetryObserveValue.getPostAttributeProfile().forEach(p -> {
|
|
537
|
+ LwM2MClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore.getProfiles().get(lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getProfileUuid());
|
|
538
|
+ lwM2MClientProfile.getPostAttributeProfile().forEach(p -> {
|
544
|
539
|
LwM2mPath pathIds = new LwM2mPath(p.getAsString().toString());
|
545
|
540
|
if (pathIds.isResource()) {
|
546
|
541
|
if (path == null || path.contains(p.getAsString())) {
|
...
|
...
|
@@ -548,7 +543,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
548
|
543
|
}
|
549
|
544
|
}
|
550
|
545
|
});
|
551
|
|
- attrTelemetryObserveValue.getPostTelemetryProfile().forEach(p -> {
|
|
546
|
+ lwM2MClientProfile.getPostTelemetryProfile().forEach(p -> {
|
552
|
547
|
LwM2mPath pathIds = new LwM2mPath(p.getAsString().toString());
|
553
|
548
|
if (pathIds.isResource()) {
|
554
|
549
|
if (path == null || path.contains(p.getAsString())) {
|
...
|
...
|
@@ -609,20 +604,20 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
609
|
604
|
if (lwServer.getObservationService().getObservations(registration).size() > 0) {
|
610
|
605
|
this.setCancelObservations(lwServer, registration);
|
611
|
606
|
}
|
612
|
|
- UUID profileUUid = lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getProfileUuid();
|
613
|
|
- AttrTelemetryObserveValue attrTelemetryObserveValue = lwM2mInMemorySecurityStore.getProfiles().get(profileUUid);
|
614
|
|
- attrTelemetryObserveValue.getPostObserveProfile().forEach(p -> {
|
|
607
|
+ LwM2MClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore.getProfile(registration.getId());
|
|
608
|
+ Set<String> clientInstances = this.getAllInstancesInClient(registration);
|
|
609
|
+ lwM2MClientProfile.getPostObserveProfile().forEach(p -> {
|
615
|
610
|
// #1.1
|
616
|
|
- String target = (getValidateObserve(attrTelemetryObserveValue.getPostAttributeProfile(), p.getAsString().toString())) ?
|
617
|
|
- p.getAsString().toString() : (getValidateObserve(attrTelemetryObserveValue.getPostTelemetryProfile(), p.getAsString().toString())) ?
|
618
|
|
- p.getAsString().toString() : null;
|
619
|
|
- if (target != null) {
|
|
611
|
+ String target = p.getAsString().toString();
|
|
612
|
+ String[] resPath = target.split("/");
|
|
613
|
+ String instance = "/" + resPath[1] + "/" + resPath[2];
|
|
614
|
+ if (clientInstances.contains(instance)) {
|
620
|
615
|
// #2
|
621
|
|
- if (this.getResourceValueToString(lwM2mInMemorySecurityStore.getSessions().get(registration.getId()), target) != null) {
|
622
|
|
- lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, GET_TYPE_OPER_OBSERVE,
|
623
|
|
- null, null, null, null, this.context.getCtxServer().getTimeout(),
|
624
|
|
- false);
|
625
|
|
- }
|
|
616
|
+// if (this.getResourceValueToString(lwM2mInMemorySecurityStore.getSessions().get(registration.getId()), target) != null) {
|
|
617
|
+ lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, GET_TYPE_OPER_OBSERVE,
|
|
618
|
+ null, null, null, null, this.context.getCtxServer().getTimeout(),
|
|
619
|
+ false);
|
|
620
|
+// }
|
626
|
621
|
}
|
627
|
622
|
});
|
628
|
623
|
}
|
...
|
...
|
@@ -648,19 +643,19 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
648
|
643
|
* @param path - recourse from postObserveProfile
|
649
|
644
|
* @return rez - true if path observe is in attribute/telemetry
|
650
|
645
|
*/
|
651
|
|
- private boolean getValidateObserve(JsonElement parameters, String path) {
|
652
|
|
- AtomicBoolean rez = new AtomicBoolean(false);
|
653
|
|
- if (parameters.isJsonArray()) {
|
654
|
|
- parameters.getAsJsonArray().forEach(p -> {
|
655
|
|
- if (p.getAsString().toString().equals(path)) rez.set(true);
|
656
|
|
- }
|
657
|
|
- );
|
658
|
|
- } else if (parameters.isJsonObject()) {
|
659
|
|
- rez.set((parameters.getAsJsonObject().entrySet()).stream().map(json -> json.toString())
|
660
|
|
- .filter(path::equals).findAny().orElse(null) != null);
|
661
|
|
- }
|
662
|
|
- return rez.get();
|
663
|
|
- }
|
|
646
|
+// private boolean getValidateObserve(JsonElement parameters, String path) {
|
|
647
|
+// AtomicBoolean rez = new AtomicBoolean(false);
|
|
648
|
+// if (parameters.isJsonArray()) {
|
|
649
|
+// parameters.getAsJsonArray().forEach(p -> {
|
|
650
|
+// if (p.getAsString().toString().equals(path)) rez.set(true);
|
|
651
|
+// }
|
|
652
|
+// );
|
|
653
|
+// } else if (parameters.isJsonObject()) {
|
|
654
|
+// rez.set((parameters.getAsJsonObject().entrySet()).stream().map(json -> json.toString())
|
|
655
|
+// .filter(path::equals).findAny().orElse(null) != null);
|
|
656
|
+// }
|
|
657
|
+// return rez.get();
|
|
658
|
+// }
|
664
|
659
|
|
665
|
660
|
/**
|
666
|
661
|
* Sending observe value to thingsboard from ObservationListener.onResponse: object, instance, SingleResource or MultipleResource
|
...
|
...
|
@@ -673,15 +668,15 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
673
|
668
|
public void onObservationResponse(Registration registration, String path, ReadResponse response) {
|
674
|
669
|
if (response.getContent() != null) {
|
675
|
670
|
if (response.getContent() instanceof LwM2mObject) {
|
676
|
|
-// LwM2mObject content = (LwM2mObject) response.getContent();
|
|
671
|
+ LwM2mObject lwM2mObject = (LwM2mObject) response.getContent();
|
677
|
672
|
} else if (response.getContent() instanceof LwM2mObjectInstance) {
|
678
|
|
-// LwM2mObjectInstance content = (LwM2mObjectInstance) response.getContent();
|
679
|
|
- } else if (response.getContent() instanceof LwM2mSingleResource) {
|
680
|
|
- LwM2mSingleResource content = (LwM2mSingleResource) response.getContent();
|
681
|
|
- this.onObservationSetResourcesValue(registration, content.getValue(), null, path);
|
682
|
|
- } else if (response.getContent() instanceof LwM2mMultipleResource) {
|
683
|
|
- LwM2mMultipleResource content = (LwM2mMultipleResource) response.getContent();
|
684
|
|
- this.onObservationSetResourcesValue(registration, null, content.getValues(), path);
|
|
673
|
+ LwM2mObjectInstance lwM2mObjectInstance = (LwM2mObjectInstance) response.getContent();
|
|
674
|
+ } else if (response.getContent() instanceof LwM2mResource) {
|
|
675
|
+ LwM2mResource lwM2mResource = (LwM2mResource) response.getContent();
|
|
676
|
+ this.onObservationSetResourcesValue(registration, lwM2mResource, path);
|
|
677
|
+// } else if (response.getContent() instanceof LwM2mMultipleResource) {
|
|
678
|
+// LwM2mMultipleResource resource = (LwM2mMultipleResource) response.getContent();
|
|
679
|
+// this.onObservationSetResourcesValue(registration, null, resource.getValues(), path);
|
685
|
680
|
}
|
686
|
681
|
}
|
687
|
682
|
}
|
...
|
...
|
@@ -692,39 +687,17 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
692
|
687
|
* #2 Update new Resources (replace old Resource Value on new Resource Value)
|
693
|
688
|
*
|
694
|
689
|
* @param registration - Registration LwM2M Client
|
695
|
|
- * @param value - LwM2mSingleResource response.getContent()
|
696
|
|
- * @param values - LwM2mSingleResource response.getContent()
|
|
690
|
+ * @param - LwM2mSingleResource response.getContent()
|
|
691
|
+ * @param - LwM2mSingleResource response.getContent()
|
697
|
692
|
* @param path - resource
|
698
|
693
|
*/
|
699
|
|
- private void onObservationSetResourcesValue(Registration registration, Object value, Map<Integer, ?> values, String path) {
|
700
|
|
- boolean isChange = false;
|
701
|
|
- try {
|
702
|
|
- writeLock.lock();
|
703
|
|
- // #1
|
704
|
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null);
|
705
|
|
- LwM2mPath pathIds = new LwM2mPath(path);
|
706
|
|
- ResourceModel.Type resModelType = context.getCtxServer().getResourceModelType(registration, pathIds);
|
707
|
|
- ResourceValue resValueOld = lwM2MClient.getResources().get(path);
|
708
|
|
- // #2
|
709
|
|
- if (resValueOld.isMultiInstances() && !values.toString().equals(resValueOld.getResourceValue().toString())) {
|
710
|
|
- lwM2MClient.getResources().get(path).setValues(values);
|
711
|
|
- isChange = true;
|
712
|
|
- } else if (!LwM2MTransportHandler.equalsResourceValue(resValueOld.getValue(), value, resModelType, pathIds)) {
|
713
|
|
- lwM2MClient.getResources().get(path).setValue(value);
|
714
|
|
- log.warn("upDateResize: [{}] [{}] [{}] [{}]", lwM2MClient.getEndPoint(), lwM2MClient.getResources().size(), value, path);
|
715
|
|
- isChange = true;
|
716
|
|
- }
|
717
|
|
- } catch (Exception e) {
|
718
|
|
- log.error("#1_1 Update ResourcesValue after Observation is unsuccessfully path: [{}] value: [{}] [{}]", path, value, e.toString());
|
719
|
|
- } finally {
|
720
|
|
- writeLock.unlock();
|
721
|
|
- }
|
722
|
|
-
|
723
|
|
- if (isChange) {
|
724
|
|
- Set<String> paths = new HashSet<>();
|
725
|
|
- paths.add(path);
|
726
|
|
- this.updateAttrTelemetry(registration, false, paths);
|
727
|
|
- }
|
|
694
|
+ private void onObservationSetResourcesValue(Registration registration, LwM2mResource lwM2mResource, String path) {
|
|
695
|
+ LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null);
|
|
696
|
+ lwM2MClient.updateResourceValue(path, lwM2mResource);
|
|
697
|
+ log.warn("upDateResize: [{}] [{}] [{}]", lwM2MClient.getEndPoint(), lwM2MClient.getResources().size(), path);
|
|
698
|
+ Set<String> paths = new HashSet<>();
|
|
699
|
+ paths.add(path);
|
|
700
|
+ this.updateAttrTelemetry(registration, false, paths);
|
728
|
701
|
}
|
729
|
702
|
|
730
|
703
|
/**
|
...
|
...
|
@@ -738,7 +711,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
738
|
711
|
/**
|
739
|
712
|
* Update - sent request in change value resources in Client
|
740
|
713
|
* Path to resources from profile equal keyName or from ModelObject equal name
|
741
|
|
- * Only for resources: isWritable && isPresent as attribute in profile -> AttrTelemetryObserveValue (format: CamelCase)
|
|
714
|
+ * Only for resources: isWritable && isPresent as attribute in profile -> LwM2MClientProfile (format: CamelCase)
|
742
|
715
|
* Delete - nothing *
|
743
|
716
|
*
|
744
|
717
|
* @param msg -
|
...
|
...
|
@@ -750,7 +723,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
750
|
723
|
String path = this.getPathAttributeUpdate(sessionInfo, de.getKey());
|
751
|
724
|
String value = de.getValue().getAsString();
|
752
|
725
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getSession(new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())).entrySet().iterator().next().getValue();
|
753
|
|
- AttrTelemetryObserveValue profile = lwM2mInMemorySecurityStore.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
|
726
|
+ LwM2MClientProfile profile = lwM2mInMemorySecurityStore.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
754
|
727
|
ResourceModel resourceModel = context.getCtxServer().getResourceModel(lwM2MClient.getRegistration(), new LwM2mPath(path));
|
755
|
728
|
if (!path.isEmpty() && (this.validatePathInAttrProfile(profile, path) || this.validatePathInTelemetryProfile(profile, path))) {
|
756
|
729
|
if (resourceModel != null && resourceModel.operations.isWritable()) {
|
...
|
...
|
@@ -775,7 +748,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
775
|
748
|
|
776
|
749
|
/**
|
777
|
750
|
* Get path to resource from profile equal keyName or from ModelObject equal name
|
778
|
|
- * Only for resource: isWritable && isPresent as attribute in profile -> AttrTelemetryObserveValue (format: CamelCase)
|
|
751
|
+ * Only for resource: isWritable && isPresent as attribute in profile -> LwM2MClientProfile (format: CamelCase)
|
779
|
752
|
*
|
780
|
753
|
* @param sessionInfo -
|
781
|
754
|
* @param name -
|
...
|
...
|
@@ -792,7 +765,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
792
|
765
|
* @param path -
|
793
|
766
|
* @return true if path isPresent in postAttributeProfile
|
794
|
767
|
*/
|
795
|
|
- private boolean validatePathInAttrProfile(AttrTelemetryObserveValue profile, String path) {
|
|
768
|
+ private boolean validatePathInAttrProfile(LwM2MClientProfile profile, String path) {
|
796
|
769
|
Set<String> attributesSet = new Gson().fromJson(profile.getPostAttributeProfile(), Set.class);
|
797
|
770
|
return attributesSet.stream().filter(p -> p.equals(path)).findFirst().isPresent();
|
798
|
771
|
}
|
...
|
...
|
@@ -802,7 +775,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
802
|
775
|
* @param path -
|
803
|
776
|
* @return true if path isPresent in postAttributeProfile
|
804
|
777
|
*/
|
805
|
|
- private boolean validatePathInTelemetryProfile(AttrTelemetryObserveValue profile, String path) {
|
|
778
|
+ private boolean validatePathInTelemetryProfile(LwM2MClientProfile profile, String path) {
|
806
|
779
|
Set<String> telemetriesSet = new Gson().fromJson(profile.getPostTelemetryProfile(), Set.class);
|
807
|
780
|
return telemetriesSet.stream().filter(p -> p.equals(path)).findFirst().isPresent();
|
808
|
781
|
}
|
...
|
...
|
@@ -816,7 +789,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
816
|
789
|
* @return -
|
817
|
790
|
*/
|
818
|
791
|
private String getPathAttributeUpdateProfile(TransportProtos.SessionInfoProto sessionInfo, String name) {
|
819
|
|
- AttrTelemetryObserveValue profile = lwM2mInMemorySecurityStore.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
|
792
|
+ LwM2MClientProfile profile = lwM2mInMemorySecurityStore.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
820
|
793
|
return profile.getPostKeyNameProfile().getAsJsonObject().entrySet().stream()
|
821
|
794
|
.filter(e -> e.getValue().getAsString().equals(name)).findFirst().map(Map.Entry::getKey)
|
822
|
795
|
.orElse("");
|
...
|
...
|
@@ -830,14 +803,16 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
830
|
803
|
* @param request -
|
831
|
804
|
*/
|
832
|
805
|
public void onAttributeUpdateOk(Registration registration, String path, WriteRequest request, boolean isDelayedUpdate) {
|
833
|
|
- ResourceModel resource = context.getCtxServer().getResourceModel(registration, new LwM2mPath(path));
|
834
|
|
- if (resource.multiple) {
|
835
|
|
- this.onObservationSetResourcesValue(registration, null, ((LwM2mSingleResource) request.getNode()).getValues(), path);
|
836
|
|
- } else {
|
837
|
|
- this.onObservationSetResourcesValue(registration, ((LwM2mSingleResource) request.getNode()).getValue(), null, path);
|
|
806
|
+// ResourceModel resource = context.getCtxServer().getResourceModel(registration, new LwM2mPath(path));
|
|
807
|
+// if (resource.multiple) {
|
|
808
|
+ this.onObservationSetResourcesValue(registration, ((LwM2mResource) request.getNode()), path);
|
|
809
|
+// } else {
|
|
810
|
+// this.onObservationSetResourcesValue(registration, ((LwM2mSingleResource) request.getNode()).getValue(), null, path);
|
|
811
|
+// }
|
|
812
|
+ if (isDelayedUpdate) {
|
|
813
|
+ lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null)
|
|
814
|
+ .onSuccessOrErrorDelayedRequests(request.getPath().toString());
|
838
|
815
|
}
|
839
|
|
- if (isDelayedUpdate) lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null)
|
840
|
|
- .onSuccessOrErrorDelayedRequests(request.getPath().toString());
|
841
|
816
|
}
|
842
|
817
|
|
843
|
818
|
/**
|
...
|
...
|
@@ -909,24 +884,24 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
909
|
884
|
*/
|
910
|
885
|
private void onDeviceUpdateChangeProfile(Set<String> registrationIds, DeviceProfile deviceProfile) {
|
911
|
886
|
|
912
|
|
- AttrTelemetryObserveValue attrTelemetryObserveValueOld = lwM2mInMemorySecurityStore.getProfiles().get(deviceProfile.getUuidId());
|
|
887
|
+ LwM2MClientProfile lwM2MClientProfileOld = lwM2mInMemorySecurityStore.getProfiles().get(deviceProfile.getUuidId());
|
913
|
888
|
if (lwM2mInMemorySecurityStore.addUpdateProfileParameters(deviceProfile)) {
|
914
|
889
|
|
915
|
890
|
// #1
|
916
|
|
- JsonArray attributeOld = attrTelemetryObserveValueOld.getPostAttributeProfile();
|
|
891
|
+ JsonArray attributeOld = lwM2MClientProfileOld.getPostAttributeProfile();
|
917
|
892
|
Set attributeSetOld = new Gson().fromJson(attributeOld, Set.class);
|
918
|
|
- JsonArray telemetryOld = attrTelemetryObserveValueOld.getPostTelemetryProfile();
|
|
893
|
+ JsonArray telemetryOld = lwM2MClientProfileOld.getPostTelemetryProfile();
|
919
|
894
|
Set telemetrySetOld = new Gson().fromJson(telemetryOld, Set.class);
|
920
|
|
- JsonArray observeOld = attrTelemetryObserveValueOld.getPostObserveProfile();
|
921
|
|
- JsonObject keyNameOld = attrTelemetryObserveValueOld.getPostKeyNameProfile();
|
|
895
|
+ JsonArray observeOld = lwM2MClientProfileOld.getPostObserveProfile();
|
|
896
|
+ JsonObject keyNameOld = lwM2MClientProfileOld.getPostKeyNameProfile();
|
922
|
897
|
|
923
|
|
- AttrTelemetryObserveValue attrTelemetryObserveValueNew = lwM2mInMemorySecurityStore.getProfiles().get(deviceProfile.getUuidId());
|
924
|
|
- JsonArray attributeNew = attrTelemetryObserveValueNew.getPostAttributeProfile();
|
|
898
|
+ LwM2MClientProfile lwM2MClientProfileNew = lwM2mInMemorySecurityStore.getProfiles().get(deviceProfile.getUuidId());
|
|
899
|
+ JsonArray attributeNew = lwM2MClientProfileNew.getPostAttributeProfile();
|
925
|
900
|
Set attributeSetNew = new Gson().fromJson(attributeNew, Set.class);
|
926
|
|
- JsonArray telemetryNew = attrTelemetryObserveValueNew.getPostTelemetryProfile();
|
|
901
|
+ JsonArray telemetryNew = lwM2MClientProfileNew.getPostTelemetryProfile();
|
927
|
902
|
Set telemetrySetNew = new Gson().fromJson(telemetryNew, Set.class);
|
928
|
|
- JsonArray observeNew = attrTelemetryObserveValueNew.getPostObserveProfile();
|
929
|
|
- JsonObject keyNameNew = attrTelemetryObserveValueNew.getPostKeyNameProfile();
|
|
903
|
+ JsonArray observeNew = lwM2MClientProfileNew.getPostObserveProfile();
|
|
904
|
+ JsonObject keyNameNew = lwM2MClientProfileNew.getPostKeyNameProfile();
|
930
|
905
|
|
931
|
906
|
// #3
|
932
|
907
|
ResultsAnalyzerParameters sentAttrToThingsboard = new ResultsAnalyzerParameters();
|
...
|
...
|
|