Merge with develop/2.5.5
This commit is contained in:
commit
1f5f411b4c
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.dao.event;
|
package org.thingsboard.server.dao.event;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -28,6 +29,7 @@ import org.thingsboard.server.common.data.page.TimePageLink;
|
|||||||
import org.thingsboard.server.dao.exception.DataValidationException;
|
import org.thingsboard.server.dao.exception.DataValidationException;
|
||||||
import org.thingsboard.server.dao.service.DataValidator;
|
import org.thingsboard.server.dao.service.DataValidator;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -35,6 +37,8 @@ import java.util.Optional;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class BaseEventService implements EventService {
|
public class BaseEventService implements EventService {
|
||||||
|
|
||||||
|
private static final int MAX_DEBUG_EVENT_SYMBOLS = 4 * 1024;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public EventDao eventDao;
|
public EventDao eventDao;
|
||||||
|
|
||||||
@ -47,6 +51,7 @@ public class BaseEventService implements EventService {
|
|||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Event> saveAsync(Event event) {
|
public ListenableFuture<Event> saveAsync(Event event) {
|
||||||
eventValidator.validate(event, Event::getTenantId);
|
eventValidator.validate(event, Event::getTenantId);
|
||||||
|
checkAndTruncateDebugEvent(event);
|
||||||
return eventDao.saveAsync(event);
|
return eventDao.saveAsync(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,9 +61,21 @@ public class BaseEventService implements EventService {
|
|||||||
if (StringUtils.isEmpty(event.getUid())) {
|
if (StringUtils.isEmpty(event.getUid())) {
|
||||||
throw new DataValidationException("Event uid should be specified!.");
|
throw new DataValidationException("Event uid should be specified!.");
|
||||||
}
|
}
|
||||||
|
checkAndTruncateDebugEvent(event);
|
||||||
return eventDao.saveIfNotExists(event);
|
return eventDao.saveIfNotExists(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkAndTruncateDebugEvent(Event event) {
|
||||||
|
if (event.getType().startsWith("DEBUG") && event.getBody() != null && event.getBody().has("data")) {
|
||||||
|
String dataStr = event.getBody().get("data").asText();
|
||||||
|
int length = dataStr.length();
|
||||||
|
if (length > MAX_DEBUG_EVENT_SYMBOLS) {
|
||||||
|
((ObjectNode) event.getBody()).put("data", dataStr.substring(0, MAX_DEBUG_EVENT_SYMBOLS) + "...[truncated " + (length - MAX_DEBUG_EVENT_SYMBOLS) + " symbols]");
|
||||||
|
log.trace("[{}] Event was truncated: {}", event.getId(), dataStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Event> findEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) {
|
public Optional<Event> findEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) {
|
||||||
if (tenantId == null) {
|
if (tenantId == null) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user