use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.
the class JpaBaseComponentDescriptorDaoTest method findByTypeAndSocpe.
@Test
public void findByTypeAndSocpe() {
for (int i = 0; i < 20; i++) {
createComponentDescriptor(ComponentType.PLUGIN, ComponentScope.SYSTEM, i);
createComponentDescriptor(ComponentType.ACTION, ComponentScope.TENANT, i + 20);
createComponentDescriptor(ComponentType.FILTER, ComponentScope.SYSTEM, i + 40);
}
TextPageLink pageLink1 = new TextPageLink(15, "COMPONENT_");
List<ComponentDescriptor> components1 = componentDescriptorDao.findByScopeAndTypeAndPageLink(ComponentScope.SYSTEM, ComponentType.FILTER, pageLink1);
assertEquals(15, components1.size());
TextPageLink pageLink2 = new TextPageLink(15, "COMPONENT_", components1.get(14).getId().getId(), null);
List<ComponentDescriptor> components2 = componentDescriptorDao.findByScopeAndTypeAndPageLink(ComponentScope.SYSTEM, ComponentType.FILTER, pageLink2);
assertEquals(5, components2.size());
}
use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.
the class JpaBaseComponentDescriptorDaoTest method findByType.
@Test
public void findByType() {
for (int i = 0; i < 20; i++) {
createComponentDescriptor(ComponentType.PLUGIN, ComponentScope.SYSTEM, i);
createComponentDescriptor(ComponentType.ACTION, ComponentScope.TENANT, i + 20);
}
TextPageLink pageLink1 = new TextPageLink(15, "COMPONENT_");
List<ComponentDescriptor> components1 = componentDescriptorDao.findByTypeAndPageLink(ComponentType.PLUGIN, pageLink1);
assertEquals(15, components1.size());
TextPageLink pageLink2 = new TextPageLink(15, "COMPONENT_", components1.get(14).getId().getId(), null);
List<ComponentDescriptor> components2 = componentDescriptorDao.findByTypeAndPageLink(ComponentType.PLUGIN, pageLink2);
assertEquals(5, components2.size());
}
use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.
the class BaseController method checkComponentDescriptorByClazz.
ComponentDescriptor checkComponentDescriptorByClazz(String clazz) throws ThingsboardException {
try {
log.debug("[{}] Lookup component descriptor", clazz);
ComponentDescriptor componentDescriptor = checkNotNull(componentDescriptorService.getComponent(clazz));
return componentDescriptor;
} catch (Exception e) {
throw handleException(e, false);
}
}
use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.
the class AbstractContextAwareMsgProcessor method initComponent.
protected <T extends ConfigurableComponent> T initComponent(JsonNode componentNode) throws Exception {
ComponentConfiguration configuration = new ComponentConfiguration(componentNode.get("clazz").asText(), componentNode.get("name").asText(), mapper.writeValueAsString(componentNode.get("configuration")));
logger.info("Initializing [{}][{}] component", configuration.getName(), configuration.getClazz());
ComponentDescriptor componentDescriptor = systemContext.getComponentService().getComponent(configuration.getClazz()).orElseThrow(() -> new InstantiationException("Component Not found!"));
return initComponent(componentDescriptor, configuration);
}
use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.
the class BaseRuleService method validateComponentJson.
private void validateComponentJson(JsonNode json, ComponentType type) {
if (json == null || json.isNull()) {
throw new IncorrectParameterException(type.name() + " is required!");
}
String clazz = getIfValid(type.name(), json, "clazz", JsonNode::isTextual, JsonNode::asText);
String name = getIfValid(type.name(), json, "name", JsonNode::isTextual, JsonNode::asText);
JsonNode configuration = getIfValid(type.name(), json, "configuration", JsonNode::isObject, node -> node);
ComponentDescriptor descriptor = componentDescriptorService.findByClazz(clazz);
if (descriptor == null) {
throw new IncorrectParameterException(type.name() + " clazz " + clazz + " is not a valid component!");
}
if (descriptor.getType() != type) {
throw new IncorrectParameterException("Clazz " + clazz + " is not a valid " + type.name() + " component!");
}
if (!componentDescriptorService.validate(descriptor, configuration)) {
throw new IncorrectParameterException(type.name() + " configuration is not valid!");
}
}
Aggregations