Search in sources :

Example 21 with EntityView

use of org.thingsboard.server.common.data.EntityView in project thingsboard by thingsboard.

the class BaseEntityViewControllerTest method fillListOf.

private List<EntityView> fillListOf(int limit, String partOfName) throws Exception {
    List<EntityView> viewNames = new ArrayList<>();
    for (int i = 0; i < limit; i++) {
        String fullName = partOfName + ' ' + RandomStringUtils.randomAlphanumeric(15);
        fullName = i % 2 == 0 ? fullName.toLowerCase() : fullName.toUpperCase();
        EntityView view = getNewSavedEntityView(fullName);
        Customer customer = getNewCustomer("Test customer " + String.valueOf(Math.random()));
        view.setCustomerId(doPost("/api/customer", customer, Customer.class).getId());
        viewNames.add(doPost("/api/entityView", view, EntityView.class));
    }
    return viewNames;
}
Also used : AttributesEntityView(org.thingsboard.server.common.data.objects.AttributesEntityView) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 22 with EntityView

use of org.thingsboard.server.common.data.EntityView in project thingsboard by thingsboard.

the class BaseEntityViewControllerTest method testUpdateEntityViewFromDifferentTenant.

@Test
public void testUpdateEntityViewFromDifferentTenant() throws Exception {
    EntityView savedView = getNewSavedEntityView("Test entity view");
    loginDifferentTenant();
    doPost("/api/entityView", savedView, EntityView.class, status().isForbidden());
    deleteDifferentTenant();
}
Also used : AttributesEntityView(org.thingsboard.server.common.data.objects.AttributesEntityView) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) Test(org.junit.Test)

Example 23 with EntityView

use of org.thingsboard.server.common.data.EntityView in project thingsboard by thingsboard.

the class BaseAssetService method deleteAsset.

@Override
public void deleteAsset(TenantId tenantId, AssetId assetId) {
    log.trace("Executing deleteAsset [{}]", assetId);
    validateId(assetId, INCORRECT_ASSET_ID + assetId);
    deleteEntityRelations(tenantId, assetId);
    Asset asset = assetDao.findById(tenantId, assetId.getId());
    try {
        List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(asset.getTenantId(), assetId).get();
        if (entityViews != null && !entityViews.isEmpty()) {
            throw new DataValidationException("Can't delete asset that has entity views!");
        }
    } catch (ExecutionException | InterruptedException e) {
        log.error("Exception while finding entity views for assetId [{}]", assetId, e);
        throw new RuntimeException("Exception while finding entity views for assetId [" + assetId + "]", e);
    }
    cacheManager.removeAssetFromCacheByName(asset.getTenantId(), asset.getName());
    assetDao.removeById(tenantId, assetId.getId());
}
Also used : DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) EntityView(org.thingsboard.server.common.data.EntityView) Asset(org.thingsboard.server.common.data.asset.Asset) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with EntityView

use of org.thingsboard.server.common.data.EntityView 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 25 with EntityView

use of org.thingsboard.server.common.data.EntityView 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)

Aggregations

EntityView (org.thingsboard.server.common.data.EntityView)51 TelemetryEntityView (org.thingsboard.server.common.data.objects.TelemetryEntityView)21 Test (org.junit.Test)18 AttributesEntityView (org.thingsboard.server.common.data.objects.AttributesEntityView)17 ExecutionException (java.util.concurrent.ExecutionException)16 EntityViewId (org.thingsboard.server.common.data.id.EntityViewId)15 ArrayList (java.util.ArrayList)13 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)12 Customer (org.thingsboard.server.common.data.Customer)11 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 ApiOperation (io.swagger.annotations.ApiOperation)9 List (java.util.List)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 Edge (org.thingsboard.server.common.data.edge.Edge)8 PageLink (org.thingsboard.server.common.data.page.PageLink)7 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)7 Matchers.containsString (org.hamcrest.Matchers.containsString)6