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