use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.
the class BaseWidgetsBundleServiceTest method testFindWidgetsBundleByTenantIdAndAlias.
@Test
public void testFindWidgetsBundleByTenantIdAndAlias() {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(tenantId);
widgetsBundle.setTitle("My widgets bundle");
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
WidgetsBundle foundWidgetsBundle = widgetsBundleService.findWidgetsBundleByTenantIdAndAlias(tenantId, savedWidgetsBundle.getAlias());
Assert.assertNotNull(foundWidgetsBundle);
Assert.assertEquals(savedWidgetsBundle, foundWidgetsBundle);
widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
}
use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.
the class BaseWidgetsBundleServiceTest method testFindAllWidgetsBundlesByTenantId.
@Test
public void testFindAllWidgetsBundlesByTenantId() {
List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles();
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
TenantId systemTenantId = new TenantId(ModelConstants.NULL_UUID);
List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
List<WidgetsBundle> createdSystemWidgetsBundles = new ArrayList<>();
for (int i = 0; i < 277; i++) {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(i % 2 == 0 ? tenantId : systemTenantId);
widgetsBundle.setTitle((i % 2 == 0 ? "Widgets bundle " : "System widget bundle ") + i);
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
createdWidgetsBundles.add(savedWidgetsBundle);
if (i % 2 == 1) {
createdSystemWidgetsBundles.add(savedWidgetsBundle);
}
}
List<WidgetsBundle> widgetsBundles = new ArrayList<>(createdWidgetsBundles);
widgetsBundles.addAll(systemWidgetsBundles);
List<WidgetsBundle> loadedWidgetsBundles = widgetsBundleService.findAllTenantWidgetsBundlesByTenantId(tenantId);
Collections.sort(widgetsBundles, idComparator);
Collections.sort(loadedWidgetsBundles, idComparator);
Assert.assertEquals(widgetsBundles, loadedWidgetsBundles);
widgetsBundleService.deleteWidgetsBundlesByTenantId(tenantId);
loadedWidgetsBundles = widgetsBundleService.findAllTenantWidgetsBundlesByTenantId(tenantId);
List<WidgetsBundle> allSystemWidgetsBundles = new ArrayList<>(systemWidgetsBundles);
allSystemWidgetsBundles.addAll(createdSystemWidgetsBundles);
Collections.sort(allSystemWidgetsBundles, idComparator);
Collections.sort(loadedWidgetsBundles, idComparator);
Assert.assertEquals(allSystemWidgetsBundles, loadedWidgetsBundles);
for (WidgetsBundle widgetsBundle : createdSystemWidgetsBundles) {
widgetsBundleService.deleteWidgetsBundle(widgetsBundle.getId());
}
loadedWidgetsBundles = widgetsBundleService.findAllTenantWidgetsBundlesByTenantId(tenantId);
Collections.sort(systemWidgetsBundles, idComparator);
Collections.sort(loadedWidgetsBundles, idComparator);
Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles);
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.
the class JpaWidgetsBundleDaoTest method testSearchTextNotFound.
@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
@DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml", type = DatabaseOperation.DELETE_ALL)
public void testSearchTextNotFound() {
UUID tenantId = UUIDs.timeBased();
createWidgetBundles(5, tenantId, "ABC_");
createSystemWidgetBundles(5, "SYS_");
TextPageLink textPageLink = new TextPageLink(30, "TEXT_NOT_FOUND");
List<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId, textPageLink);
assertEquals(0, widgetsBundles4.size());
}
use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.
the class JpaWidgetsBundleDaoTest method testFindAllWidgetsBundlesByTenantId.
@Test
@DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type = DatabaseOperation.DELETE_ALL)
public void testFindAllWidgetsBundlesByTenantId() {
UUID tenantId1 = UUIDs.timeBased();
UUID tenantId2 = UUIDs.timeBased();
// Create a bunch of widgetBundles
for (int i = 0; i < 10; i++) {
createWidgetBundles(5, tenantId1, "WB1_");
createWidgetBundles(3, tenantId2, "WB2_");
createSystemWidgetBundles(2, "WB_SYS_");
}
TextPageLink textPageLink1 = new TextPageLink(30, "WB");
List<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, textPageLink1);
assertEquals(30, widgetsBundles1.size());
TextPageLink textPageLink2 = new TextPageLink(30, "WB", widgetsBundles1.get(29).getId().getId(), null);
List<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, textPageLink2);
assertEquals(30, widgetsBundles2.size());
TextPageLink textPageLink3 = new TextPageLink(30, "WB", widgetsBundles2.get(29).getId().getId(), null);
List<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, textPageLink3);
assertEquals(10, widgetsBundles3.size());
TextPageLink textPageLink4 = new TextPageLink(30, "WB", widgetsBundles3.get(9).getId().getId(), null);
List<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, textPageLink4);
assertEquals(0, widgetsBundles4.size());
}
use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.
the class DefaultSystemDataLoaderService method loadSystemWidgets.
@Override
public void loadSystemWidgets() throws Exception {
Path widgetBundlesDir = Paths.get(dataDir, JSON_DIR, SYSTEM_DIR, WIDGET_BUNDLES_DIR);
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(widgetBundlesDir, path -> path.toString().endsWith(JSON_EXT))) {
dirStream.forEach(path -> {
try {
JsonNode widgetsBundleDescriptorJson = objectMapper.readTree(path.toFile());
JsonNode widgetsBundleJson = widgetsBundleDescriptorJson.get("widgetsBundle");
WidgetsBundle widgetsBundle = objectMapper.treeToValue(widgetsBundleJson, WidgetsBundle.class);
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
JsonNode widgetTypesArrayJson = widgetsBundleDescriptorJson.get("widgetTypes");
widgetTypesArrayJson.forEach(widgetTypeJson -> {
try {
WidgetType widgetType = objectMapper.treeToValue(widgetTypeJson, WidgetType.class);
widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
widgetTypeService.saveWidgetType(widgetType);
} catch (Exception e) {
log.error("Unable to load widget type from json: [{}]", path.toString());
throw new RuntimeException("Unable to load widget type from json", e);
}
});
} catch (Exception e) {
log.error("Unable to load widgets bundle from json: [{}]", path.toString());
throw new RuntimeException("Unable to load widgets bundle from json", e);
}
});
}
}
Aggregations