Search in sources :

Example 91 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseAssetService method unassignAssetFromEdge.

@Override
public Asset unassignAssetFromEdge(TenantId tenantId, AssetId assetId, EdgeId edgeId) {
    Asset asset = findAssetById(tenantId, assetId);
    Edge edge = edgeService.findEdgeById(tenantId, edgeId);
    if (edge == null) {
        throw new DataValidationException("Can't unassign asset from non-existent edge!");
    }
    checkAssignedEntityViewsToEdge(tenantId, assetId, edgeId);
    try {
        deleteRelation(tenantId, new EntityRelation(edgeId, assetId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
    } catch (Exception e) {
        log.warn("[{}] Failed to delete asset relation. Edge Id: [{}]", assetId, edgeId);
        throw new RuntimeException(e);
    }
    return asset;
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Asset(org.thingsboard.server.common.data.asset.Asset) Edge(org.thingsboard.server.common.data.edge.Edge) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) ExecutionException(java.util.concurrent.ExecutionException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Example 92 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseAssetService method assignAssetToEdge.

@Override
public Asset assignAssetToEdge(TenantId tenantId, AssetId assetId, EdgeId edgeId) {
    Asset asset = findAssetById(tenantId, assetId);
    Edge edge = edgeService.findEdgeById(tenantId, edgeId);
    if (edge == null) {
        throw new DataValidationException("Can't assign asset to non-existent edge!");
    }
    if (!edge.getTenantId().getId().equals(asset.getTenantId().getId())) {
        throw new DataValidationException("Can't assign asset to edge from different tenant!");
    }
    try {
        createRelation(tenantId, new EntityRelation(edgeId, assetId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
    } catch (Exception e) {
        log.warn("[{}] Failed to create asset relation. Edge Id: [{}]", assetId, edgeId);
        throw new RuntimeException(e);
    }
    return asset;
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Asset(org.thingsboard.server.common.data.asset.Asset) Edge(org.thingsboard.server.common.data.edge.Edge) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) ExecutionException(java.util.concurrent.ExecutionException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Example 93 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class DashboardServiceImpl method assignDashboardToEdge.

@Override
public Dashboard assignDashboardToEdge(TenantId tenantId, DashboardId dashboardId, EdgeId edgeId) {
    Dashboard dashboard = findDashboardById(tenantId, dashboardId);
    Edge edge = edgeDao.findById(tenantId, edgeId.getId());
    if (edge == null) {
        throw new DataValidationException("Can't assign dashboard to non-existent edge!");
    }
    if (!edge.getTenantId().equals(dashboard.getTenantId())) {
        throw new DataValidationException("Can't assign dashboard to edge from different tenant!");
    }
    try {
        createRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
    } catch (Exception e) {
        log.warn("[{}] Failed to create dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
        throw new RuntimeException(e);
    }
    return dashboard;
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Dashboard(org.thingsboard.server.common.data.Dashboard) Edge(org.thingsboard.server.common.data.edge.Edge) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Example 94 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class DashboardServiceImpl method unassignDashboardFromEdge.

@Override
public Dashboard unassignDashboardFromEdge(TenantId tenantId, DashboardId dashboardId, EdgeId edgeId) {
    Dashboard dashboard = findDashboardById(tenantId, dashboardId);
    Edge edge = edgeDao.findById(tenantId, edgeId.getId());
    if (edge == null) {
        throw new DataValidationException("Can't unassign dashboard from non-existent edge!");
    }
    try {
        deleteRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
    } catch (Exception e) {
        log.warn("[{}] Failed to delete dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
        throw new RuntimeException(e);
    }
    return dashboard;
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Dashboard(org.thingsboard.server.common.data.Dashboard) Edge(org.thingsboard.server.common.data.edge.Edge) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Example 95 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseRuleChainService method unassignRuleChainFromEdge.

@Override
public RuleChain unassignRuleChainFromEdge(TenantId tenantId, RuleChainId ruleChainId, EdgeId edgeId, boolean remove) {
    RuleChain ruleChain = findRuleChainById(tenantId, ruleChainId);
    Edge edge = edgeService.findEdgeById(tenantId, edgeId);
    if (edge == null) {
        throw new DataValidationException("Can't unassign rule chain from non-existent edge!");
    }
    if (!remove && edge.getRootRuleChainId() != null && edge.getRootRuleChainId().equals(ruleChainId)) {
        throw new DataValidationException("Can't unassign root rule chain from edge [" + edge.getName() + "]. Please assign another root rule chain first!");
    }
    try {
        deleteRelation(tenantId, new EntityRelation(edgeId, ruleChainId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
    } catch (Exception e) {
        log.warn("[{}] Failed to delete rule chain relation. Edge Id: [{}]", ruleChainId, edgeId);
        throw new RuntimeException(e);
    }
    return ruleChain;
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) Edge(org.thingsboard.server.common.data.edge.Edge) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Aggregations

Edge (org.thingsboard.server.common.data.edge.Edge)98 Test (org.junit.Test)46 EdgeId (org.thingsboard.server.common.data.id.EdgeId)32 PageLink (org.thingsboard.server.common.data.page.PageLink)31 ArrayList (java.util.ArrayList)25 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)25 ApiOperation (io.swagger.annotations.ApiOperation)23 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)22 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)22 CustomerId (org.thingsboard.server.common.data.id.CustomerId)21 Customer (org.thingsboard.server.common.data.Customer)20 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)20 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)16 TypeReference (com.fasterxml.jackson.core.type.TypeReference)15 TenantId (org.thingsboard.server.common.data.id.TenantId)14 Device (org.thingsboard.server.common.data.Device)13 Asset (org.thingsboard.server.common.data.asset.Asset)13 PageData (org.thingsboard.server.common.data.page.PageData)13