Search in sources :

Example 11 with EntityView

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

the class EntityViewServiceImpl method deleteEntityView.

@CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}")
@Override
public void deleteEntityView(TenantId tenantId, EntityViewId entityViewId) {
    log.trace("Executing deleteEntityView [{}]", entityViewId);
    validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId);
    deleteEntityRelations(tenantId, entityViewId);
    EntityView entityView = entityViewDao.findById(tenantId, entityViewId.getId());
    cacheManager.getCache(ENTITY_VIEW_CACHE).evict(Arrays.asList(entityView.getTenantId(), entityView.getEntityId()));
    cacheManager.getCache(ENTITY_VIEW_CACHE).evict(Arrays.asList(entityView.getTenantId(), entityView.getName()));
    entityViewDao.removeById(tenantId, entityViewId.getId());
}
Also used : EntityView(org.thingsboard.server.common.data.EntityView) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 12 with EntityView

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

the class EntityViewServiceImpl method unassignEntityViewFromEdge.

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

Example 13 with EntityView

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

the class EntityViewServiceImpl method unassignEntityViewFromCustomer.

@CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}")
@Override
public EntityView unassignEntityViewFromCustomer(TenantId tenantId, EntityViewId entityViewId) {
    EntityView entityView = findEntityViewById(tenantId, entityViewId);
    entityView.setCustomerId(null);
    return saveEntityView(entityView);
}
Also used : EntityView(org.thingsboard.server.common.data.EntityView) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 14 with EntityView

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

the class EntityViewServiceImpl method assignEntityViewToEdge.

@CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}")
@Override
public EntityView assignEntityViewToEdge(TenantId tenantId, EntityViewId entityViewId, EdgeId edgeId) {
    EntityView entityView = findEntityViewById(tenantId, entityViewId);
    Edge edge = edgeService.findEdgeById(tenantId, edgeId);
    if (edge == null) {
        throw new DataValidationException("Can't assign entityView to non-existent edge!");
    }
    if (!edge.getTenantId().getId().equals(entityView.getTenantId().getId())) {
        throw new DataValidationException("Can't assign entityView to edge from different tenant!");
    }
    try {
        Boolean relationExists = relationService.checkRelation(tenantId, edgeId, entityView.getEntityId(), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE).get();
        if (!relationExists) {
            throw new DataValidationException("Can't assign entity view to edge because related device/asset doesn't assigned to edge!");
        }
    } catch (ExecutionException | InterruptedException e) {
        log.error("Exception during relation check", e);
        throw new RuntimeException("Exception during relation check", e);
    }
    try {
        createRelation(tenantId, new EntityRelation(edgeId, entityViewId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
    } catch (Exception e) {
        log.warn("[{}] Failed to create entityView relation. Edge Id: [{}]", entityViewId, edgeId);
        throw new RuntimeException(e);
    }
    return entityView;
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) EntityView(org.thingsboard.server.common.data.EntityView) ExecutionException(java.util.concurrent.ExecutionException) Edge(org.thingsboard.server.common.data.edge.Edge) ExecutionException(java.util.concurrent.ExecutionException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 15 with EntityView

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

the class BaseTimeseriesServiceTest method testFindByQueryAscOrder.

@Test
public void testFindByQueryAscOrder() throws Exception {
    DeviceId deviceId = new DeviceId(Uuids.timeBased());
    saveEntries(deviceId, TS - 3);
    saveEntries(deviceId, TS - 2);
    saveEntries(deviceId, TS - 1);
    List<ReadTsKvQuery> queries = new ArrayList<>();
    queries.add(new BaseReadTsKvQuery(STRING_KEY, TS - 3, TS, 0, 1000, Aggregation.NONE, "ASC"));
    List<TsKvEntry> entries = tsService.findAll(tenantId, deviceId, queries).get(MAX_TIMEOUT, TimeUnit.SECONDS);
    Assert.assertEquals(3, entries.size());
    Assert.assertEquals(toTsEntry(TS - 3, stringKvEntry), entries.get(0));
    Assert.assertEquals(toTsEntry(TS - 2, stringKvEntry), entries.get(1));
    Assert.assertEquals(toTsEntry(TS - 1, stringKvEntry), entries.get(2));
    EntityView entityView = saveAndCreateEntityView(deviceId, Arrays.asList(STRING_KEY));
    entries = tsService.findAll(tenantId, entityView.getId(), queries).get(MAX_TIMEOUT, TimeUnit.SECONDS);
    Assert.assertEquals(3, entries.size());
    Assert.assertEquals(toTsEntry(TS - 3, stringKvEntry), entries.get(0));
    Assert.assertEquals(toTsEntry(TS - 2, stringKvEntry), entries.get(1));
    Assert.assertEquals(toTsEntry(TS - 1, stringKvEntry), entries.get(2));
}
Also used : BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ArrayList(java.util.ArrayList) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

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