Search in sources :

Example 6 with EntityViewId

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

the class EntityViewController method deleteAttributesFromEntityView.

private ListenableFuture<Void> deleteAttributesFromEntityView(EntityView entityView, String scope, List<String> keys, SecurityUser user) {
    EntityViewId entityId = entityView.getId();
    SettableFuture<Void> resultFuture = SettableFuture.create();
    if (keys != null && !keys.isEmpty()) {
        tsSubService.deleteAndNotify(entityView.getTenantId(), entityId, scope, keys, new FutureCallback<Void>() {

            @Override
            public void onSuccess(@Nullable Void tmp) {
                try {
                    logAttributesDeleted(user, entityId, scope, keys, null);
                } catch (ThingsboardException e) {
                    log.error("Failed to log attribute delete", e);
                }
                resultFuture.set(tmp);
            }

            @Override
            public void onFailure(Throwable t) {
                try {
                    logAttributesDeleted(user, entityId, scope, keys, t);
                } catch (ThingsboardException e) {
                    log.error("Failed to log attribute delete", e);
                }
                resultFuture.setException(t);
            }
        });
    } else {
        resultFuture.set(null);
    }
    return resultFuture;
}
Also used : EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException)

Example 7 with EntityViewId

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

the class EntityViewController method assignEntityViewToCustomer.

@ApiOperation(value = "Assign Entity View to customer (assignEntityViewToCustomer)", notes = "Creates assignment of the Entity View to customer. Customer will be able to query Entity View afterwards." + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/{customerId}/entityView/{entityViewId}", method = RequestMethod.POST)
@ResponseBody
public EntityView assignEntityViewToCustomer(@ApiParam(value = CUSTOMER_ID_PARAM_DESCRIPTION) @PathVariable(CUSTOMER_ID) String strCustomerId, @ApiParam(value = ENTITY_VIEW_ID_PARAM_DESCRIPTION) @PathVariable(ENTITY_VIEW_ID) String strEntityViewId) throws ThingsboardException {
    checkParameter(CUSTOMER_ID, strCustomerId);
    checkParameter(ENTITY_VIEW_ID, strEntityViewId);
    try {
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        Customer customer = checkCustomerId(customerId, Operation.READ);
        EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
        checkEntityViewId(entityViewId, Operation.ASSIGN_TO_CUSTOMER);
        EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToCustomer(getTenantId(), entityViewId, customerId));
        logEntityAction(entityViewId, savedEntityView, savedEntityView.getCustomerId(), ActionType.ASSIGNED_TO_CUSTOMER, null, strEntityViewId, strCustomerId, customer.getName());
        sendEntityAssignToCustomerNotificationMsg(savedEntityView.getTenantId(), savedEntityView.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
        return savedEntityView;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.ENTITY_VIEW), null, null, ActionType.ASSIGNED_TO_CUSTOMER, e, strEntityViewId, strCustomerId);
        throw handleException(e);
    }
}
Also used : EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) Customer(org.thingsboard.server.common.data.Customer) EntityView(org.thingsboard.server.common.data.EntityView) CustomerId(org.thingsboard.server.common.data.id.CustomerId) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ExecutionException(java.util.concurrent.ExecutionException) 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 8 with EntityViewId

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

the class EntityViewController method unassignEntityViewFromEdge.

@ApiOperation(value = "Unassign entity view from edge (unassignEntityViewFromEdge)", notes = "Clears assignment of the entity view to the edge. " + EDGE_UNASSIGN_ASYNC_FIRST_STEP_DESCRIPTION + "Second, remote edge service will receive an 'unassign' command to remove entity view " + EDGE_UNASSIGN_RECEIVE_STEP_DESCRIPTION + "Third, once 'unassign' command will be delivered to edge service, it's going to remove entity view locally.", produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/edge/{edgeId}/entityView/{entityViewId}", method = RequestMethod.DELETE)
@ResponseBody
public EntityView unassignEntityViewFromEdge(@PathVariable(EDGE_ID) String strEdgeId, @PathVariable(ENTITY_VIEW_ID) String strEntityViewId) throws ThingsboardException {
    checkParameter(EDGE_ID, strEdgeId);
    checkParameter(ENTITY_VIEW_ID, strEntityViewId);
    try {
        EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
        Edge edge = checkEdgeId(edgeId, Operation.READ);
        EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
        EntityView entityView = checkEntityViewId(entityViewId, Operation.READ);
        EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromEdge(getTenantId(), entityViewId, edgeId));
        logEntityAction(entityViewId, entityView, entityView.getCustomerId(), ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
        sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
        return savedEntityView;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.ENTITY_VIEW), null, null, ActionType.UNASSIGNED_FROM_EDGE, e, strEntityViewId, strEdgeId);
        throw handleException(e);
    }
}
Also used : EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) EntityView(org.thingsboard.server.common.data.EntityView) EdgeId(org.thingsboard.server.common.data.id.EdgeId) Edge(org.thingsboard.server.common.data.edge.Edge) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ExecutionException(java.util.concurrent.ExecutionException) 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 9 with EntityViewId

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

