use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.
the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithEmptyName.
@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithEmptyName() throws IOException {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(tenantId);
widgetsBundle.setTitle("Widgets bundle");
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
WidgetTypeDetails widgetType = new WidgetTypeDetails();
widgetType.setTenantId(tenantId);
widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
try {
widgetTypeService.saveWidgetType(widgetType);
} finally {
widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
}
}
use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.
the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithInvalidBundleAlias.
@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithInvalidBundleAlias() throws IOException {
WidgetTypeDetails widgetType = new WidgetTypeDetails();
widgetType.setTenantId(tenantId);
widgetType.setBundleAlias("some_alias");
widgetType.setName("Widget Type");
widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
widgetTypeService.saveWidgetType(widgetType);
}
use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.
the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithEmptyDescriptor.
@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithEmptyDescriptor() throws IOException {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(tenantId);
widgetsBundle.setTitle("Widgets bundle");
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
WidgetTypeDetails widgetType = new WidgetTypeDetails();
widgetType.setTenantId(tenantId);
widgetType.setName("Widget Type");
widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
widgetType.setDescriptor(new ObjectMapper().readValue("{}", JsonNode.class));
try {
widgetTypeService.saveWidgetType(widgetType);
} finally {
widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
}
}
use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.
the class BaseWidgetTypeServiceTest method testDeleteWidgetType.
@Test
public void testDeleteWidgetType() throws IOException {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(tenantId);
widgetsBundle.setTitle("Widgets bundle");
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
WidgetTypeDetails widgetType = new WidgetTypeDetails();
widgetType.setTenantId(tenantId);
widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
widgetType.setName("Widget Type");
widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
WidgetType foundWidgetType = widgetTypeService.findWidgetTypeById(tenantId, savedWidgetType.getId());
Assert.assertNotNull(foundWidgetType);
widgetTypeService.deleteWidgetType(tenantId, savedWidgetType.getId());
foundWidgetType = widgetTypeService.findWidgetTypeById(tenantId, savedWidgetType.getId());
Assert.assertNull(foundWidgetType);
widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
}
use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.
the class InstallScripts method loadSystemWidgets.
public void loadSystemWidgets() throws Exception {
Path widgetBundlesDir = Paths.get(getDataDir(), 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 {
WidgetTypeDetails widgetTypeDetails = objectMapper.treeToValue(widgetTypeJson, WidgetTypeDetails.class);
widgetTypeDetails.setBundleAlias(savedWidgetsBundle.getAlias());
widgetTypeService.saveWidgetType(widgetTypeDetails);
} 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