Showing
6 changed files
with
19 additions
and
19 deletions
@@ -15,13 +15,13 @@ | @@ -15,13 +15,13 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.edge.rpc.constructor; | 16 | package org.thingsboard.server.service.edge.rpc.constructor; |
17 | 17 | ||
18 | +import com.google.gson.reflect.TypeToken; | ||
18 | import com.google.gson.Gson; | 19 | import com.google.gson.Gson; |
19 | import com.google.gson.JsonArray; | 20 | import com.google.gson.JsonArray; |
20 | import com.google.gson.JsonElement; | 21 | import com.google.gson.JsonElement; |
21 | import com.google.gson.JsonObject; | 22 | import com.google.gson.JsonObject; |
22 | import lombok.extern.slf4j.Slf4j; | 23 | import lombok.extern.slf4j.Slf4j; |
23 | import org.springframework.stereotype.Component; | 24 | import org.springframework.stereotype.Component; |
24 | -import org.thingsboard.server.common.data.audit.ActionType; | ||
25 | import org.thingsboard.server.common.data.edge.EdgeEventActionType; | 25 | import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
26 | import org.thingsboard.server.common.data.id.EntityId; | 26 | import org.thingsboard.server.common.data.id.EntityId; |
27 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; | 27 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
@@ -82,7 +82,7 @@ public class EntityDataMsgConstructor { | @@ -82,7 +82,7 @@ public class EntityDataMsgConstructor { | ||
82 | AttributeDeleteMsg.Builder attributeDeleteMsg = AttributeDeleteMsg.newBuilder(); | 82 | AttributeDeleteMsg.Builder attributeDeleteMsg = AttributeDeleteMsg.newBuilder(); |
83 | attributeDeleteMsg.setScope(entityData.getAsJsonObject().getAsJsonPrimitive("scope").getAsString()); | 83 | attributeDeleteMsg.setScope(entityData.getAsJsonObject().getAsJsonPrimitive("scope").getAsString()); |
84 | JsonArray jsonArray = entityData.getAsJsonObject().getAsJsonArray("keys"); | 84 | JsonArray jsonArray = entityData.getAsJsonObject().getAsJsonArray("keys"); |
85 | - List<String> keys = new Gson().fromJson(jsonArray.toString(), List.class); | 85 | + List<String> keys = new Gson().fromJson(jsonArray.toString(), new TypeToken<>(){}.getType()); |
86 | attributeDeleteMsg.addAllAttributeNames(keys); | 86 | attributeDeleteMsg.addAllAttributeNames(keys); |
87 | attributeDeleteMsg.build(); | 87 | attributeDeleteMsg.build(); |
88 | builder.setAttributeDeleteMsg(attributeDeleteMsg); | 88 | builder.setAttributeDeleteMsg(attributeDeleteMsg); |
@@ -159,7 +159,7 @@ public class CassandraDbHelper { | @@ -159,7 +159,7 @@ public class CassandraDbHelper { | ||
159 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) { | 159 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) { |
160 | str = ""+row.getInstant(index).toEpochMilli(); | 160 | str = ""+row.getInstant(index).toEpochMilli(); |
161 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.BOOLEAN) { | 161 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.BOOLEAN) { |
162 | - str = new Boolean(row.getBoolean(index)).toString(); | 162 | + str = Boolean.valueOf(row.getBoolean(index)).toString(); |
163 | } else { | 163 | } else { |
164 | str = row.getString(index); | 164 | str = row.getString(index); |
165 | } | 165 | } |
@@ -270,7 +270,8 @@ public class EdgeImitator { | @@ -270,7 +270,8 @@ public class EdgeImitator { | ||
270 | responsesLatch = new CountDownLatch(messageAmount); | 270 | responsesLatch = new CountDownLatch(messageAmount); |
271 | } | 271 | } |
272 | 272 | ||
273 | - public <T> Optional<T> findMessageByType(Class<T> tClass) { | 273 | + @SuppressWarnings("unchecked") |
274 | + public <T extends AbstractMessage> Optional<T> findMessageByType(Class<T> tClass) { | ||
274 | Optional<T> result; | 275 | Optional<T> result; |
275 | try { | 276 | try { |
276 | lock.lock(); | 277 | lock.lock(); |
@@ -103,9 +103,9 @@ public class LwM2mClient implements Cloneable { | @@ -103,9 +103,9 @@ public class LwM2mClient implements Cloneable { | ||
103 | * @param modelProvider - | 103 | * @param modelProvider - |
104 | */ | 104 | */ |
105 | public void deleteResources(String pathIdVer, LwM2mModelProvider modelProvider) { | 105 | public void deleteResources(String pathIdVer, LwM2mModelProvider modelProvider) { |
106 | - Set key = getKeysEqualsIdVer(pathIdVer); | 106 | + Set<String> key = getKeysEqualsIdVer(pathIdVer); |
107 | key.forEach(pathRez -> { | 107 | key.forEach(pathRez -> { |
108 | - LwM2mPath pathIds = new LwM2mPath(convertToObjectIdFromIdVer(pathRez.toString())); | 108 | + LwM2mPath pathIds = new LwM2mPath(convertToObjectIdFromIdVer(pathRez)); |
109 | ResourceModel resourceModel = modelProvider.getObjectModel(registration).getResourceModel(pathIds.getObjectId(), pathIds.getResourceId()); | 109 | ResourceModel resourceModel = modelProvider.getObjectModel(registration).getResourceModel(pathIds.getObjectId(), pathIds.getResourceId()); |
110 | if (resourceModel != null) { | 110 | if (resourceModel != null) { |
111 | this.resources.get(pathRez).setResourceModel(resourceModel); | 111 | this.resources.get(pathRez).setResourceModel(resourceModel); |
@@ -122,8 +122,8 @@ public class LwM2mClient implements Cloneable { | @@ -122,8 +122,8 @@ public class LwM2mClient implements Cloneable { | ||
122 | * @param modelProvider - | 122 | * @param modelProvider - |
123 | */ | 123 | */ |
124 | public void updateResourceModel(String idVer, LwM2mModelProvider modelProvider) { | 124 | public void updateResourceModel(String idVer, LwM2mModelProvider modelProvider) { |
125 | - Set key = getKeysEqualsIdVer(idVer); | ||
126 | - key.forEach(k -> this.saveResourceModel(k.toString(), modelProvider)); | 125 | + Set<String> key = getKeysEqualsIdVer(idVer); |
126 | + key.forEach(k -> this.saveResourceModel(k, modelProvider)); | ||
127 | } | 127 | } |
128 | 128 | ||
129 | private void saveResourceModel(String pathRez, LwM2mModelProvider modelProvider) { | 129 | private void saveResourceModel(String pathRez, LwM2mModelProvider modelProvider) { |
@@ -132,7 +132,7 @@ public class LwM2mClient implements Cloneable { | @@ -132,7 +132,7 @@ public class LwM2mClient implements Cloneable { | ||
132 | this.resources.get(pathRez).setResourceModel(resourceModel); | 132 | this.resources.get(pathRez).setResourceModel(resourceModel); |
133 | } | 133 | } |
134 | 134 | ||
135 | - private Set getKeysEqualsIdVer(String idVer) { | 135 | + private Set<String> getKeysEqualsIdVer(String idVer) { |
136 | return this.resources.keySet() | 136 | return this.resources.keySet() |
137 | .stream() | 137 | .stream() |
138 | .filter(e -> idVer.equals(e.split(LWM2M_SEPARATOR_PATH)[1])) | 138 | .filter(e -> idVer.equals(e.split(LWM2M_SEPARATOR_PATH)[1])) |
@@ -586,7 +586,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | @@ -586,7 +586,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | ||
586 | 586 | ||
587 | @Override | 587 | @Override |
588 | public Object activateInstance(String edgeLicenseSecret, String releaseDate) { | 588 | public Object activateInstance(String edgeLicenseSecret, String releaseDate) { |
589 | - Map<String, String> params = new HashMap(); | 589 | + Map<String, String> params = new HashMap<>(); |
590 | params.put("licenseSecret", edgeLicenseSecret); | 590 | params.put("licenseSecret", edgeLicenseSecret); |
591 | params.put("releaseDate", releaseDate); | 591 | params.put("releaseDate", releaseDate); |
592 | return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", (Object) null, Object.class, params); | 592 | return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", (Object) null, Object.class, params); |
@@ -16,13 +16,14 @@ | @@ -16,13 +16,14 @@ | ||
16 | package org.thingsboard.rule.engine.edge; | 16 | package org.thingsboard.rule.engine.edge; |
17 | 17 | ||
18 | import com.fasterxml.jackson.core.JsonProcessingException; | 18 | import com.fasterxml.jackson.core.JsonProcessingException; |
19 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 20 | import com.fasterxml.jackson.databind.JsonNode; |
20 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
21 | import com.google.common.util.concurrent.FutureCallback; | 21 | import com.google.common.util.concurrent.FutureCallback; |
22 | import com.google.common.util.concurrent.Futures; | 22 | import com.google.common.util.concurrent.Futures; |
23 | import com.google.common.util.concurrent.ListenableFuture; | 23 | import com.google.common.util.concurrent.ListenableFuture; |
24 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
25 | import org.springframework.util.StringUtils; | 25 | import org.springframework.util.StringUtils; |
26 | +import org.thingsboard.common.util.JacksonUtil; | ||
26 | import org.thingsboard.rule.engine.api.EmptyNodeConfiguration; | 27 | import org.thingsboard.rule.engine.api.EmptyNodeConfiguration; |
27 | import org.thingsboard.rule.engine.api.RuleNode; | 28 | import org.thingsboard.rule.engine.api.RuleNode; |
28 | import org.thingsboard.rule.engine.api.TbContext; | 29 | import org.thingsboard.rule.engine.api.TbContext; |
@@ -87,8 +88,6 @@ public class TbMsgPushToEdgeNode implements TbNode { | @@ -87,8 +88,6 @@ public class TbMsgPushToEdgeNode implements TbNode { | ||
87 | 88 | ||
88 | private EmptyNodeConfiguration config; | 89 | private EmptyNodeConfiguration config; |
89 | 90 | ||
90 | - private static final ObjectMapper json = new ObjectMapper(); | ||
91 | - | ||
92 | private static final String SCOPE = "scope"; | 91 | private static final String SCOPE = "scope"; |
93 | 92 | ||
94 | @Override | 93 | @Override |
@@ -200,7 +199,7 @@ public class TbMsgPushToEdgeNode implements TbNode { | @@ -200,7 +199,7 @@ public class TbMsgPushToEdgeNode implements TbNode { | ||
200 | EdgeEventActionType actionType = getEdgeEventActionTypeByMsgType(msgType); | 199 | EdgeEventActionType actionType = getEdgeEventActionTypeByMsgType(msgType); |
201 | Map<String, Object> entityBody = new HashMap<>(); | 200 | Map<String, Object> entityBody = new HashMap<>(); |
202 | Map<String, String> metadata = msg.getMetaData().getData(); | 201 | Map<String, String> metadata = msg.getMetaData().getData(); |
203 | - JsonNode dataJson = json.readTree(msg.getData()); | 202 | + JsonNode dataJson = JacksonUtil.toJsonNode(msg.getData()); |
204 | switch (actionType) { | 203 | switch (actionType) { |
205 | case ATTRIBUTES_UPDATED: | 204 | case ATTRIBUTES_UPDATED: |
206 | case POST_ATTRIBUTES: | 205 | case POST_ATTRIBUTES: |
@@ -208,7 +207,7 @@ public class TbMsgPushToEdgeNode implements TbNode { | @@ -208,7 +207,7 @@ public class TbMsgPushToEdgeNode implements TbNode { | ||
208 | entityBody.put(SCOPE, getScope(metadata)); | 207 | entityBody.put(SCOPE, getScope(metadata)); |
209 | break; | 208 | break; |
210 | case ATTRIBUTES_DELETED: | 209 | case ATTRIBUTES_DELETED: |
211 | - List<String> keys = json.treeToValue(dataJson.get("attributes"), List.class); | 210 | + List<String> keys = JacksonUtil.convertValue(dataJson.get("attributes"), new TypeReference<>() {}); |
212 | entityBody.put("keys", keys); | 211 | entityBody.put("keys", keys); |
213 | entityBody.put(SCOPE, getScope(metadata)); | 212 | entityBody.put(SCOPE, getScope(metadata)); |
214 | break; | 213 | break; |
@@ -217,7 +216,7 @@ public class TbMsgPushToEdgeNode implements TbNode { | @@ -217,7 +216,7 @@ public class TbMsgPushToEdgeNode implements TbNode { | ||
217 | entityBody.put("ts", metadata.get("ts")); | 216 | entityBody.put("ts", metadata.get("ts")); |
218 | break; | 217 | break; |
219 | } | 218 | } |
220 | - return buildEdgeEvent(ctx.getTenantId(), actionType, msg.getOriginator().getId(), edgeEventTypeByEntityType, json.valueToTree(entityBody)); | 219 | + return buildEdgeEvent(ctx.getTenantId(), actionType, msg.getOriginator().getId(), edgeEventTypeByEntityType, JacksonUtil.valueToTree(entityBody)); |
221 | } | 220 | } |
222 | } | 221 | } |
223 | 222 | ||
@@ -240,9 +239,9 @@ public class TbMsgPushToEdgeNode implements TbNode { | @@ -240,9 +239,9 @@ public class TbMsgPushToEdgeNode implements TbNode { | ||
240 | return edgeEvent; | 239 | return edgeEvent; |
241 | } | 240 | } |
242 | 241 | ||
243 | - private UUID getUUIDFromMsgData(TbMsg msg) throws JsonProcessingException { | ||
244 | - JsonNode data = json.readTree(msg.getData()).get("id"); | ||
245 | - String id = json.treeToValue(data.get("id"), String.class); | 242 | + private UUID getUUIDFromMsgData(TbMsg msg) { |
243 | + JsonNode data = JacksonUtil.toJsonNode(msg.getData()).get("id"); | ||
244 | + String id = JacksonUtil.convertValue(data.get("id"), String.class); | ||
246 | return UUID.fromString(id); | 245 | return UUID.fromString(id); |
247 | } | 246 | } |
248 | 247 |