the class EntityViewController method deleteLatestFromEntityView.

private ListenableFuture<Void> deleteLatestFromEntityView(EntityView entityView, List<String> keys, SecurityUser user) {
    EntityViewId entityId = entityView.getId();
    SettableFuture<Void> resultFuture = SettableFuture.create();
    if (keys != null && !keys.isEmpty()) {
        tsSubService.deleteLatest(entityView.getTenantId(), entityId, keys, new FutureCallback<Void>() {

            @Override
            public void onSuccess(@Nullable Void tmp) {
                try {
                    logTimeseriesDeleted(user, entityId, keys, null);
                } catch (ThingsboardException e) {
                    log.error("Failed to log timeseries delete", e);
                }
                resultFuture.set(tmp);
            }

            @Override
            public void onFailure(Throwable t) {
                try {
                    logTimeseriesDeleted(user, entityId, keys, t);
                } catch (ThingsboardException e) {
                    log.error("Failed to log timeseries delete", e);
                }
                resultFuture.setException(t);
            }
        });
    } else {
        tsSubService.deleteAllLatest(entityView.getTenantId(), entityId, new FutureCallback<Collection<String>>() {

            @Override
            public void onSuccess(@Nullable Collection<String> keys) {
                try {
                    logTimeseriesDeleted(user, entityId, new ArrayList<>(keys), null);
                } catch (ThingsboardException e) {
                    log.error("Failed to log timeseries delete", e);
                }
                resultFuture.set(null);
            }

            @Override
            public void onFailure(Throwable t) {
                try {
                    logTimeseriesDeleted(user, entityId, Collections.emptyList(), t);
                } catch (ThingsboardException e) {
                    log.error("Failed to log timeseries delete", e);
                }
                resultFuture.setException(t);
            }
        });
    }
    return resultFuture;
}
Also used : EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 10 with EntityViewId

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

the class EntityViewController method deleteEntityView.

@ApiOperation(value = "Delete entity view (deleteEntityView)", notes = "Delete the EntityView object based on the provided entity view id. " + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/entityView/{entityViewId}", method = RequestMethod.DELETE)
@ResponseStatus(value = HttpStatus.OK)
public void deleteEntityView(@ApiParam(value = ENTITY_VIEW_ID_PARAM_DESCRIPTION) @PathVariable(ENTITY_VIEW_ID) String strEntityViewId) throws ThingsboardException {
    checkParameter(ENTITY_VIEW_ID, strEntityViewId);
    try {
        EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
        EntityView entityView = checkEntityViewId(entityViewId, Operation.DELETE);
        List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(getTenantId(), entityViewId);
        entityViewService.deleteEntityView(getTenantId(), entityViewId);
        logEntityAction(entityViewId, entityView, entityView.getCustomerId(), ActionType.DELETED, null, strEntityViewId);
        sendDeleteNotificationMsg(getTenantId(), entityViewId, relatedEdgeIds);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.ENTITY_VIEW), null, null, ActionType.DELETED, e, strEntityViewId);
        throw handleException(e);
    }
}
Also used : EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) EntityView(org.thingsboard.server.common.data.EntityView) EdgeId(org.thingsboard.server.common.data.id.EdgeId) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ExecutionException(java.util.concurrent.ExecutionException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EntityViewId (org.thingsboard.server.common.data.id.EntityViewId)19 EntityView (org.thingsboard.server.common.data.EntityView)14 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)11 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)10 ExecutionException (java.util.concurrent.ExecutionException)8 ApiOperation (io.swagger.annotations.ApiOperation)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 EdgeId (org.thingsboard.server.common.data.id.EdgeId)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Customer (org.thingsboard.server.common.data.Customer)5 Futures (com.google.common.util.concurrent.Futures)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Edge (org.thingsboard.server.common.data.edge.Edge)4 AssetId (org.thingsboard.server.common.data.id.AssetId)4 DeviceId (org.thingsboard.server.common.data.id.DeviceId)4