use of org.thingsboard.server.common.data.relation.EntityRelationsQuery in project thingsboard by thingsboard.
the class BaseRelationServiceTest method testCyclicRecursiveRelation.
@Test
public void testCyclicRecursiveRelation() throws ExecutionException, InterruptedException {
// A -> B -> C -> A
AssetId assetA = new AssetId(UUIDs.timeBased());
AssetId assetB = new AssetId(UUIDs.timeBased());
AssetId assetC = new AssetId(UUIDs.timeBased());
EntityRelation relationA = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);
EntityRelation relationB = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);
EntityRelation relationC = new EntityRelation(assetC, assetA, EntityRelation.CONTAINS_TYPE);
saveRelation(relationA);
saveRelation(relationB);
saveRelation(relationC);
EntityRelationsQuery query = new EntityRelationsQuery();
query.setParameters(new RelationsSearchParameters(assetA, EntitySearchDirection.FROM, -1));
query.setFilters(Collections.singletonList(new EntityTypeFilter(EntityRelation.CONTAINS_TYPE, Collections.singletonList(EntityType.ASSET))));
List<EntityRelation> relations = relationService.findByQuery(query).get();
Assert.assertEquals(3, relations.size());
Assert.assertTrue(relations.contains(relationA));
Assert.assertTrue(relations.contains(relationB));
Assert.assertTrue(relations.contains(relationC));
}
use of org.thingsboard.server.common.data.relation.EntityRelationsQuery in project thingsboard by thingsboard.
the class BaseAlarmService method createAlarmRelations.
private void createAlarmRelations(Alarm alarm) throws InterruptedException, ExecutionException {
if (alarm.isPropagate()) {
EntityRelationsQuery query = new EntityRelationsQuery();
query.setParameters(new RelationsSearchParameters(alarm.getOriginator(), EntitySearchDirection.TO, Integer.MAX_VALUE));
List<EntityId> parentEntities = relationService.findByQuery(query).get().stream().map(r -> r.getFrom()).collect(Collectors.toList());
for (EntityId parentId : parentEntities) {
createAlarmRelation(parentId, alarm.getId(), alarm.getStatus(), true);
}
}
createAlarmRelation(alarm.getOriginator(), alarm.getId(), alarm.getStatus(), true);
}
use of org.thingsboard.server.common.data.relation.EntityRelationsQuery in project thingsboard by thingsboard.
the class AssetSearchQuery method toEntitySearchQuery.
public EntityRelationsQuery toEntitySearchQuery() {
EntityRelationsQuery query = new EntityRelationsQuery();
query.setParameters(parameters);
query.setFilters(Collections.singletonList(new EntityTypeFilter(relationType == null ? EntityRelation.CONTAINS_TYPE : relationType, Collections.singletonList(EntityType.ASSET))));
return query;
}
use of org.thingsboard.server.common.data.relation.EntityRelationsQuery in project thingsboard by thingsboard.
the class DeviceSearchQuery method toEntitySearchQuery.
public EntityRelationsQuery toEntitySearchQuery() {
EntityRelationsQuery query = new EntityRelationsQuery();
query.setParameters(parameters);
query.setFilters(Collections.singletonList(new EntityTypeFilter(relationType == null ? EntityRelation.CONTAINS_TYPE : relationType, Collections.singletonList(EntityType.DEVICE))));
return query;
}
use of org.thingsboard.server.common.data.relation.EntityRelationsQuery in project thingsboard by thingsboard.
the class BaseRelationServiceTest method testRecursiveRelation.
@Test
public void testRecursiveRelation() throws ExecutionException, InterruptedException {
// A -> B -> [C,D]
AssetId assetA = new AssetId(UUIDs.timeBased());
AssetId assetB = new AssetId(UUIDs.timeBased());
AssetId assetC = new AssetId(UUIDs.timeBased());
DeviceId deviceD = new DeviceId(UUIDs.timeBased());
EntityRelation relationAB = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);
EntityRelation relationBC = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);
EntityRelation relationBD = new EntityRelation(assetB, deviceD, EntityRelation.CONTAINS_TYPE);
saveRelation(relationAB);
saveRelation(relationBC);
saveRelation(relationBD);
EntityRelationsQuery query = new EntityRelationsQuery();
query.setParameters(new RelationsSearchParameters(assetA, EntitySearchDirection.FROM, -1));
query.setFilters(Collections.singletonList(new EntityTypeFilter(EntityRelation.CONTAINS_TYPE, Collections.singletonList(EntityType.ASSET))));
List<EntityRelation> relations = relationService.findByQuery(query).get();
Assert.assertEquals(2, relations.size());
Assert.assertTrue(relations.contains(relationAB));
Assert.assertTrue(relations.contains(relationBC));
}
Aggregations