...
|
...
|
@@ -20,13 +20,11 @@ import com.google.gson.JsonArray; |
20
|
20
|
import com.google.gson.JsonElement;
|
21
|
21
|
import com.google.gson.JsonObject;
|
22
|
22
|
import lombok.extern.slf4j.Slf4j;
|
23
|
|
-import org.eclipse.leshan.core.model.ObjectModel;
|
24
|
23
|
import org.eclipse.leshan.core.model.ResourceModel;
|
25
|
24
|
import org.eclipse.leshan.core.node.LwM2mMultipleResource;
|
26
|
25
|
import org.eclipse.leshan.core.node.LwM2mObject;
|
27
|
26
|
import org.eclipse.leshan.core.node.LwM2mObjectInstance;
|
28
|
27
|
import org.eclipse.leshan.core.node.LwM2mPath;
|
29
|
|
-import org.eclipse.leshan.core.node.LwM2mResource;
|
30
|
28
|
import org.eclipse.leshan.core.node.LwM2mSingleResource;
|
31
|
29
|
import org.eclipse.leshan.core.observation.Observation;
|
32
|
30
|
import org.eclipse.leshan.core.request.ContentFormat;
|
...
|
...
|
@@ -51,7 +49,6 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportUpdateCre |
51
|
49
|
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCredentialsResponseMsg;
|
52
|
50
|
import org.thingsboard.server.transport.lwm2m.server.client.AttrTelemetryObserveValue;
|
53
|
51
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClient;
|
54
|
|
-import org.thingsboard.server.transport.lwm2m.server.client.ModelObject;
|
55
|
52
|
import org.thingsboard.server.transport.lwm2m.server.client.ResourceValue;
|
56
|
53
|
import org.thingsboard.server.transport.lwm2m.server.client.ResultsAnalyzerParameters;
|
57
|
54
|
import org.thingsboard.server.transport.lwm2m.server.secure.LwM2mInMemorySecurityStore;
|
...
|
...
|
@@ -62,9 +59,9 @@ import java.util.ArrayList; |
62
|
59
|
import java.util.Arrays;
|
63
|
60
|
import java.util.Collection;
|
64
|
61
|
import java.util.HashSet;
|
|
62
|
+import java.util.LinkedHashSet;
|
65
|
63
|
import java.util.List;
|
66
|
64
|
import java.util.Map;
|
67
|
|
-import java.util.NoSuchElementException;
|
68
|
65
|
import java.util.Optional;
|
69
|
66
|
import java.util.Random;
|
70
|
67
|
import java.util.Set;
|
...
|
...
|
@@ -76,7 +73,6 @@ import java.util.concurrent.ExecutorService; |
76
|
73
|
import java.util.concurrent.Executors;
|
77
|
74
|
import java.util.concurrent.TimeUnit;
|
78
|
75
|
import java.util.concurrent.atomic.AtomicBoolean;
|
79
|
|
-import java.util.function.Predicate;
|
80
|
76
|
import java.util.stream.Collectors;
|
81
|
77
|
|
82
|
78
|
import static org.thingsboard.server.common.transport.util.JsonUtils.getJsonObject;
|
...
|
...
|
@@ -148,13 +144,14 @@ public class LwM2MTransportService { |
148
|
144
|
public void onRegistered(LeshanServer lwServer, Registration registration, Collection<Observation> previousObsersations) {
|
149
|
145
|
executorRegistered.submit(() -> {
|
150
|
146
|
try {
|
151
|
|
- log.info("[{}] Client: onRegistered name ", registration.getEndpoint());
|
|
147
|
+ log.info("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId());
|
152
|
148
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.updateInSessionsLwM2MClient(lwServer, registration);
|
153
|
149
|
if (lwM2MClient != null) {
|
154
|
150
|
lwM2MClient.setLwM2MTransportService(this);
|
155
|
151
|
lwM2MClient.setSessionUuid(UUID.randomUUID());
|
|
152
|
+ this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration);
|
156
|
153
|
this.setLwM2MClient(lwServer, registration, lwM2MClient);
|
157
|
|
- SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration.getId());
|
|
154
|
+ SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
158
|
155
|
if (sessionInfo != null) {
|
159
|
156
|
lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
|
160
|
157
|
lwM2MClient.setProfileUuid(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
...
|
...
|
@@ -163,7 +160,7 @@ public class LwM2MTransportService { |
163
|
160
|
transportService.registerAsyncSession(sessionInfo, new LwM2MSessionMsgListener(this, sessionInfo));
|
164
|
161
|
transportService.process(sessionInfo, DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN), null);
|
165
|
162
|
transportService.process(sessionInfo, TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build(), null);
|
166
|
|
- this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client registration", registration.getId());
|
|
163
|
+ this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration);
|
167
|
164
|
} else {
|
168
|
165
|
log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
|
169
|
166
|
}
|
...
|
...
|
@@ -184,7 +181,7 @@ public class LwM2MTransportService { |
184
|
181
|
public void updatedReg(LeshanServer lwServer, Registration registration) {
|
185
|
182
|
executorUpdateRegistered.submit(() -> {
|
186
|
183
|
try {
|
187
|
|
- SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration.getId());
|
|
184
|
+ SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
188
|
185
|
if (sessionInfo != null) {
|
189
|
186
|
this.checkInactivity(sessionInfo);
|
190
|
187
|
log.info("Client: [{}] updatedReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType());
|
...
|
...
|
@@ -206,7 +203,7 @@ public class LwM2MTransportService { |
206
|
203
|
public void unReg(Registration registration, Collection<Observation> observations) {
|
207
|
204
|
executorUnRegistered.submit(() -> {
|
208
|
205
|
try {
|
209
|
|
- this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration.getId());
|
|
206
|
+ this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration);
|
210
|
207
|
this.closeClientSession(registration);
|
211
|
208
|
} catch (Throwable t) {
|
212
|
209
|
log.error("[{}] endpoint [{}] error Unable un registration.", registration.getEndpoint(), t);
|
...
|
...
|
@@ -215,7 +212,7 @@ public class LwM2MTransportService { |
215
|
212
|
}
|
216
|
213
|
|
217
|
214
|
private void closeClientSession(Registration registration) {
|
218
|
|
- SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration.getId());
|
|
215
|
+ SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
219
|
216
|
if (sessionInfo != null) {
|
220
|
217
|
transportService.deregisterSession(sessionInfo);
|
221
|
218
|
this.doCloseSession(sessionInfo);
|
...
|
...
|
@@ -278,9 +275,6 @@ public class LwM2MTransportService { |
278
|
275
|
* @param lwM2MClient - object with All parameters off client
|
279
|
276
|
*/
|
280
|
277
|
private void setLwM2MClient(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient) {
|
281
|
|
- // #0
|
282
|
|
- this.setNewObjectModels(lwServer, registration);
|
283
|
|
- // #1
|
284
|
278
|
Arrays.stream(registration.getObjectLinks()).forEach(url -> {
|
285
|
279
|
LwM2mPath pathIds = new LwM2mPath(url.getUrl());
|
286
|
280
|
if (pathIds.isObjectInstance() && !pathIds.isResource()) {
|
...
|
...
|
@@ -297,30 +291,35 @@ public class LwM2MTransportService { |
297
|
291
|
});
|
298
|
292
|
}
|
299
|
293
|
|
300
|
|
- private void setNewObjectModels(LeshanServer lwServer, Registration registration) {
|
301
|
|
- Arrays.stream(registration.getObjectLinks()).forEach(url -> {
|
302
|
|
- LwM2mPath pathIds = new LwM2mPath(url.getUrl());
|
303
|
|
- if (pathIds.isObjectInstance() && !pathIds.isResource() && !context.getCtxServer().getObjectModels().containsKey(pathIds.getObjectId())) {
|
304
|
|
- ObjectModel model = lwServer.getModelProvider().getObjectModel(registration).getObjectModels().stream().filter(v -> v.id == pathIds.getObjectId()).collect(Collectors.toList()).get(0);
|
305
|
|
- context.getCtxServer().getObjectModels().put(pathIds.getObjectId(), model);
|
306
|
|
- }
|
307
|
|
- });
|
|
294
|
+ /**
|
|
295
|
+ * @param registration - Registration LwM2M Client
|
|
296
|
+ * @return - sessionInfo after access connect client
|
|
297
|
+ */
|
|
298
|
+ private SessionInfoProto getValidateSessionInfo(Registration registration) {
|
|
299
|
+ LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null);
|
|
300
|
+ return getNewSessionInfoProto(lwM2MClient);
|
|
301
|
+
|
308
|
302
|
}
|
309
|
303
|
|
310
|
304
|
/**
|
311
|
|
- * @param registrationId - Id of Registration LwM2M Client
|
312
|
|
- * @return - sessionInfo after access connect client
|
|
305
|
+ *
|
|
306
|
+ * @param registrationId -
|
|
307
|
+ * @return -
|
313
|
308
|
*/
|
314
|
309
|
private SessionInfoProto getValidateSessionInfo(String registrationId) {
|
315
|
|
- SessionInfoProto sessionInfo = null;
|
316
|
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(registrationId);
|
|
310
|
+ LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(null, registrationId);
|
|
311
|
+ return getNewSessionInfoProto(lwM2MClient);
|
|
312
|
+ }
|
|
313
|
+
|
|
314
|
+ private SessionInfoProto getNewSessionInfoProto(LwM2MClient lwM2MClient) {
|
317
|
315
|
if (lwM2MClient != null) {
|
318
|
316
|
ValidateDeviceCredentialsResponseMsg msg = lwM2MClient.getCredentialsResponse();
|
319
|
317
|
if (msg == null || msg.getDeviceInfo() == null) {
|
320
|
318
|
log.error("[{}] [{}]", lwM2MClient.getEndPoint(), CLIENT_NOT_AUTHORIZED);
|
321
|
319
|
this.closeClientSession(lwM2MClient.getRegistration());
|
|
320
|
+ return null;
|
322
|
321
|
} else {
|
323
|
|
- sessionInfo = SessionInfoProto.newBuilder()
|
|
322
|
+ return SessionInfoProto.newBuilder()
|
324
|
323
|
.setNodeId(this.context.getNodeId())
|
325
|
324
|
.setSessionIdMSB(lwM2MClient.getSessionUuid().getMostSignificantBits())
|
326
|
325
|
.setSessionIdLSB(lwM2MClient.getSessionUuid().getLeastSignificantBits())
|
...
|
...
|
@@ -335,7 +334,7 @@ public class LwM2MTransportService { |
335
|
334
|
.build();
|
336
|
335
|
}
|
337
|
336
|
}
|
338
|
|
- return sessionInfo;
|
|
337
|
+ return null;
|
339
|
338
|
}
|
340
|
339
|
|
341
|
340
|
/**
|
...
|
...
|
@@ -365,7 +364,7 @@ public class LwM2MTransportService { |
365
|
364
|
* @param lwM2MClient - LwM2M Client
|
366
|
365
|
*/
|
367
|
366
|
public void putDelayedUpdateResourcesThingsboard(LwM2MClient lwM2MClient) {
|
368
|
|
- SessionInfoProto sessionInfo = this.getValidateSessionInfo(lwM2MClient.getRegistration().getId());
|
|
367
|
+ SessionInfoProto sessionInfo = this.getValidateSessionInfo(lwM2MClient.getRegistration());
|
369
|
368
|
if (sessionInfo != null) {
|
370
|
369
|
//#1.1 + #1.2
|
371
|
370
|
List<String> attrSharedNames = this.getNamesAttrFromProfileIsWritable(lwM2MClient);
|
...
|
...
|
@@ -404,7 +403,7 @@ public class LwM2MTransportService { |
404
|
403
|
attributesResponse.getSharedAttributeListList().forEach(attr -> {
|
405
|
404
|
String path = this.getPathAttributeUpdate(sessionInfo, attr.getKv().getKey());
|
406
|
405
|
// #1.1
|
407
|
|
- if (lwM2MClient.getDelayedRequests().keySet().contains(path) && attr.getTs() > lwM2MClient.getDelayedRequests().get(path).getTs()) {
|
|
406
|
+ if (lwM2MClient.getDelayedRequests().containsKey(path) && attr.getTs() > lwM2MClient.getDelayedRequests().get(path).getTs()) {
|
408
|
407
|
lwM2MClient.getDelayedRequests().put(path, attr);
|
409
|
408
|
} else {
|
410
|
409
|
lwM2MClient.getDelayedRequests().put(path, attr);
|
...
|
...
|
@@ -412,7 +411,7 @@ public class LwM2MTransportService { |
412
|
411
|
});
|
413
|
412
|
// #2.1
|
414
|
413
|
lwM2MClient.getDelayedRequests().forEach((k, v) -> {
|
415
|
|
- List listV = new ArrayList<TransportProtos.KeyValueProto>();
|
|
414
|
+ ArrayList<TransportProtos.KeyValueProto> listV = new ArrayList<>();
|
416
|
415
|
listV.add(v.getKv());
|
417
|
416
|
this.putDelayedUpdateResourcesClient(lwM2MClient, this.getResourceValueToString(lwM2MClient, k), getJsonObject(listV).get(v.getKv().getKey()), k);
|
418
|
417
|
});
|
...
|
...
|
@@ -432,24 +431,24 @@ public class LwM2MTransportService { |
432
|
431
|
}
|
433
|
432
|
|
434
|
433
|
/**
|
435
|
|
- * Get names and keyNames from profile attr resources IsWritable
|
436
|
|
- *
|
|
434
|
+ * Get names and keyNames from profile shared!!!! attr resources IsWritable
|
437
|
435
|
* @param lwM2MClient -
|
438
|
|
- * @return ArrayList names and keyNames from profile attr resources IsWritable
|
|
436
|
+ * @return ArrayList keyNames from profile attr resources shared!!!! && IsWritable
|
439
|
437
|
*/
|
440
|
438
|
private List<String> getNamesAttrFromProfileIsWritable(LwM2MClient lwM2MClient) {
|
441
|
|
- Set<String> namesIsIsWritable = ConcurrentHashMap.newKeySet();
|
442
|
439
|
AttrTelemetryObserveValue profile = lwM2mInMemorySecurityStore.getProfile(lwM2MClient.getProfileUuid());
|
443
|
440
|
Set attrSet = new Gson().fromJson(profile.getPostAttributeProfile(), Set.class);
|
444
|
441
|
ConcurrentMap<String, String> keyNamesMap = new Gson().fromJson(profile.getPostKeyNameProfile().toString(), ConcurrentHashMap.class);
|
|
442
|
+
|
445
|
443
|
ConcurrentMap<String, String> keyNamesIsWritable = keyNamesMap.entrySet()
|
446
|
444
|
.stream()
|
447
|
|
- .filter(e -> (attrSet.contains(e.getKey()) && context.getCtxServer().getResourceModel(new LwM2mPath(e.getKey())) != null &&
|
448
|
|
- context.getCtxServer().getResourceModel(new LwM2mPath(e.getKey())).operations.isWritable()))
|
|
445
|
+ .filter(e -> (attrSet.contains(e.getKey()) && context.getCtxServer().getResourceModel(lwM2MClient.getRegistration(), new LwM2mPath(e.getKey())) != null &&
|
|
446
|
+ context.getCtxServer().getResourceModel(lwM2MClient.getRegistration(), new LwM2mPath(e.getKey())).operations.isWritable()))
|
449
|
447
|
.collect(Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue));
|
450
|
|
- namesIsIsWritable.addAll(new HashSet<>(keyNamesIsWritable.values()));
|
451
|
|
- keyNamesIsWritable.keySet().forEach(p -> namesIsIsWritable.add(this.getResourceName(p)));
|
452
|
|
- return new ArrayList<>(namesIsIsWritable);
|
|
448
|
+
|
|
449
|
+ Set<String> namesIsWritable = ConcurrentHashMap.newKeySet();
|
|
450
|
+ namesIsWritable.addAll(new HashSet<>(keyNamesIsWritable.values()));
|
|
451
|
+ return new ArrayList<>(namesIsWritable);
|
453
|
452
|
}
|
454
|
453
|
|
455
|
454
|
|
...
|
...
|
@@ -484,9 +483,9 @@ public class LwM2MTransportService { |
484
|
483
|
log.error("[{}] updateAttrTelemetry", e.toString());
|
485
|
484
|
}
|
486
|
485
|
if (attributes.getAsJsonObject().entrySet().size() > 0)
|
487
|
|
- this.updateParametersOnThingsboard(attributes, DEVICE_ATTRIBUTES_TOPIC, registration.getId());
|
|
486
|
+ this.updateParametersOnThingsboard(attributes, DEVICE_ATTRIBUTES_TOPIC, registration);
|
488
|
487
|
if (telemetries.getAsJsonObject().entrySet().size() > 0)
|
489
|
|
- this.updateParametersOnThingsboard(telemetries, DEVICE_TELEMETRY_TOPIC, registration.getId());
|
|
488
|
+ this.updateParametersOnThingsboard(telemetries, DEVICE_TELEMETRY_TOPIC, registration);
|
490
|
489
|
}
|
491
|
490
|
|
492
|
491
|
/**
|
...
|
...
|
@@ -541,9 +540,8 @@ public class LwM2MTransportService { |
541
|
540
|
JsonObject names = lwM2mInMemorySecurityStore.getProfiles().get(lwM2MClient.getProfileUuid()).getPostKeyNameProfile();
|
542
|
541
|
String resName = String.valueOf(names.get(path));
|
543
|
542
|
if (resName != null && !resName.isEmpty()) {
|
544
|
|
- String resValue = null;
|
545
|
543
|
try {
|
546
|
|
- resValue = this.getResourceValueToString(lwM2MClient, path);
|
|
544
|
+ String resValue = this.getResourceValueToString(lwM2MClient, path);
|
547
|
545
|
if (resValue != null) {
|
548
|
546
|
parameters.addProperty(resName, resValue);
|
549
|
547
|
}
|
...
|
...
|
@@ -558,14 +556,14 @@ public class LwM2MTransportService { |
558
|
556
|
*
|
559
|
557
|
* @param msg - JsonArray: [{name: value}]
|
560
|
558
|
* @param topicName - Api Attribute or Telemetry
|
561
|
|
- * @param registrationId - Id of Registration LwM2M Client
|
|
559
|
+ * @param registration - Id of Registration LwM2M Client
|
562
|
560
|
*/
|
563
|
|
- public void updateParametersOnThingsboard(JsonElement msg, String topicName, String registrationId) {
|
564
|
|
- SessionInfoProto sessionInfo = this.getValidateSessionInfo(registrationId);
|
|
561
|
+ public void updateParametersOnThingsboard(JsonElement msg, String topicName, Registration registration) {
|
|
562
|
+ SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
565
|
563
|
if (sessionInfo != null) {
|
566
|
564
|
context.sentParametersOnThingsboard(msg, topicName, sessionInfo);
|
567
|
565
|
} else {
|
568
|
|
- log.error("Client: [{}] updateParametersOnThingsboard [{}] sessionInfo ", registrationId, null);
|
|
566
|
+ log.error("Client: [{}] updateParametersOnThingsboard [{}] sessionInfo ", registration, null);
|
569
|
567
|
}
|
570
|
568
|
}
|
571
|
569
|
|
...
|
...
|
@@ -655,10 +653,9 @@ public class LwM2MTransportService { |
655
|
653
|
public void onObservationResponse(Registration registration, String path, ReadResponse response) {
|
656
|
654
|
if (response.getContent() != null) {
|
657
|
655
|
if (response.getContent() instanceof LwM2mObject) {
|
658
|
|
- LwM2mObject content = (LwM2mObject) response.getContent();
|
659
|
|
- String target = "/" + content.getId();
|
|
656
|
+// LwM2mObject content = (LwM2mObject) response.getContent();
|
660
|
657
|
} else if (response.getContent() instanceof LwM2mObjectInstance) {
|
661
|
|
- LwM2mObjectInstance content = (LwM2mObjectInstance) response.getContent();
|
|
658
|
+// LwM2mObjectInstance content = (LwM2mObjectInstance) response.getContent();
|
662
|
659
|
} else if (response.getContent() instanceof LwM2mSingleResource) {
|
663
|
660
|
LwM2mSingleResource content = (LwM2mSingleResource) response.getContent();
|
664
|
661
|
this.onObservationSetResourcesValue(registration, content.getValue(), null, path);
|
...
|
...
|
@@ -684,10 +681,10 @@ public class LwM2MTransportService { |
684
|
681
|
boolean isChange = false;
|
685
|
682
|
try {
|
686
|
683
|
// #1
|
687
|
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(registration.getId());
|
|
684
|
+ LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null);
|
688
|
685
|
LwM2mPath pathIds = new LwM2mPath(path);
|
689
|
686
|
log.warn("#0 nameDevice: [{}] resultIds: [{}] value: [{}], values: [{}] ", lwM2MClient.getDeviceName(), pathIds, value, values);
|
690
|
|
- ResourceModel.Type resModelType = context.getCtxServer().getResourceModelType(pathIds);
|
|
687
|
+ ResourceModel.Type resModelType = context.getCtxServer().getResourceModelType(registration, pathIds);
|
691
|
688
|
ResourceValue resValueOld = lwM2MClient.getResources().get(path);
|
692
|
689
|
// #2
|
693
|
690
|
if (resValueOld.isMultiInstances() && !values.toString().equals(resValueOld.getResourceValue().toString())) {
|
...
|
...
|
@@ -739,8 +736,8 @@ public class LwM2MTransportService { |
739
|
736
|
String value = de.getValue().getAsString();
|
740
|
737
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getSession(new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())).entrySet().iterator().next().getValue();
|
741
|
738
|
AttrTelemetryObserveValue profile = lwM2mInMemorySecurityStore.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
742
|
|
- ResourceModel resourceModel = context.getCtxServer().getResourceModel(new LwM2mPath(path));
|
743
|
|
- if (path != null && (this.validatePathInAttrProfile(profile, path) || this.validatePathInTelemetryProfile(profile, path))) {
|
|
739
|
+ ResourceModel resourceModel = context.getCtxServer().getResourceModel(lwM2MClient.getRegistration(), new LwM2mPath(path));
|
|
740
|
+ if (!path.isEmpty() && (this.validatePathInAttrProfile(profile, path) || this.validatePathInTelemetryProfile(profile, path))) {
|
744
|
741
|
if (resourceModel != null && resourceModel.operations.isWritable()) {
|
745
|
742
|
lwM2MTransportRequest.sendAllRequest(lwM2MClient.getLwServer(), lwM2MClient.getRegistration(), path, POST_TYPE_OPER_WRITE_REPLACE,
|
746
|
743
|
ContentFormat.TLV.getName(), lwM2MClient, null, value, this.context.getCtxServer().getTimeout(),
|
...
|
...
|
@@ -748,12 +745,12 @@ public class LwM2MTransportService { |
748
|
745
|
} else {
|
749
|
746
|
log.error("Resource path - [{}] value - [{}] is not Writable and cannot be updated", path, value);
|
750
|
747
|
String logMsg = String.format(LOG_LW2M_ERROR + ": attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated", path, value);
|
751
|
|
- this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId());
|
|
748
|
+ this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
|
752
|
749
|
}
|
753
|
750
|
} else {
|
754
|
751
|
log.error("Attribute name - [{}] value - [{}] is not present as attribute in profile and cannot be updated", de.getKey(), value);
|
755
|
752
|
String logMsg = String.format(LOG_LW2M_ERROR + ": attributeUpdate: attribute name - %s value - %s is not present as attribute in profile and cannot be updated", de.getKey(), value);
|
756
|
|
- this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId());
|
|
753
|
+ this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
|
757
|
754
|
}
|
758
|
755
|
});
|
759
|
756
|
} else if (msg.getSharedDeletedCount() > 0) {
|
...
|
...
|
@@ -767,11 +764,12 @@ public class LwM2MTransportService { |
767
|
764
|
*
|
768
|
765
|
* @param sessionInfo -
|
769
|
766
|
* @param name -
|
770
|
|
- * @return true if path isPresent in postProfile
|
|
767
|
+ * @return path if path isPresent in postProfile
|
771
|
768
|
*/
|
772
|
769
|
private String getPathAttributeUpdate(TransportProtos.SessionInfoProto sessionInfo, String name) {
|
773
|
770
|
String profilePath = this.getPathAttributeUpdateProfile(sessionInfo, name);
|
774
|
|
- return !profilePath.isEmpty() ? profilePath : this.getPathAttributeUpdateModelObject(sessionInfo, name);
|
|
771
|
+// return !profilePath.isEmpty() ? profilePath : this.getPathAttributeUpdateModelObject(name);
|
|
772
|
+ return !profilePath.isEmpty() ? profilePath : null;
|
775
|
773
|
}
|
776
|
774
|
|
777
|
775
|
/**
|
...
|
...
|
@@ -800,7 +798,7 @@ public class LwM2MTransportService { |
800
|
798
|
*
|
801
|
799
|
* @param sessionInfo -
|
802
|
800
|
* @param name -
|
803
|
|
- * @return
|
|
801
|
+ * @return -
|
804
|
802
|
*/
|
805
|
803
|
private String getPathAttributeUpdateProfile(TransportProtos.SessionInfoProto sessionInfo, String name) {
|
806
|
804
|
AttrTelemetryObserveValue profile = lwM2mInMemorySecurityStore.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
...
|
...
|
@@ -810,31 +808,6 @@ public class LwM2MTransportService { |
810
|
808
|
}
|
811
|
809
|
|
812
|
810
|
/**
|
813
|
|
- * Get path to resource from ModelObject equal name
|
814
|
|
- *
|
815
|
|
- * @param name -
|
816
|
|
- * @return true if name isPresent as Resource name (usual format) in ResourceModel
|
817
|
|
- */
|
818
|
|
- private String getPathAttributeUpdateModelObject(TransportProtos.SessionInfoProto sessionInfo, String name) {
|
819
|
|
- try {
|
820
|
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getSession(new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())).entrySet().iterator().next().getValue();
|
821
|
|
- Predicate<Map.Entry<Integer, ResourceModel>> predicateRes = res -> name.equals(res.getValue().name);
|
822
|
|
- Predicate<Map.Entry<Integer, ModelObject>> predicateObj = (obj -> {
|
823
|
|
- return obj.getValue().getObjectModel().resources.entrySet().stream().filter(predicateRes).findFirst().isPresent();
|
824
|
|
- });
|
825
|
|
-// Map.Entry<Integer, ModelObject> object = lwM2MClient.getModelObjects().entrySet().stream().filter(predicateObj).findFirst().get();
|
826
|
|
- Map.Entry<Integer, ModelObject> object = null;
|
827
|
|
- ModelObject modelObject = object.getValue();
|
828
|
|
- LwM2mObjectInstance instance = modelObject.getInstances().entrySet().stream().findFirst().get().getValue();
|
829
|
|
- ResourceModel resource = modelObject.getObjectModel().resources.entrySet().stream().filter(predicateRes).findFirst().get().getValue();
|
830
|
|
- return new LwM2mPath(object.getKey(), instance.getId(), resource.id).toString();
|
831
|
|
- } catch (NoSuchElementException e) {
|
832
|
|
- log.error("[{}] keyName [{}]", name, e.toString());
|
833
|
|
- return null;
|
834
|
|
- }
|
835
|
|
- }
|
836
|
|
-
|
837
|
|
- /**
|
838
|
811
|
* Update resource (attribute) value on thingsboard after update value in client
|
839
|
812
|
*
|
840
|
813
|
* @param registration -
|
...
|
...
|
@@ -842,17 +815,14 @@ public class LwM2MTransportService { |
842
|
815
|
* @param request -
|
843
|
816
|
*/
|
844
|
817
|
public void onAttributeUpdateOk(Registration registration, String path, WriteRequest request, boolean isDelayedUpdate) {
|
845
|
|
-// ResultIds resultIds = new ResultIds(path);
|
846
|
|
- LwM2mPath resultIds = new LwM2mPath(path);
|
847
|
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(registration.getId());
|
848
|
|
-// LwM2mResource resource = lwM2MClient.getModelObjects().get(resultIds.getObjectId()).getInstances().get(resultIds.getObjectInstanceId()).getResource(resultIds.getResourceId());
|
849
|
|
- LwM2mResource resource = null;
|
850
|
|
- if (resource.isMultiInstances()) {
|
|
818
|
+ ResourceModel resource = context.getCtxServer().getResourceModel(registration, new LwM2mPath(path));
|
|
819
|
+ if (resource.multiple) {
|
851
|
820
|
this.onObservationSetResourcesValue(registration, null, ((LwM2mSingleResource) request.getNode()).getValues(), path);
|
852
|
821
|
} else {
|
853
|
822
|
this.onObservationSetResourcesValue(registration, ((LwM2mSingleResource) request.getNode()).getValue(), null, path);
|
854
|
823
|
}
|
855
|
|
- if (isDelayedUpdate) lwM2MClient.onSuccessOrErrorDelayedRequests(request.getPath().toString());
|
|
824
|
+ if (isDelayedUpdate) lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null)
|
|
825
|
+ .onSuccessOrErrorDelayedRequests(request.getPath().toString());
|
856
|
826
|
}
|
857
|
827
|
|
858
|
828
|
/**
|
...
|
...
|
@@ -863,7 +833,7 @@ public class LwM2MTransportService { |
863
|
833
|
Set<String> registrationIds = lwM2mInMemorySecurityStore.getSessions().entrySet()
|
864
|
834
|
.stream()
|
865
|
835
|
.filter(e -> e.getValue().getProfileUuid().equals(deviceProfile.getUuidId()))
|
866
|
|
- .map(Map.Entry::getKey).sorted().collect(Collectors.toSet());
|
|
836
|
+ .map(Map.Entry::getKey).sorted().collect(Collectors.toCollection(LinkedHashSet::new));
|
867
|
837
|
if (registrationIds.size() > 0) {
|
868
|
838
|
this.onDeviceUpdateChangeProfile(registrationIds, deviceProfile);
|
869
|
839
|
}
|
...
|
...
|
@@ -968,11 +938,11 @@ public class LwM2MTransportService { |
968
|
938
|
if (sentAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
|
969
|
939
|
// update value in Resources
|
970
|
940
|
registrationIds.forEach(registrationId -> {
|
971
|
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(registrationId);
|
|
941
|
+ LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(null, registrationId);
|
972
|
942
|
LeshanServer lwServer = lwM2MClient.getLwServer();
|
973
|
943
|
Registration registration = lwM2mInMemorySecurityStore.getByRegistration(registrationId);
|
974
|
944
|
log.warn("[{}] # 4.1", registration.getEndpoint());
|
975
|
|
- this.updateResourceValueObserve(lwServer, registration, lwM2MClient, sentAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
|
|
945
|
+ this.updateResourceValueObserve(lwServer, registration, sentAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
|
976
|
946
|
// sent attr/telemetry to tingsboard for new path
|
977
|
947
|
this.updateAttrTelemetry(registration, false, sentAttrToThingsboard.getPathPostParametersAdd());
|
978
|
948
|
});
|
...
|
...
|
@@ -997,11 +967,11 @@ public class LwM2MTransportService { |
997
|
967
|
ResultsAnalyzerParameters postObserveAnalyzer = this.getAnalyzerParameters(sentObserveToClientOld.getPathPostParametersAdd(), sentObserveToClientNew.getPathPostParametersAdd());
|
998
|
968
|
// sent Request observe to Client
|
999
|
969
|
registrationIds.forEach(registrationId -> {
|
1000
|
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(registrationId);
|
|
970
|
+ LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(null, registrationId);
|
1001
|
971
|
LeshanServer lwServer = lwM2MClient.getLwServer();
|
1002
|
972
|
Registration registration = lwM2mInMemorySecurityStore.getByRegistration(registrationId);
|
1003
|
973
|
log.warn("[{}] # 5.1", registration.getEndpoint());
|
1004
|
|
- this.updateResourceValueObserve(lwServer, registration, lwM2MClient, postObserveAnalyzer.getPathPostParametersAdd(), GET_TYPE_OPER_OBSERVE);
|
|
974
|
+ this.updateResourceValueObserve(lwServer, registration, postObserveAnalyzer.getPathPostParametersAdd(), GET_TYPE_OPER_OBSERVE);
|
1005
|
975
|
// 5.3 del
|
1006
|
976
|
// sent Request cancel observe to Client
|
1007
|
977
|
this.cancelObserveIsValue(lwServer, registration, postObserveAnalyzer.getPathPostParametersDel());
|
...
|
...
|
@@ -1052,10 +1022,9 @@ public class LwM2MTransportService { |
1052
|
1022
|
*
|
1053
|
1023
|
* @param lwServer - LeshanServer
|
1054
|
1024
|
* @param registration - Registration LwM2M Client
|
1055
|
|
- * @param lwM2MClient - object with All parameters off client
|
1056
|
1025
|
* @param targets - path Resources == [ "/2/0/0", "/2/0/1"]
|
1057
|
1026
|
*/
|
1058
|
|
- private void updateResourceValueObserve(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient, Set<String> targets, String typeOper) {
|
|
1027
|
+ private void updateResourceValueObserve(LeshanServer lwServer, Registration registration, Set<String> targets, String typeOper) {
|
1059
|
1028
|
targets.forEach(target -> {
|
1060
|
1029
|
LwM2mPath pathIds = new LwM2mPath(target);
|
1061
|
1030
|
if (pathIds.isResource()) {
|
...
|
...
|
@@ -1073,7 +1042,7 @@ public class LwM2MTransportService { |
1073
|
1042
|
}
|
1074
|
1043
|
|
1075
|
1044
|
private void cancelObserveIsValue(LeshanServer lwServer, Registration registration, Set<String> paramAnallyzer) {
|
1076
|
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(registration.getId());
|
|
1045
|
+ LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null);
|
1077
|
1046
|
paramAnallyzer.forEach(p -> {
|
1078
|
1047
|
if (this.getResourceValue(lwM2MClient, new LwM2mPath(p)) != null) {
|
1079
|
1048
|
this.setCancelObservationRecourse(lwServer, registration, p);
|
...
|
...
|
@@ -1130,7 +1099,7 @@ public class LwM2MTransportService { |
1130
|
1099
|
|
1131
|
1100
|
/**
|
1132
|
1101
|
* if sessionInfo removed from sessions, then new registerAsyncSession
|
1133
|
|
- * @param sessionInfo
|
|
1102
|
+ * @param sessionInfo -
|
1134
|
1103
|
*/
|
1135
|
1104
|
private void checkInactivity(SessionInfoProto sessionInfo) {
|
1136
|
1105
|
if (transportService.reportActivity(sessionInfo) == null) {
|
...
|
...
|
@@ -1138,20 +1107,14 @@ public class LwM2MTransportService { |
1138
|
1107
|
}
|
1139
|
1108
|
}
|
1140
|
1109
|
|
1141
|
|
- public void sentLogsToThingsboard(String msg, String registrationId) {
|
|
1110
|
+ public void sentLogsToThingsboard(String msg, Registration registration) {
|
1142
|
1111
|
if (msg != null) {
|
1143
|
1112
|
JsonObject telemetries = new JsonObject();
|
1144
|
1113
|
telemetries.addProperty(LOG_LW2M_TELEMETRY, msg);
|
1145
|
|
- this.updateParametersOnThingsboard(telemetries, LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC, registrationId);
|
|
1114
|
+ this.updateParametersOnThingsboard(telemetries, LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC, registration);
|
1146
|
1115
|
}
|
1147
|
1116
|
}
|
1148
|
1117
|
|
1149
|
|
- private String getResourceName(String path) {
|
1150
|
|
- LwM2mPath resultIds = new LwM2mPath(path);
|
1151
|
|
- return (context.getCtxServer().getObjectModels().get(resultIds.getObjectId()) != null) ?
|
1152
|
|
- context.getCtxServer().getObjectModels().get(resultIds.getObjectId()).resources.get(resultIds.getResourceId()).name : "";
|
1153
|
|
- }
|
1154
|
|
-
|
1155
|
1118
|
/**
|
1156
|
1119
|
* @param path - path resource
|
1157
|
1120
|
* @return - value of Resource or null
|
...
|
...
|
@@ -1160,6 +1123,6 @@ public class LwM2MTransportService { |
1160
|
1123
|
LwM2mPath pathIds = new LwM2mPath(path);
|
1161
|
1124
|
ResourceValue resourceValue = this.getResourceValue(lwM2MClient, pathIds);
|
1162
|
1125
|
return (resourceValue == null) ? null :
|
1163
|
|
- (String) this.converter.convertValue(resourceValue.getResourceValue(), this.context.getCtxServer().getResourceModelType(pathIds), ResourceModel.Type.STRING, pathIds);
|
|
1126
|
+ (String) this.converter.convertValue(resourceValue.getResourceValue(), this.context.getCtxServer().getResourceModelType(lwM2MClient.getRegistration(), pathIds), ResourceModel.Type.STRING, pathIds);
|
1164
|
1127
|
}
|
1165
|
1128
|
} |
...
|
...
|
|