|
|
|
@ -45,6 +45,7 @@ import org.thingsboard.common.util.ThingsBoardThreadFactory; |
|
|
|
import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; |
|
|
|
import org.thingsboard.server.common.data.DataConstants; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.TenantProfile; |
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
|
import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
@ -69,6 +70,7 @@ import org.thingsboard.server.common.data.kv.LongDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.ReadTsKvQuery; |
|
|
|
import org.thingsboard.server.common.data.kv.StringDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
|
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|
|
|
import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
|
|
|
import org.thingsboard.server.dao.timeseries.TimeseriesService; |
|
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
|
@ -93,6 +95,7 @@ import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -205,7 +208,7 @@ public class TelemetryController extends BaseController { |
|
|
|
@RequestParam(name = "interval", defaultValue = "0") Long interval, |
|
|
|
@RequestParam(name = "limit", defaultValue = "100") Integer limit, |
|
|
|
@RequestParam(name = "agg", defaultValue = "NONE") String aggStr, |
|
|
|
@RequestParam(name= "orderBy", defaultValue = "DESC") String orderBy, |
|
|
|
@RequestParam(name = "orderBy", defaultValue = "DESC") String orderBy, |
|
|
|
@RequestParam(name = "useStrictDataTypes", required = false, defaultValue = "false") Boolean useStrictDataTypes) throws ThingsboardException { |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_TELEMETRY, entityType, entityIdStr, |
|
|
|
(result, tenantId, entityId) -> { |
|
|
|
@ -392,7 +395,7 @@ public class TelemetryController extends BaseController { |
|
|
|
if (attributes.isEmpty()) { |
|
|
|
return getImmediateDeferredResult("No attributes data found in request body!", HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
for (AttributeKvEntry attributeKvEntry: attributes) { |
|
|
|
for (AttributeKvEntry attributeKvEntry : attributes) { |
|
|
|
if (attributeKvEntry.getKey().isEmpty() || attributeKvEntry.getKey().trim().length() == 0) { |
|
|
|
return getImmediateDeferredResult("Key cannot be empty or contains only spaces", HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
@ -440,9 +443,13 @@ public class TelemetryController extends BaseController { |
|
|
|
if (entries.isEmpty()) { |
|
|
|
return getImmediateDeferredResult("No timeseries data found in request body!", HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.WRITE_TELEMETRY, entityIdSrc, (result, tenantId, entityId) -> { |
|
|
|
tsSubService.saveAndNotify(tenantId, entityId, entries, ttl, new FutureCallback<Void>() { |
|
|
|
long tenantTtl = ttl; |
|
|
|
if (!TenantId.SYS_TENANT_ID.equals(tenantId) && tenantTtl == 0) { |
|
|
|
TenantProfile tenantProfile = tenantProfileCache.get(tenantId); |
|
|
|
tenantTtl = TimeUnit.DAYS.toSeconds(((DefaultTenantProfileConfiguration) tenantProfile.getProfileData().getConfiguration()).getDefaultStorageTtlDays()); |
|
|
|
} |
|
|
|
tsSubService.saveAndNotify(tenantId, entityId, entries, tenantTtl, new FutureCallback<Void>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(@Nullable Void tmp) { |
|
|
|
result.setResult(new ResponseEntity(HttpStatus.OK)); |
|
|
|
|