Search in sources :

Example 6 with RpcId

use of org.thingsboard.server.common.data.id.RpcId in project thingsboard by thingsboard.

the class RpcV2Controller method deleteRpc.

@ApiOperation(value = "Delete persistent RPC", notes = "Deletes the persistent RPC request." + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/persistent/{rpcId}", method = RequestMethod.DELETE)
@ResponseBody
public void deleteRpc(@ApiParam(value = RPC_ID_PARAM_DESCRIPTION, required = true) @PathVariable(RPC_ID) String strRpc) throws ThingsboardException {
    checkParameter("RpcId", strRpc);
    try {
        RpcId rpcId = new RpcId(UUID.fromString(strRpc));
        Rpc rpc = checkRpcId(rpcId, Operation.DELETE);
        if (rpc != null) {
            if (rpc.getStatus().equals(RpcStatus.QUEUED)) {
                RemoveRpcActorMsg removeMsg = new RemoveRpcActorMsg(getTenantId(), rpc.getDeviceId(), rpc.getUuidId());
                log.trace("[{}] Forwarding msg {} to queue actor!", rpc.getDeviceId(), rpc);
                tbClusterService.pushMsgToCore(removeMsg, null);
            }
            rpcService.deleteRpc(getTenantId(), rpcId);
            rpc.setStatus(RpcStatus.DELETED);
            TbMsg msg = TbMsg.newMsg(RPC_DELETED, rpc.getDeviceId(), TbMsgMetaData.EMPTY, JacksonUtil.toString(rpc));
            tbClusterService.pushMsgToRuleEngine(getTenantId(), rpc.getDeviceId(), msg, null);
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : Rpc(org.thingsboard.server.common.data.rpc.Rpc) RemoveRpcActorMsg(org.thingsboard.server.service.rpc.RemoveRpcActorMsg) RpcId(org.thingsboard.server.common.data.id.RpcId) TbMsg(org.thingsboard.server.common.msg.TbMsg) ResponseStatusException(org.springframework.web.server.ResponseStatusException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with RpcId

use of org.thingsboard.server.common.data.id.RpcId in project thingsboard by thingsboard.

the class AccessValidator method validateRpc.

private void validateRpc(final SecurityUser currentUser, Operation operation, EntityId entityId, FutureCallback<ValidationResult> callback) {
    ListenableFuture<Rpc> rpcFurure = rpcService.findRpcByIdAsync(currentUser.getTenantId(), new RpcId(entityId.getId()));
    Futures.addCallback(rpcFurure, getCallback(callback, rpc -> {
        if (rpc == null) {
            return ValidationResult.entityNotFound("Rpc with requested id wasn't found!");
        } else {
            try {
                accessControlService.checkPermission(currentUser, Resource.RPC, operation, entityId, rpc);
            } catch (ThingsboardException e) {
                return ValidationResult.accessDenied(e.getMessage());
            }
            return ValidationResult.ok(rpc);
        }
    }), executor);
}
Also used : Edge(org.thingsboard.server.common.data.edge.Edge) HttpValidationCallback(org.thingsboard.server.controller.HttpValidationCallback) Customer(org.thingsboard.server.common.data.Customer) Autowired(org.springframework.beans.factory.annotation.Autowired) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) RuleNodeId(org.thingsboard.server.common.data.id.RuleNodeId) TenantId(org.thingsboard.server.common.data.id.TenantId) ToErrorResponseEntity(org.thingsboard.server.service.telemetry.exception.ToErrorResponseEntity) PreDestroy(javax.annotation.PreDestroy) TenantService(org.thingsboard.server.dao.tenant.TenantService) Rpc(org.thingsboard.server.common.data.rpc.Rpc) ResourceService(org.thingsboard.server.dao.resource.ResourceService) RpcService(org.thingsboard.server.dao.rpc.RpcService) ApiUsageStateService(org.thingsboard.server.dao.usagerecord.ApiUsageStateService) EntityViewService(org.thingsboard.server.dao.entityview.EntityViewService) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) EdgeId(org.thingsboard.server.common.data.id.EdgeId) AssetService(org.thingsboard.server.dao.asset.AssetService) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Function(com.google.common.base.Function) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) EdgeService(org.thingsboard.server.dao.edge.EdgeService) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) ThingsBoardThreadFactory(org.thingsboard.common.util.ThingsBoardThreadFactory) ApiUsageStateId(org.thingsboard.server.common.data.id.ApiUsageStateId) OtaPackageId(org.thingsboard.server.common.data.id.OtaPackageId) Executors(java.util.concurrent.Executors) EntityView(org.thingsboard.server.common.data.EntityView) PostConstruct(javax.annotation.PostConstruct) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) Operation(org.thingsboard.server.service.security.permission.Operation) EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) OtaPackageService(org.thingsboard.server.dao.ota.OtaPackageService) UserService(org.thingsboard.server.dao.user.UserService) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Device(org.thingsboard.server.common.data.Device) DeferredResult(org.springframework.web.context.request.async.DeferredResult) AssetId(org.thingsboard.server.common.data.id.AssetId) Tenant(org.thingsboard.server.common.data.Tenant) RuleChainService(org.thingsboard.server.dao.rule.RuleChainService) User(org.thingsboard.server.common.data.User) EntityIdFactory(org.thingsboard.server.common.data.id.EntityIdFactory) DeviceService(org.thingsboard.server.dao.device.DeviceService) AlarmService(org.thingsboard.server.dao.alarm.AlarmService) EntityId(org.thingsboard.server.common.data.id.EntityId) BiConsumer(java.util.function.BiConsumer) CustomerService(org.thingsboard.server.dao.customer.CustomerService) Nullable(javax.annotation.Nullable) ExecutorService(java.util.concurrent.ExecutorService) RpcId(org.thingsboard.server.common.data.id.RpcId) RuleNode(org.thingsboard.server.common.data.rule.RuleNode) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) TbResourceId(org.thingsboard.server.common.data.id.TbResourceId) FutureCallback(com.google.common.util.concurrent.FutureCallback) ApiUsageState(org.thingsboard.server.common.data.ApiUsageState) DeviceProfileService(org.thingsboard.server.dao.device.DeviceProfileService) HttpStatus(org.springframework.http.HttpStatus) Futures(com.google.common.util.concurrent.Futures) Component(org.springframework.stereotype.Component) UserId(org.thingsboard.server.common.data.id.UserId) TbResourceInfo(org.thingsboard.server.common.data.TbResourceInfo) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) Resource(org.thingsboard.server.service.security.permission.Resource) ResponseEntity(org.springframework.http.ResponseEntity) Asset(org.thingsboard.server.common.data.asset.Asset) AccessControlService(org.thingsboard.server.service.security.permission.AccessControlService) Rpc(org.thingsboard.server.common.data.rpc.Rpc) RpcId(org.thingsboard.server.common.data.id.RpcId) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException)

