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