|
|
|
@ -1,9 +1,27 @@ |
|
|
|
/** |
|
|
|
* Copyright © 2016-2018 The Thingsboard Authors |
|
|
|
* <p> |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* You may obtain a copy of the License at |
|
|
|
* <p> |
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* <p> |
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.controller; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.google.common.base.Function; |
|
|
|
import com.google.common.util.concurrent.FutureCallback; |
|
|
|
import com.google.common.util.concurrent.Futures; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import com.google.gson.JsonElement; |
|
|
|
import com.google.gson.JsonParser; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
@ -11,47 +29,54 @@ import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.springframework.web.context.request.async.DeferredResult; |
|
|
|
import org.thingsboard.server.actors.plugin.ValidationResult; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.DataConstants; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
|
import org.thingsboard.server.common.data.asset.Asset; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
|
import org.thingsboard.server.common.data.id.AssetId; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|
|
|
import org.thingsboard.server.common.data.id.RuleChainId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.id.UUIDBased; |
|
|
|
import org.thingsboard.server.common.data.kv.Aggregation; |
|
|
|
import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.BaseTsKvQuery; |
|
|
|
import org.thingsboard.server.common.data.kv.BasicTsKvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.BooleanDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.DoubleDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.KvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.LongDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.StringDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleChain; |
|
|
|
import org.thingsboard.server.common.data.kv.TsKvQuery; |
|
|
|
import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
|
|
|
import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
|
|
|
import org.thingsboard.server.dao.attributes.AttributesService; |
|
|
|
import org.thingsboard.server.dao.timeseries.TimeseriesService; |
|
|
|
import org.thingsboard.server.exception.ThingsboardException; |
|
|
|
import org.thingsboard.server.extensions.api.exception.ToErrorResponseEntity; |
|
|
|
import org.thingsboard.server.extensions.api.exception.InvalidParametersException; |
|
|
|
import org.thingsboard.server.extensions.api.exception.UncheckedApiException; |
|
|
|
import org.thingsboard.server.extensions.api.plugins.PluginConstants; |
|
|
|
import org.thingsboard.server.extensions.core.plugin.telemetry.AttributeData; |
|
|
|
import org.thingsboard.server.extensions.core.plugin.telemetry.TsData; |
|
|
|
import org.thingsboard.server.service.security.AccessValidator; |
|
|
|
import org.thingsboard.server.service.security.model.SecurityUser; |
|
|
|
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
|
|
|
|
|
|
|
import javax.annotation.Nullable; |
|
|
|
import javax.annotation.PreDestroy; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.function.BiConsumer; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -62,9 +87,8 @@ import java.util.stream.Collectors; |
|
|
|
@Slf4j |
|
|
|
public class TelemetryController extends BaseController { |
|
|
|
|
|
|
|
public static final String CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION = "Customer user is not allowed to perform this operation!"; |
|
|
|
public static final String SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION = "System administrator is not allowed to perform this operation!"; |
|
|
|
public static final String DEVICE_WITH_REQUESTED_ID_NOT_FOUND = "Device with requested id wasn't found!"; |
|
|
|
@Autowired |
|
|
|
private TelemetrySubscriptionService subscriptionService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AttributesService attributesService; |
|
|
|
@ -72,6 +96,9 @@ public class TelemetryController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private TimeseriesService tsService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AccessValidator accessValidator; |
|
|
|
|
|
|
|
private ExecutorService executor; |
|
|
|
|
|
|
|
public void initExecutor() { |
|
|
|
@ -87,117 +114,277 @@ public class TelemetryController extends BaseController { |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/keys/ATTRIBUTES", method = RequestMethod.GET) |
|
|
|
@ResponseStatus(value = HttpStatus.OK) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> getAttributeKeys( |
|
|
|
@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr) throws ThingsboardException { |
|
|
|
return validateEntityAndCallback(entityType, entityIdStr, |
|
|
|
this::getAttributeKeysCallback, |
|
|
|
(result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityType, entityIdStr, this::getAttributeKeysCallback); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/keys/ATTRIBUTES/{scope}", method = RequestMethod.GET) |
|
|
|
@ResponseStatus(value = HttpStatus.OK) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> getAttributeKeysByScope( |
|
|
|
@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr |
|
|
|
, @PathVariable("scope") String scope) throws ThingsboardException { |
|
|
|
return validateEntityAndCallback(entityType, entityIdStr, |
|
|
|
(result, entityId) -> getAttributeKeysCallback(result, entityId, scope), |
|
|
|
(result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityType, entityIdStr, |
|
|
|
(result, entityId) -> getAttributeKeysCallback(result, entityId, scope)); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/values/ATTRIBUTES", method = RequestMethod.GET) |
|
|
|
@ResponseStatus(value = HttpStatus.OK) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> getAttributes( |
|
|
|
@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException { |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
return validateEntityAndCallback(entityType, entityIdStr, |
|
|
|
(result, entityId) -> getAttributeValuesCallback(result, user, entityId, null, keysStr), |
|
|
|
(result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityType, entityIdStr, |
|
|
|
(result, entityId) -> getAttributeValuesCallback(result, user, entityId, null, keysStr)); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/values/ATTRIBUTES/{scope}", method = RequestMethod.GET) |
|
|
|
@ResponseStatus(value = HttpStatus.OK) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> getAttributesByScope( |
|
|
|
@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@PathVariable("scope") String scope, |
|
|
|
@RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException { |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
return validateEntityAndCallback(entityType, entityIdStr, |
|
|
|
(result, entityId) -> getAttributeValuesCallback(result, user, entityId, scope, keysStr), |
|
|
|
(result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityType, entityIdStr, |
|
|
|
(result, entityId) -> getAttributeValuesCallback(result, user, entityId, scope, keysStr)); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/keys/TIMESERIES", method = RequestMethod.GET) |
|
|
|
@ResponseStatus(value = HttpStatus.OK) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> getTimeseriesKeys( |
|
|
|
@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr) throws ThingsboardException { |
|
|
|
return validateEntityAndCallback(entityType, entityIdStr, |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityType, entityIdStr, |
|
|
|
(result, entityId) -> { |
|
|
|
Futures.addCallback(tsService.findAllLatest(entityId), getTsKeysToResponseCallback(result)); |
|
|
|
}, |
|
|
|
(result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/values/TIMESERIES", method = RequestMethod.GET) |
|
|
|
@ResponseStatus(value = HttpStatus.OK) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> getLatestTimeseries( |
|
|
|
@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@PathVariable("scope") String scope, |
|
|
|
@RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException { |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
|
|
|
|
return validateEntityAndCallback(entityType, entityIdStr, |
|
|
|
(result, entityId) -> getAttributeValuesCallback(result, user, entityId, scope, keysStr), |
|
|
|
(result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityType, entityIdStr, |
|
|
|
(result, entityId) -> getLatestTimeseriesValuesCallback(result, user, entityId, keysStr)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/values/TIMESERIES", method = RequestMethod.GET) |
|
|
|
@ResponseStatus(value = HttpStatus.OK) |
|
|
|
public DeferredResult<ResponseEntity> getLatestTimeseries( |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> getTimeseries( |
|
|
|
@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@PathVariable("scope") String scope, |
|
|
|
@RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException { |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
@RequestParam(name = "keys") String keys, |
|
|
|
@RequestParam(name = "startTs") Long startTs, |
|
|
|
@RequestParam(name = "endTs") Long endTs, |
|
|
|
@RequestParam(name = "interval", defaultValue = "0") Long interval, |
|
|
|
@RequestParam(name = "limit", defaultValue = "100") Integer limit, |
|
|
|
@RequestParam(name = "agg", defaultValue = "NONE") String aggStr |
|
|
|
) throws ThingsboardException { |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityType, entityIdStr, |
|
|
|
(result, entityId) -> { |
|
|
|
// If interval is 0, convert this to a NONE aggregation, which is probably what the user really wanted
|
|
|
|
Aggregation agg = interval == 0L ? Aggregation.valueOf(Aggregation.NONE.name()) : Aggregation.valueOf(aggStr); |
|
|
|
List<TsKvQuery> queries = toKeysList(keys).stream().map(key -> new BaseTsKvQuery(key, startTs, endTs, interval, limit, agg)) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
Futures.addCallback(tsService.findAll(entityId, queries), getTsKvListCallback(result)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{deviceId}/{scope}", method = RequestMethod.POST) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> saveDeviceAttributes(@PathVariable("deviceId") String deviceIdStr, @PathVariable("scope") String scope, |
|
|
|
@RequestBody JsonNode request) throws ThingsboardException { |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndUuid(EntityType.DEVICE, deviceIdStr); |
|
|
|
return saveAttributes(entityId, scope, request); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/{scope}", method = RequestMethod.POST) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> saveEntityAttributesV1(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@PathVariable("scope") String scope, |
|
|
|
@RequestBody JsonNode request) throws ThingsboardException { |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr); |
|
|
|
return saveAttributes(entityId, scope, request); |
|
|
|
} |
|
|
|
|
|
|
|
return validateEntityAndCallback(entityType, entityIdStr, |
|
|
|
(result, entityId) -> getAttributeValuesCallback(result, user, entityId, scope, keysStr), |
|
|
|
(result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); |
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/ATTRIBUTES/{scope}", method = RequestMethod.POST) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> saveEntityAttributesV2(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@PathVariable("scope") String scope, |
|
|
|
@RequestBody JsonNode request) throws ThingsboardException { |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr); |
|
|
|
return saveAttributes(entityId, scope, request); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/TIMESERIES/{scope}", method = RequestMethod.POST) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> saveEntityTelemetry(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@PathVariable("scope") String scope, |
|
|
|
@RequestBody String requestBody) throws ThingsboardException { |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr); |
|
|
|
return saveTelemetry(entityId, requestBody, 0L); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/TIMESERIES/{scope}/{ttl}", method = RequestMethod.POST) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> saveEntityTelemetryWithTTL(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@PathVariable("scope") String scope, @PathVariable("ttl") Long ttl, |
|
|
|
@RequestBody String requestBody) throws ThingsboardException { |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr); |
|
|
|
return saveTelemetry(entityId, requestBody, ttl); |
|
|
|
} |
|
|
|
|
|
|
|
private DeferredResult<ResponseEntity> validateEntityAndCallback(String entityType, String entityIdStr, |
|
|
|
BiConsumer<DeferredResult<ResponseEntity>, EntityId> onSuccess, BiConsumer<DeferredResult<ResponseEntity>, Throwable> onFailure) throws ThingsboardException { |
|
|
|
final DeferredResult<ResponseEntity> response = new DeferredResult<>(); |
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{deviceId}/{scope}", method = RequestMethod.DELETE) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> deleteEntityAttributes(@PathVariable("deviceId") String deviceIdStr, |
|
|
|
@PathVariable("scope") String scope, |
|
|
|
@RequestParam(name = "keys") String keysStr) throws ThingsboardException { |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndUuid(EntityType.DEVICE, deviceIdStr); |
|
|
|
return deleteAttributes(entityId, scope, keysStr); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/{entityType}/{entityId}/{scope}", method = RequestMethod.DELETE) |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> deleteEntityAttributes(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@PathVariable("scope") String scope, |
|
|
|
@RequestParam(name = "keys") String keysStr) throws ThingsboardException { |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr); |
|
|
|
return deleteAttributes(entityId, scope, keysStr); |
|
|
|
} |
|
|
|
|
|
|
|
private DeferredResult<ResponseEntity> deleteAttributes(EntityId entityIdStr, String scope, String keysStr) throws ThingsboardException { |
|
|
|
List<String> keys = toKeysList(keysStr); |
|
|
|
if (keys.isEmpty()) { |
|
|
|
return getImmediateDeferredResult("Empty keys: " + keysStr, HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
if (DataConstants.SERVER_SCOPE.equals(scope) || |
|
|
|
DataConstants.SHARED_SCOPE.equals(scope) || |
|
|
|
DataConstants.CLIENT_SCOPE.equals(scope)) { |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityIdStr, (result, entityId) -> { |
|
|
|
ListenableFuture<List<Void>> future = attributesService.removeAll(entityId, scope, keys); |
|
|
|
Futures.addCallback(future, new FutureCallback<List<Void>>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(@Nullable List<Void> tmp) { |
|
|
|
logAttributesDeleted(user, entityId, scope, keys, null); |
|
|
|
result.setResult(new ResponseEntity<>(HttpStatus.OK)); |
|
|
|
} |
|
|
|
|
|
|
|
validate(getCurrentUser(), entityId, new ValidationCallback(response, |
|
|
|
new FutureCallback<DeferredResult<ResponseEntity>>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(@Nullable DeferredResult<ResponseEntity> result) { |
|
|
|
onSuccess.accept(response, entityId); |
|
|
|
public void onFailure(Throwable t) { |
|
|
|
logAttributesDeleted(user, entityId, scope, keys, t); |
|
|
|
result.setResult(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); |
|
|
|
} |
|
|
|
}, executor); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
return getImmediateDeferredResult("Invalid attribute scope: " + scope, HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private DeferredResult<ResponseEntity> saveAttributes(EntityId entityIdSrc, String scope, JsonNode json) throws ThingsboardException { |
|
|
|
if (!DataConstants.SERVER_SCOPE.equals(scope) && !DataConstants.SHARED_SCOPE.equals(scope)) { |
|
|
|
return getImmediateDeferredResult("Invalid scope: " + scope, HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
if (json.isObject()) { |
|
|
|
List<AttributeKvEntry> attributes = extractRequestAttributes(json); |
|
|
|
if (attributes.isEmpty()) { |
|
|
|
return getImmediateDeferredResult("No attributes data found in request body!", HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityIdSrc, (result, entityId) -> { |
|
|
|
ListenableFuture<List<Void>> future = attributesService.save(entityId, scope, attributes); |
|
|
|
Futures.addCallback(future, new FutureCallback<List<Void>>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(@Nullable List<Void> tmp) { |
|
|
|
logAttributesUpdated(user, entityId, scope, attributes, null); |
|
|
|
result.setResult(new ResponseEntity(HttpStatus.OK)); |
|
|
|
subscriptionService.onAttributesUpdateFromServer(entityId, scope, attributes); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Throwable t) { |
|
|
|
onFailure.accept(response, t); |
|
|
|
logAttributesUpdated(user, entityId, scope, attributes, t); |
|
|
|
AccessValidator.handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
} |
|
|
|
})); |
|
|
|
}); |
|
|
|
result.setResult(new ResponseEntity(HttpStatus.OK)); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
return getImmediateDeferredResult("Request is not a JSON object", HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private DeferredResult<ResponseEntity> saveTelemetry(EntityId entityIdSrc, String requestBody, long ttl) throws ThingsboardException { |
|
|
|
TelemetryUploadRequest telemetryRequest; |
|
|
|
JsonElement telemetryJson; |
|
|
|
try { |
|
|
|
telemetryJson = new JsonParser().parse(requestBody); |
|
|
|
} catch (Exception e) { |
|
|
|
return getImmediateDeferredResult("Unable to parse timeseries payload: Invalid JSON body!", HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
try { |
|
|
|
telemetryRequest = JsonConverter.convertToTelemetry(telemetryJson); |
|
|
|
} catch (Exception e) { |
|
|
|
return getImmediateDeferredResult("Unable to parse timeseries payload. Invalid JSON body: " + e.getMessage(), HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
List<TsKvEntry> entries = new ArrayList<>(); |
|
|
|
for (Map.Entry<Long, List<KvEntry>> entry : telemetryRequest.getData().entrySet()) { |
|
|
|
for (KvEntry kv : entry.getValue()) { |
|
|
|
entries.add(new BasicTsKvEntry(entry.getKey(), kv)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (entries.isEmpty()) { |
|
|
|
return getImmediateDeferredResult("No timeseries data found in request body!", HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), entityIdSrc, (result, entityId) -> { |
|
|
|
ListenableFuture<List<Void>> future = tsService.save(entityId, entries, ttl); |
|
|
|
Futures.addCallback(future, new FutureCallback<List<Void>>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(@Nullable List<Void> tmp) { |
|
|
|
result.setResult(new ResponseEntity(HttpStatus.OK)); |
|
|
|
subscriptionService.onTimeseriesUpdateFromServer(entityId, entries); |
|
|
|
} |
|
|
|
|
|
|
|
return response; |
|
|
|
@Override |
|
|
|
public void onFailure(Throwable t) { |
|
|
|
AccessValidator.handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
} |
|
|
|
}); |
|
|
|
result.setResult(new ResponseEntity(HttpStatus.OK)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void getAttributeValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String scope, String keys) { |
|
|
|
List<String> keyList = null; |
|
|
|
if (!StringUtils.isEmpty(keys)) { |
|
|
|
keyList = Arrays.asList(keys.split(",")); |
|
|
|
private void getLatestTimeseriesValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String keys) { |
|
|
|
ListenableFuture<List<TsKvEntry>> future; |
|
|
|
if (StringUtils.isEmpty(keys)) { |
|
|
|
future = tsService.findAllLatest(entityId); |
|
|
|
} else { |
|
|
|
future = tsService.findLatest(entityId, toKeysList(keys)); |
|
|
|
} |
|
|
|
Futures.addCallback(future, getTsKvListCallback(result)); |
|
|
|
} |
|
|
|
|
|
|
|
private void getAttributeValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String scope, String keys) { |
|
|
|
List<String> keyList = toKeysList(keys); |
|
|
|
FutureCallback<List<AttributeKvEntry>> callback = getAttributeValuesToResponseCallback(result, user, scope, entityId, keyList); |
|
|
|
if (!StringUtils.isEmpty(scope)) { |
|
|
|
if (keyList != null && !keyList.isEmpty()) { |
|
|
|
@ -247,7 +434,7 @@ public class TelemetryController extends BaseController { |
|
|
|
@Override |
|
|
|
public void onFailure(Throwable e) { |
|
|
|
log.error("Failed to fetch attributes", e); |
|
|
|
handleError(e, response, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
AccessValidator.handleError(e, response, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
@ -264,12 +451,13 @@ public class TelemetryController extends BaseController { |
|
|
|
@Override |
|
|
|
public void onFailure(Throwable e) { |
|
|
|
log.error("Failed to fetch attributes", e); |
|
|
|
handleError(e, response, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
AccessValidator.handleError(e, response, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private FutureCallback<List<AttributeKvEntry>> getAttributeValuesToResponseCallback(final DeferredResult<ResponseEntity> response, final SecurityUser user, final String scope, |
|
|
|
private FutureCallback<List<AttributeKvEntry>> getAttributeValuesToResponseCallback(final DeferredResult<ResponseEntity> response, |
|
|
|
final SecurityUser user, final String scope, |
|
|
|
final EntityId entityId, final List<String> keyList) { |
|
|
|
return new FutureCallback<List<AttributeKvEntry>>() { |
|
|
|
@Override |
|
|
|
@ -284,12 +472,32 @@ public class TelemetryController extends BaseController { |
|
|
|
public void onFailure(Throwable e) { |
|
|
|
log.error("Failed to fetch attributes", e); |
|
|
|
logAttributesRead(user, entityId, scope, keyList, e); |
|
|
|
handleError(e, response, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
AccessValidator.handleError(e, response, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private void logAttributesRead(SecurityUser user, EntityId entityId, String scope, List<String> keys, Throwable e) { |
|
|
|
private FutureCallback<List<TsKvEntry>> getTsKvListCallback(final DeferredResult<ResponseEntity> response) { |
|
|
|
return new FutureCallback<List<TsKvEntry>>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(List<TsKvEntry> data) { |
|
|
|
Map<String, List<TsData>> result = new LinkedHashMap<>(); |
|
|
|
for (TsKvEntry entry : data) { |
|
|
|
result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()) |
|
|
|
.add(new TsData(entry.getTs(), entry.getValueAsString())); |
|
|
|
} |
|
|
|
response.setResult(new ResponseEntity<>(result, HttpStatus.OK)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Throwable e) { |
|
|
|
log.error("Failed to fetch historical data", e); |
|
|
|
AccessValidator.handleError(e, response, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private void logAttributesDeleted(SecurityUser user, EntityId entityId, String scope, List<String> keys, Throwable e) { |
|
|
|
auditLogService.logEntityAction( |
|
|
|
user.getTenantId(), |
|
|
|
user.getCustomerId(), |
|
|
|
@ -297,163 +505,39 @@ public class TelemetryController extends BaseController { |
|
|
|
user.getName(), |
|
|
|
(UUIDBased & EntityId) entityId, |
|
|
|
null, |
|
|
|
ActionType.ATTRIBUTES_READ, |
|
|
|
ActionType.ATTRIBUTES_DELETED, |
|
|
|
toException(e), |
|
|
|
scope, |
|
|
|
keys); |
|
|
|
} |
|
|
|
|
|
|
|
private void handleError(Throwable e, final DeferredResult<ResponseEntity> response, HttpStatus defaultErrorStatus) { |
|
|
|
ResponseEntity responseEntity; |
|
|
|
if (e != null && e instanceof ToErrorResponseEntity) { |
|
|
|
responseEntity = ((ToErrorResponseEntity) e).toErrorResponseEntity(); |
|
|
|
} else if (e != null && e instanceof IllegalArgumentException) { |
|
|
|
responseEntity = new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); |
|
|
|
} else { |
|
|
|
responseEntity = new ResponseEntity<>(defaultErrorStatus); |
|
|
|
} |
|
|
|
response.setResult(responseEntity); |
|
|
|
} |
|
|
|
|
|
|
|
private void validate(SecurityUser currentUser, EntityId entityId, ValidationCallback callback) { |
|
|
|
switch (entityId.getEntityType()) { |
|
|
|
case DEVICE: |
|
|
|
validateDevice(currentUser, entityId, callback); |
|
|
|
return; |
|
|
|
case ASSET: |
|
|
|
validateAsset(currentUser, entityId, callback); |
|
|
|
return; |
|
|
|
case RULE_CHAIN: |
|
|
|
validateRuleChain(currentUser, entityId, callback); |
|
|
|
return; |
|
|
|
case CUSTOMER: |
|
|
|
validateCustomer(currentUser, entityId, callback); |
|
|
|
return; |
|
|
|
case TENANT: |
|
|
|
validateTenant(currentUser, entityId, callback); |
|
|
|
return; |
|
|
|
default: |
|
|
|
//TODO: add support of other entities
|
|
|
|
throw new IllegalStateException("Not Implemented!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void validateDevice(final SecurityUser currentUser, EntityId entityId, ValidationCallback callback) { |
|
|
|
if (currentUser.isSystemAdmin()) { |
|
|
|
callback.onSuccess(ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); |
|
|
|
} else { |
|
|
|
ListenableFuture<Device> deviceFuture = deviceService.findDeviceByIdAsync(new DeviceId(entityId.getId())); |
|
|
|
Futures.addCallback(deviceFuture, getCallback(callback, device -> { |
|
|
|
if (device == null) { |
|
|
|
return ValidationResult.entityNotFound(DEVICE_WITH_REQUESTED_ID_NOT_FOUND); |
|
|
|
} else { |
|
|
|
if (!device.getTenantId().equals(currentUser.getTenantId())) { |
|
|
|
return ValidationResult.accessDenied("Device doesn't belong to the current Tenant!"); |
|
|
|
} else if (currentUser.isCustomerUser() && !device.getCustomerId().equals(currentUser.getCustomerId())) { |
|
|
|
return ValidationResult.accessDenied("Device doesn't belong to the current Customer!"); |
|
|
|
} else { |
|
|
|
return ValidationResult.ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void validateAsset(final SecurityUser currentUser, EntityId entityId, ValidationCallback callback) { |
|
|
|
if (currentUser.isSystemAdmin()) { |
|
|
|
callback.onSuccess(ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); |
|
|
|
} else { |
|
|
|
ListenableFuture<Asset> assetFuture = assetService.findAssetByIdAsync(new AssetId(entityId.getId())); |
|
|
|
Futures.addCallback(assetFuture, getCallback(callback, asset -> { |
|
|
|
if (asset == null) { |
|
|
|
return ValidationResult.entityNotFound("Asset with requested id wasn't found!"); |
|
|
|
} else { |
|
|
|
if (!asset.getTenantId().equals(currentUser.getTenantId())) { |
|
|
|
return ValidationResult.accessDenied("Asset doesn't belong to the current Tenant!"); |
|
|
|
} else if (currentUser.isCustomerUser() && !asset.getCustomerId().equals(currentUser.getCustomerId())) { |
|
|
|
return ValidationResult.accessDenied("Asset doesn't belong to the current Customer!"); |
|
|
|
} else { |
|
|
|
return ValidationResult.ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void validateRuleChain(final SecurityUser currentUser, EntityId entityId, ValidationCallback callback) { |
|
|
|
if (currentUser.isCustomerUser()) { |
|
|
|
callback.onSuccess(ValidationResult.accessDenied(CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); |
|
|
|
} else { |
|
|
|
ListenableFuture<RuleChain> ruleChainFuture = ruleChainService.findRuleChainByIdAsync(new RuleChainId(entityId.getId())); |
|
|
|
Futures.addCallback(ruleChainFuture, getCallback(callback, ruleChain -> { |
|
|
|
if (ruleChain == null) { |
|
|
|
return ValidationResult.entityNotFound("Rule chain with requested id wasn't found!"); |
|
|
|
} else { |
|
|
|
if (currentUser.isTenantAdmin() && !ruleChain.getTenantId().equals(currentUser.getTenantId())) { |
|
|
|
return ValidationResult.accessDenied("Rule chain doesn't belong to the current Tenant!"); |
|
|
|
} else if (currentUser.isSystemAdmin() && !ruleChain.getTenantId().isNullUid()) { |
|
|
|
return ValidationResult.accessDenied("Rule chain is not in system scope!"); |
|
|
|
} else { |
|
|
|
return ValidationResult.ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void validateCustomer(final SecurityUser currentUser, EntityId entityId, ValidationCallback callback) { |
|
|
|
if (currentUser.isSystemAdmin()) { |
|
|
|
callback.onSuccess(ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); |
|
|
|
} else { |
|
|
|
ListenableFuture<Customer> customerFuture = customerService.findCustomerByIdAsync(new CustomerId(entityId.getId())); |
|
|
|
Futures.addCallback(customerFuture, getCallback(callback, customer -> { |
|
|
|
if (customer == null) { |
|
|
|
return ValidationResult.entityNotFound("Customer with requested id wasn't found!"); |
|
|
|
} else { |
|
|
|
if (!customer.getTenantId().equals(currentUser.getTenantId())) { |
|
|
|
return ValidationResult.accessDenied("Customer doesn't belong to the current Tenant!"); |
|
|
|
} else if (currentUser.isCustomerUser() && !customer.getId().equals(currentUser.getCustomerId())) { |
|
|
|
return ValidationResult.accessDenied("Customer doesn't relate to the currently authorized customer user!"); |
|
|
|
} else { |
|
|
|
return ValidationResult.ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void validateTenant(final SecurityUser currentUser, EntityId entityId, ValidationCallback callback) { |
|
|
|
if (currentUser.isCustomerUser()) { |
|
|
|
callback.onSuccess(ValidationResult.accessDenied(CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); |
|
|
|
} else if (currentUser.isSystemAdmin()) { |
|
|
|
callback.onSuccess(ValidationResult.ok()); |
|
|
|
} else { |
|
|
|
ListenableFuture<Tenant> tenantFuture = tenantService.findTenantByIdAsync(new TenantId(entityId.getId())); |
|
|
|
Futures.addCallback(tenantFuture, getCallback(callback, tenant -> { |
|
|
|
if (tenant == null) { |
|
|
|
return ValidationResult.entityNotFound("Tenant with requested id wasn't found!"); |
|
|
|
} else if (!tenant.getId().equals(currentUser.getTenantId())) { |
|
|
|
return ValidationResult.accessDenied("Tenant doesn't relate to the currently authorized user!"); |
|
|
|
} else { |
|
|
|
return ValidationResult.ok(); |
|
|
|
} |
|
|
|
})); |
|
|
|
} |
|
|
|
private void logAttributesUpdated(SecurityUser user, EntityId entityId, String scope, List<AttributeKvEntry> attributes, Throwable e) { |
|
|
|
auditLogService.logEntityAction( |
|
|
|
user.getTenantId(), |
|
|
|
user.getCustomerId(), |
|
|
|
user.getId(), |
|
|
|
user.getName(), |
|
|
|
(UUIDBased & EntityId) entityId, |
|
|
|
null, |
|
|
|
ActionType.ATTRIBUTES_UPDATED, |
|
|
|
toException(e), |
|
|
|
scope, |
|
|
|
attributes); |
|
|
|
} |
|
|
|
|
|
|
|
private <T> FutureCallback<T> getCallback(ValidationCallback callback, Function<T, ValidationResult> transformer) { |
|
|
|
return new FutureCallback<T>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(@Nullable T result) { |
|
|
|
callback.onSuccess(transformer.apply(result)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Throwable t) { |
|
|
|
callback.onFailure(t); |
|
|
|
} |
|
|
|
}; |
|
|
|
private void logAttributesRead(SecurityUser user, EntityId entityId, String scope, List<String> keys, Throwable e) { |
|
|
|
auditLogService.logEntityAction( |
|
|
|
user.getTenantId(), |
|
|
|
user.getCustomerId(), |
|
|
|
user.getId(), |
|
|
|
user.getName(), |
|
|
|
(UUIDBased & EntityId) entityId, |
|
|
|
null, |
|
|
|
ActionType.ATTRIBUTES_READ, |
|
|
|
toException(e), |
|
|
|
scope, |
|
|
|
keys); |
|
|
|
} |
|
|
|
|
|
|
|
private ListenableFuture<List<AttributeKvEntry>> mergeAllAttributesFutures(List<ListenableFuture<List<AttributeKvEntry>>> futures) { |
|
|
|
@ -467,4 +551,40 @@ public class TelemetryController extends BaseController { |
|
|
|
}, executor); |
|
|
|
} |
|
|
|
|
|
|
|
private List<String> toKeysList(String keys) { |
|
|
|
List<String> keyList = null; |
|
|
|
if (!StringUtils.isEmpty(keys)) { |
|
|
|
keyList = Arrays.asList(keys.split(",")); |
|
|
|
} |
|
|
|
return keyList; |
|
|
|
} |
|
|
|
|
|
|
|
private DeferredResult<ResponseEntity> getImmediateDeferredResult(String message, HttpStatus status) { |
|
|
|
DeferredResult<ResponseEntity> result = new DeferredResult<>(); |
|
|
|
result.setResult(new ResponseEntity<>(message, status)); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private List<AttributeKvEntry> extractRequestAttributes(JsonNode jsonNode) { |
|
|
|
long ts = System.currentTimeMillis(); |
|
|
|
List<AttributeKvEntry> attributes = new ArrayList<>(); |
|
|
|
jsonNode.fields().forEachRemaining(entry -> { |
|
|
|
String key = entry.getKey(); |
|
|
|
JsonNode value = entry.getValue(); |
|
|
|
if (entry.getValue().isTextual()) { |
|
|
|
attributes.add(new BaseAttributeKvEntry(new StringDataEntry(key, value.textValue()), ts)); |
|
|
|
} else if (entry.getValue().isBoolean()) { |
|
|
|
attributes.add(new BaseAttributeKvEntry(new BooleanDataEntry(key, value.booleanValue()), ts)); |
|
|
|
} else if (entry.getValue().isDouble()) { |
|
|
|
attributes.add(new BaseAttributeKvEntry(new DoubleDataEntry(key, value.doubleValue()), ts)); |
|
|
|
} else if (entry.getValue().isNumber()) { |
|
|
|
if (entry.getValue().isBigInteger()) { |
|
|
|
throw new UncheckedApiException(new InvalidParametersException("Big integer values are not supported!")); |
|
|
|
} else { |
|
|
|
attributes.add(new BaseAttributeKvEntry(new LongDataEntry(key, value.longValue()), ts)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return attributes; |
|
|
|
} |
|
|
|
} |
|
|
|
|