Browse Source

Merge pull request #3949 from ShvaykaD/master

[3.2.1] added new method to JacksonUtil & replaced objectMapper from AuditLogServiceImpl
pull/3950/head
Igor Kulikov 6 years ago
committed by GitHub
parent
commit
03457a3566
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java
  2. 2
      dao/src/main/java/org/thingsboard/server/dao/util/mapping/JacksonUtil.java

20
dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java

@ -17,7 +17,6 @@ package org.thingsboard.server.dao.audit;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
@ -50,6 +49,7 @@ import org.thingsboard.server.dao.device.provision.ProvisionRequest;
import org.thingsboard.server.dao.entity.EntityService;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.util.mapping.JacksonUtil;
import java.io.PrintWriter;
import java.io.StringWriter;
@ -65,8 +65,6 @@ import static org.thingsboard.server.dao.service.Validator.validateId;
@ConditionalOnProperty(prefix = "audit-log", value = "enabled", havingValue = "true")
public class AuditLogServiceImpl implements AuditLogService {
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";
private static final int INSERTS_PER_ENTRY = 3;
@ -159,7 +157,7 @@ public class AuditLogServiceImpl implements AuditLogService {
private <E extends HasName, I extends EntityId> JsonNode constructActionData(I entityId, E entity,
ActionType actionType,
Object... additionalInfo) {
ObjectNode actionData = objectMapper.createObjectNode();
ObjectNode actionData = JacksonUtil.newObjectNode();
switch (actionType) {
case ADDED:
case UPDATED:
@ -168,7 +166,7 @@ public class AuditLogServiceImpl implements AuditLogService {
case RELATIONS_DELETED:
case ASSIGNED_TO_TENANT:
if (entity != null) {
ObjectNode entityNode = objectMapper.valueToTree(entity);
ObjectNode entityNode = (ObjectNode) JacksonUtil.valueToTree(entity);
if (entityId.getEntityType() == EntityType.DASHBOARD) {
entityNode.put("configuration", "");
}
@ -177,7 +175,7 @@ public class AuditLogServiceImpl implements AuditLogService {
if (entityId.getEntityType() == EntityType.RULE_CHAIN) {
RuleChainMetaData ruleChainMetaData = extractParameter(RuleChainMetaData.class, additionalInfo);
if (ruleChainMetaData != null) {
ObjectNode ruleChainMetaDataNode = objectMapper.valueToTree(ruleChainMetaData);
ObjectNode ruleChainMetaDataNode = (ObjectNode) JacksonUtil.valueToTree(ruleChainMetaData);
actionData.set("metadata", ruleChainMetaDataNode);
}
}
@ -194,7 +192,7 @@ public class AuditLogServiceImpl implements AuditLogService {
String scope = extractParameter(String.class, 0, additionalInfo);
List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo);
actionData.put("scope", scope);
ObjectNode attrsNode = objectMapper.createObjectNode();
ObjectNode attrsNode = JacksonUtil.newObjectNode();
if (attributes != null) {
for (AttributeKvEntry attr : attributes) {
attrsNode.put(attr.getKey(), attr.getValueAsString());
@ -225,7 +223,7 @@ public class AuditLogServiceImpl implements AuditLogService {
case CREDENTIALS_UPDATED:
actionData.put("entityId", entityId.toString());
DeviceCredentials deviceCredentials = extractParameter(DeviceCredentials.class, additionalInfo);
actionData.set("credentials", objectMapper.valueToTree(deviceCredentials));
actionData.set("credentials", JacksonUtil.valueToTree(deviceCredentials));
break;
case ASSIGNED_TO_CUSTOMER:
strEntityId = extractParameter(String.class, 0, additionalInfo);
@ -246,7 +244,7 @@ public class AuditLogServiceImpl implements AuditLogService {
case RELATION_ADD_OR_UPDATE:
case RELATION_DELETED:
EntityRelation relation = extractParameter(EntityRelation.class, 0, additionalInfo);
actionData.set("relation", objectMapper.valueToTree(relation));
actionData.set("relation", JacksonUtil.valueToTree(relation));
break;
case LOGIN:
case LOGOUT:
@ -264,7 +262,7 @@ public class AuditLogServiceImpl implements AuditLogService {
case PROVISION_FAILURE:
ProvisionRequest request = extractParameter(ProvisionRequest.class, additionalInfo);
if (request != null) {
actionData.set("provisionRequest", objectMapper.valueToTree(request));
actionData.set("provisionRequest", JacksonUtil.valueToTree(request));
}
break;
case TIMESERIES_UPDATED:
@ -275,7 +273,7 @@ public class AuditLogServiceImpl implements AuditLogService {
updatedTimeseries.stream()
.collect(Collectors.groupingBy(TsKvEntry::getTs))
.forEach((k, v) -> {
ObjectNode element = objectMapper.createObjectNode();
ObjectNode element = JacksonUtil.newObjectNode();
element.put("ts", k);
ObjectNode values = element.putObject("values");
v.forEach(kvEntry -> values.put(kvEntry.getKey(), kvEntry.getValueAsString()));

2
dao/src/main/java/org/thingsboard/server/dao/util/mapping/JacksonUtil.java

@ -66,7 +66,7 @@ public class JacksonUtil {
throw new IllegalArgumentException(e);
}
}
public static ObjectNode newObjectNode(){
return OBJECT_MAPPER.createObjectNode();
}

Loading…
Cancel
Save