Commit 42dc805339c728cf8fe7136695760ee9cf95de4c

Authored by Andrew Shvayka
Committed by GitHub
2 parents bb8f92b1 6521caf0

Merge pull request #5397 from thingsboard/lwm2m_fix_bug_models_null

[3.3.2]Lwm2m fix bug if model null
... ... @@ -95,7 +95,7 @@ public class LwM2mVersionedModelProvider implements LwM2mModelProvider {
95 95 if (objectModel != null)
96 96 return objectModel.resources.get(resourceId);
97 97 else
98   - log.trace("TbResources (Object model) with id [{}/0/{}] not found on the server", objectId, resourceId);
  98 + log.trace("Tenant hasn't such the TbResources: Object model with id [{}/0/{}].", objectId, resourceId);
99 99 return null;
100 100 } catch (Exception e) {
101 101 log.error("", e);
... ... @@ -128,14 +128,17 @@ public class LwM2mVersionedModelProvider implements LwM2mModelProvider {
128 128 private ObjectModel getObjectModelDynamic(Integer objectId, String version) {
129 129 String key = getKeyIdVer(objectId, version);
130 130 ObjectModel objectModel = models.get(tenantId).get(key);
131   -
132 131 if (objectModel == null) {
133 132 modelsLock.lock();
134 133 try {
135 134 objectModel = models.get(tenantId).get(key);
136 135 if (objectModel == null) {
137 136 objectModel = getObjectModel(key);
  137 + }
  138 + if (objectModel != null) {
138 139 models.get(tenantId).put(key, objectModel);
  140 + } else {
  141 + log.error("Tenant hasn't such the resource: Object model with id [{}] version [{}].", objectId, version);
139 142 }
140 143 } finally {
141 144 modelsLock.unlock();
... ...
... ... @@ -186,6 +186,9 @@ public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService im
186 186 }
187 187 sendSimpleRequest(client, downlink, request.getTimeout(), callback);
188 188 }
  189 + else {
  190 + callback.onValidationError(toString(request), "Tenant hasn't such the TbResources: " + request.getVersionedId() + "!");
  191 + }
189 192 }
190 193
191 194 @Override
... ... @@ -245,7 +248,7 @@ public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService im
245 248 callback.onError(toString(request), e);
246 249 }
247 250 } else {
248   - callback.onValidationError(toString(request), "Resource " + request.getVersionedId() + " is not configured in the device profile!");
  251 + callback.onValidationError(toString(request), "Tenant hasn't such the TbResources: " + request.getVersionedId() + "!");
249 252 }
250 253 }
251 254
... ... @@ -271,10 +274,15 @@ public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService im
271 274 **/
272 275 Collection<LwM2mResource> resources = client.getNewResourceForInstance(request.getVersionedId(), request.getValue(), modelProvider, this.converter);
273 276 ResourceModel resourceModelWrite = client.getResourceModel(request.getVersionedId(), modelProvider);
274   - ContentFormat contentFormat = request.getObjectContentFormat() != null ? request.getObjectContentFormat() : convertResourceModelTypeToContentFormat(client, resourceModelWrite.type);
275   - WriteRequest downlink = new WriteRequest(WriteRequest.Mode.UPDATE, contentFormat, resultIds.getObjectId(),
276   - resultIds.getObjectInstanceId(), resources);
277   - sendSimpleRequest(client, downlink, request.getTimeout(), callback);
  277 + if (resourceModelWrite != null) {
  278 + ContentFormat contentFormat = request.getObjectContentFormat() != null ? request.getObjectContentFormat() : convertResourceModelTypeToContentFormat(client, resourceModelWrite.type);
  279 + WriteRequest downlink = new WriteRequest(WriteRequest.Mode.UPDATE, contentFormat, resultIds.getObjectId(),
  280 + resultIds.getObjectInstanceId(), resources);
  281 + sendSimpleRequest(client, downlink, request.getTimeout(), callback);
  282 + }
  283 + else {
  284 + callback.onValidationError(toString(request), "Tenant hasn't such the TbResources: " + request.getVersionedId() + " !");
  285 + }
278 286 } else if (resultIds.isObjectInstance()) {
279 287 /*
280 288 * params = "{\"id\":0,\"resources\":[{\"id\":14,\"value\":\"+5\"},{\"id\":15,\"value\":\"+9\"}]}"
... ...