Search in sources :

Example 6 with ComponentDescriptor

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());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 7 with ComponentDescriptor

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());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 8 with ComponentDescriptor

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);
    }
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Example 9 with ComponentDescriptor

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);
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor)

Example 10 with ComponentDescriptor

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!");
    }
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)19 Test (org.junit.Test)5 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ComponentDescriptorId (org.thingsboard.server.common.data.id.ComponentDescriptorId)3 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)2 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)2 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 List (java.util.List)1 MessagingException (javax.mail.MessagingException)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)1 Device (org.thingsboard.server.common.data.Device)1 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)1 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)1 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)1 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)1 ComponentType (org.thingsboard.server.common.data.plugin.ComponentType)1 DeviceCredentialsFilter (org.thingsboard.server.common.data.security.DeviceCredentialsFilter)1