|
|
|
@ -17,6 +17,7 @@ package org.thingsboard.server.dao.service; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.thingsboard.server.common.data.BaseData; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
@ -36,6 +37,11 @@ public abstract class DataValidator<D extends BaseData<?>> { |
|
|
|
private static final Pattern EMAIL_PATTERN = |
|
|
|
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}$", Pattern.CASE_INSENSITIVE); |
|
|
|
|
|
|
|
private static final Pattern QUEUE_PATTERN = Pattern.compile("^[a-zA-Z0-9_.\\-]+$"); |
|
|
|
|
|
|
|
private static final String NAME = "name"; |
|
|
|
private static final String TOPIC = "topic"; |
|
|
|
|
|
|
|
// Returns old instance of the same object that is fetched during validation.
|
|
|
|
public D validate(D data, Function<D, TenantId> tenantIdFunction) { |
|
|
|
try { |
|
|
|
@ -134,4 +140,22 @@ public abstract class DataValidator<D extends BaseData<?>> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected static void validateQueueName(String name) { |
|
|
|
validateQueueNameOrTopic(name, NAME); |
|
|
|
} |
|
|
|
|
|
|
|
protected static void validateQueueTopic(String topic) { |
|
|
|
validateQueueNameOrTopic(topic, TOPIC); |
|
|
|
} |
|
|
|
|
|
|
|
private static void validateQueueNameOrTopic(String value, String fieldName) { |
|
|
|
if (StringUtils.isEmpty(value)) { |
|
|
|
throw new DataValidationException(String.format("Queue %s should be specified!", fieldName)); |
|
|
|
} |
|
|
|
if (!QUEUE_PATTERN.matcher(value).matches()) { |
|
|
|
throw new DataValidationException( |
|
|
|
String.format("Queue %s contains a character other than ASCII alphanumerics, '.', '_' and '-'!", fieldName)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|