Search in sources :

Example 26 with EntityRelation

use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.

the class BaseRelationServiceTest method testSaveRelationWithEmptyType.

@Test(expected = DataValidationException.class)
public void testSaveRelationWithEmptyType() throws ExecutionException, InterruptedException {
    EntityRelation relation = new EntityRelation();
    relation.setFrom(new AssetId(UUIDs.timeBased()));
    relation.setTo(new AssetId(UUIDs.timeBased()));
    Assert.assertTrue(saveRelation(relation));
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Example 27 with EntityRelation

use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.

the class BaseAlarmServiceTest method testFindAlarm.

@Test
public void testFindAlarm() throws ExecutionException, InterruptedException {
    AssetId parentId = new AssetId(UUIDs.timeBased());
    AssetId childId = new AssetId(UUIDs.timeBased());
    EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
    Assert.assertTrue(relationService.saveRelationAsync(relation).get());
    long ts = System.currentTimeMillis();
    Alarm alarm = Alarm.builder().tenantId(tenantId).originator(childId).type(TEST_ALARM).propagate(false).severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK).startTs(ts).build();
    Alarm created = alarmService.createOrUpdateAlarm(alarm);
    // Check child relation
    TimePageData<AlarmInfo> alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
    Assert.assertNotNull(alarms.getData());
    Assert.assertEquals(1, alarms.getData().size());
    Assert.assertEquals(created, alarms.getData().get(0));
    // Check parent relation
    alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(parentId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
    Assert.assertNotNull(alarms.getData());
    Assert.assertEquals(0, alarms.getData().size());
    created.setPropagate(true);
    created = alarmService.createOrUpdateAlarm(created);
    // Check child relation
    alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
    Assert.assertNotNull(alarms.getData());
    Assert.assertEquals(1, alarms.getData().size());
    Assert.assertEquals(created, alarms.getData().get(0));
    // Check parent relation
    alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(parentId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
    Assert.assertNotNull(alarms.getData());
    Assert.assertEquals(1, alarms.getData().size());
    Assert.assertEquals(created, alarms.getData().get(0));
    alarmService.ackAlarm(created.getId(), System.currentTimeMillis()).get();
    created = alarmService.findAlarmByIdAsync(created.getId()).get();
    alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.ACTIVE_ACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
    Assert.assertNotNull(alarms.getData());
    Assert.assertEquals(1, alarms.getData().size());
    Assert.assertEquals(created, alarms.getData().get(0));
    // Check not existing relation
    alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
    Assert.assertNotNull(alarms.getData());
    Assert.assertEquals(0, alarms.getData().size());
    alarmService.clearAlarm(created.getId(), System.currentTimeMillis()).get();
    created = alarmService.findAlarmByIdAsync(created.getId()).get();
    alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.CLEARED_ACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
    Assert.assertNotNull(alarms.getData());
    Assert.assertEquals(1, alarms.getData().size());
    Assert.assertEquals(created, alarms.getData().get(0));
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Example 28 with EntityRelation

use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.

the class RestClient method makeRelation.

public EntityRelation makeRelation(String relationType, EntityId idFrom, EntityId idTo) {
    EntityRelation relation = new EntityRelation();
    relation.setFrom(idFrom);
    relation.setTo(idTo);
    relation.setType(relationType);
    return restTemplate.postForEntity(baseURL + "/api/relation", relation, EntityRelation.class).getBody();
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation)

Aggregations

EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)28 AssetId (org.thingsboard.server.common.data.id.AssetId)13 Test (org.junit.Test)12 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)6 Futures (com.google.common.util.concurrent.Futures)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 Slf4j (lombok.extern.slf4j.Slf4j)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 EntityId (org.thingsboard.server.common.data.id.EntityId)6 List (java.util.List)5 ExecutionException (java.util.concurrent.ExecutionException)5 EntityType (org.thingsboard.server.common.data.EntityType)5 Function (com.google.common.base.Function)4 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)4 Component (org.springframework.stereotype.Component)4 CustomerId (org.thingsboard.server.common.data.id.CustomerId)4 TenantId (org.thingsboard.server.common.data.id.TenantId)4 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)4 RelationTypeGroup (org.thingsboard.server.common.data.relation.RelationTypeGroup)4