Example 8 with RpcId

use of org.thingsboard.server.common.data.id.RpcId in project thingsboard by thingsboard.

the class RpcEntity method toData.

@Override
public Rpc toData() {
    Rpc rpc = new Rpc(new RpcId(id));
    rpc.setCreatedTime(createdTime);
    rpc.setTenantId(TenantId.fromUUID(tenantId));
    rpc.setDeviceId(new DeviceId(deviceId));
    rpc.setExpirationTime(expirationTime);
    rpc.setRequest(request);
    rpc.setResponse(response);
    rpc.setStatus(status);
    rpc.setAdditionalInfo(additionalInfo);
    return rpc;
}
Also used : Rpc(org.thingsboard.server.common.data.rpc.Rpc) DeviceId(org.thingsboard.server.common.data.id.DeviceId) RpcId(org.thingsboard.server.common.data.id.RpcId)

Aggregations

RpcId (org.thingsboard.server.common.data.id.RpcId)8 Rpc (org.thingsboard.server.common.data.rpc.Rpc)4 FromDeviceRpcResponse (org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 UUID (java.util.UUID)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Nullable (javax.annotation.Nullable)2 Device (org.thingsboard.server.common.data.Device)2 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)2 RpcStatus (org.thingsboard.server.common.data.rpc.RpcStatus)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Function (com.google.common.base.Function)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1