Commit 03457a3566b1911e67c2f007c48f7acb0fb45895

Authored by Igor Kulikov
Committed by GitHub
2 parents 9409acfe 27e15ab7

Merge pull request #3949 from ShvaykaD/master

[3.2.1] added new method to JacksonUtil & replaced objectMapper from AuditLogServiceImpl
... ... @@ -17,7 +17,6 @@ package org.thingsboard.server.dao.audit;
17 17
18 18 import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20   -import com.fasterxml.jackson.databind.ObjectMapper;
21 20 import com.fasterxml.jackson.databind.node.ArrayNode;
22 21 import com.fasterxml.jackson.databind.node.ObjectNode;
23 22 import com.google.common.collect.Lists;
... ... @@ -50,6 +49,7 @@ import org.thingsboard.server.dao.device.provision.ProvisionRequest;
50 49 import org.thingsboard.server.dao.entity.EntityService;
51 50 import org.thingsboard.server.dao.exception.DataValidationException;
52 51 import org.thingsboard.server.dao.service.DataValidator;
  52 +import org.thingsboard.server.dao.util.mapping.JacksonUtil;
53 53
54 54 import java.io.PrintWriter;
55 55 import java.io.StringWriter;
... ... @@ -65,8 +65,6 @@ import static org.thingsboard.server.dao.service.Validator.validateId;
65 65 @ConditionalOnProperty(prefix = "audit-log", value = "enabled", havingValue = "true")
66 66 public class AuditLogServiceImpl implements AuditLogService {
67 67
68   - private static final ObjectMapper objectMapper = new ObjectMapper();
69   -
70 68 private static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";
71 69 private static final int INSERTS_PER_ENTRY = 3;
72 70
... ... @@ -159,7 +157,7 @@ public class AuditLogServiceImpl implements AuditLogService {
159 157 private <E extends HasName, I extends EntityId> JsonNode constructActionData(I entityId, E entity,
160 158 ActionType actionType,
161 159 Object... additionalInfo) {
162   - ObjectNode actionData = objectMapper.createObjectNode();
  160 + ObjectNode actionData = JacksonUtil.newObjectNode();
163 161 switch (actionType) {
164 162 case ADDED:
165 163 case UPDATED:
... ... @@ -168,7 +166,7 @@ public class AuditLogServiceImpl implements AuditLogService {
168 166 case RELATIONS_DELETED:
169 167 case ASSIGNED_TO_TENANT:
170 168 if (entity != null) {
171   - ObjectNode entityNode = objectMapper.valueToTree(entity);
  169 + ObjectNode entityNode = (ObjectNode) JacksonUtil.valueToTree(entity);
172 170 if (entityId.getEntityType() == EntityType.DASHBOARD) {
173 171 entityNode.put("configuration", "");
174 172 }
... ... @@ -177,7 +175,7 @@ public class AuditLogServiceImpl implements AuditLogService {
177 175 if (entityId.getEntityType() == EntityType.RULE_CHAIN) {
178 176 RuleChainMetaData ruleChainMetaData = extractParameter(RuleChainMetaData.class, additionalInfo);
179 177 if (ruleChainMetaData != null) {
180   - ObjectNode ruleChainMetaDataNode = objectMapper.valueToTree(ruleChainMetaData);
  178 + ObjectNode ruleChainMetaDataNode = (ObjectNode) JacksonUtil.valueToTree(ruleChainMetaData);
181 179 actionData.set("metadata", ruleChainMetaDataNode);
182 180 }
183 181 }
... ... @@ -194,7 +192,7 @@ public class AuditLogServiceImpl implements AuditLogService {
194 192 String scope = extractParameter(String.class, 0, additionalInfo);
195 193 List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo);
196 194 actionData.put("scope", scope);
197   - ObjectNode attrsNode = objectMapper.createObjectNode();
  195 + ObjectNode attrsNode = JacksonUtil.newObjectNode();
198 196 if (attributes != null) {
199 197 for (AttributeKvEntry attr : attributes) {
200 198 attrsNode.put(attr.getKey(), attr.getValueAsString());
... ... @@ -225,7 +223,7 @@ public class AuditLogServiceImpl implements AuditLogService {
225 223 case CREDENTIALS_UPDATED:
226 224 actionData.put("entityId", entityId.toString());
227 225 DeviceCredentials deviceCredentials = extractParameter(DeviceCredentials.class, additionalInfo);
228   - actionData.set("credentials", objectMapper.valueToTree(deviceCredentials));
  226 + actionData.set("credentials", JacksonUtil.valueToTree(deviceCredentials));
229 227 break;
230 228 case ASSIGNED_TO_CUSTOMER:
231 229 strEntityId = extractParameter(String.class, 0, additionalInfo);
... ... @@ -246,7 +244,7 @@ public class AuditLogServiceImpl implements AuditLogService {
246 244 case RELATION_ADD_OR_UPDATE:
247 245 case RELATION_DELETED:
248 246 EntityRelation relation = extractParameter(EntityRelation.class, 0, additionalInfo);
249   - actionData.set("relation", objectMapper.valueToTree(relation));
  247 + actionData.set("relation", JacksonUtil.valueToTree(relation));
250 248 break;
251 249 case LOGIN:
252 250 case LOGOUT:
... ... @@ -264,7 +262,7 @@ public class AuditLogServiceImpl implements AuditLogService {
264 262 case PROVISION_FAILURE:
265 263 ProvisionRequest request = extractParameter(ProvisionRequest.class, additionalInfo);
266 264 if (request != null) {
267   - actionData.set("provisionRequest", objectMapper.valueToTree(request));
  265 + actionData.set("provisionRequest", JacksonUtil.valueToTree(request));
268 266 }
269 267 break;
270 268 case TIMESERIES_UPDATED:
... ... @@ -275,7 +273,7 @@ public class AuditLogServiceImpl implements AuditLogService {
275 273 updatedTimeseries.stream()
276 274 .collect(Collectors.groupingBy(TsKvEntry::getTs))
277 275 .forEach((k, v) -> {
278   - ObjectNode element = objectMapper.createObjectNode();
  276 + ObjectNode element = JacksonUtil.newObjectNode();
279 277 element.put("ts", k);
280 278 ObjectNode values = element.putObject("values");
281 279 v.forEach(kvEntry -> values.put(kvEntry.getKey(), kvEntry.getValueAsString()));
... ...
... ... @@ -66,7 +66,7 @@ public class JacksonUtil {
66 66 throw new IllegalArgumentException(e);
67 67 }
68 68 }
69   -
  69 +
70 70 public static ObjectNode newObjectNode(){
71 71 return OBJECT_MAPPER.createObjectNode();
72 72 }
... ...