use of org.thingsboard.server.common.data.widget.WidgetType in project thingsboard by thingsboard.
the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithInvalidBundleAlias.
@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithInvalidBundleAlias() throws IOException {
WidgetType widgetType = new WidgetType();
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.WidgetType in project thingsboard by thingsboard.
the class JpaWidgetTypeDaoTest method testFindByTenantIdAndBundleAlias.
@Test
@DatabaseSetup(("classpath:dbunit/widget_type.xml"))
public void testFindByTenantIdAndBundleAlias() {
UUID tenantId = UUID.fromString("2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833");
List<WidgetType> widgetTypes = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId, "BUNDLE_ALIAS_1");
assertEquals(3, widgetTypes.size());
}
use of org.thingsboard.server.common.data.widget.WidgetType 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);
}
});
}
}
use of org.thingsboard.server.common.data.widget.WidgetType in project thingsboard by thingsboard.
the class WidgetTypeController method getWidgetType.
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/widgetType", params = { "isSystem", "bundleAlias", "alias" }, method = RequestMethod.GET)
@ResponseBody
public WidgetType getWidgetType(@RequestParam boolean isSystem, @RequestParam String bundleAlias, @RequestParam String alias) throws ThingsboardException {
try {
TenantId tenantId;
if (isSystem) {
tenantId = new TenantId(ModelConstants.NULL_UUID);
} else {
tenantId = getCurrentUser().getTenantId();
}
WidgetType widgetType = widgetTypeService.findWidgetTypeByTenantIdBundleAliasAndAlias(tenantId, bundleAlias, alias);
checkWidgetType(widgetType, false);
return widgetType;
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.widget.WidgetType in project thingsboard by thingsboard.
the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithEmptyBundleAlias.
@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithEmptyBundleAlias() throws IOException {
WidgetType widgetType = new WidgetType();
widgetType.setTenantId(tenantId);
widgetType.setName("Widget Type");
widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
widgetTypeService.saveWidgetType(widgetType);
}
Aggregations