Search in sources :

Example 11 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class BasePluginService method savePlugin.

@Override
public PluginMetaData savePlugin(PluginMetaData plugin) {
    pluginValidator.validate(plugin);
    if (plugin.getTenantId() == null) {
        log.trace("Save system plugin metadata with predefined id {}", SYSTEM_TENANT);
        plugin.setTenantId(SYSTEM_TENANT);
    }
    if (plugin.getId() != null) {
        PluginMetaData oldVersion = pluginDao.findById(plugin.getId());
        if (plugin.getState() == null) {
            plugin.setState(oldVersion.getState());
        } else if (plugin.getState() != oldVersion.getState()) {
            throw new IncorrectParameterException("Use Activate/Suspend method to control state of the plugin!");
        }
    } else {
        if (plugin.getState() == null) {
            plugin.setState(ComponentLifecycleState.SUSPENDED);
        } else if (plugin.getState() != ComponentLifecycleState.SUSPENDED) {
            throw new IncorrectParameterException("Use Activate/Suspend method to control state of the plugin!");
        }
    }
    ComponentDescriptor descriptor = componentDescriptorService.findByClazz(plugin.getClazz());
    if (descriptor == null) {
        throw new IncorrectParameterException("Plugin descriptor not found!");
    } else if (!ComponentType.PLUGIN.equals(descriptor.getType())) {
        throw new IncorrectParameterException("Plugin class is actually " + descriptor.getType() + "!");
    }
    PluginMetaData savedPlugin = pluginDao.findByApiToken(plugin.getApiToken());
    if (savedPlugin != null && (plugin.getId() == null || !savedPlugin.getId().getId().equals(plugin.getId().getId()))) {
        throw new IncorrectParameterException("API token is already reserved!");
    }
    if (!componentDescriptorService.validate(descriptor, plugin.getConfiguration())) {
        throw new IncorrectParameterException("Filters configuration is not valid!");
    }
    return pluginDao.save(plugin);
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData)

Example 12 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class ComponentDescriptorEntity method toData.

@Override
public ComponentDescriptor toData() {
    ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(this.getId()));
    data.setType(type);
    data.setScope(scope);
    data.setName(this.getName());
    data.setClazz(this.getClazz());
    data.setActions(this.getActions());
    data.setConfigurationDescriptor(configurationDescriptor);
    return data;
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) ComponentDescriptorId(org.thingsboard.server.common.data.id.ComponentDescriptorId)

Example 13 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class ComponentDescriptorEntity method toData.

@Override
public ComponentDescriptor toData() {
    ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(id));
    data.setType(type);
    data.setScope(scope);
    data.setName(this.getName());
    data.setClazz(this.getClazz());
    data.setActions(this.getActions());
    data.setConfigurationDescriptor(this.getConfigurationDescriptor());
    return data;
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) ComponentDescriptorId(org.thingsboard.server.common.data.id.ComponentDescriptorId)

Example 14 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class CassandraBaseComponentDescriptorDao method saveIfNotExist.

@Override
public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) {
    ComponentDescriptorEntity entity = new ComponentDescriptorEntity(component);
    log.debug("Save component entity [{}]", entity);
    Optional<ComponentDescriptor> result = saveIfNotExist(entity);
    if (log.isTraceEnabled()) {
        log.trace("Saved result: [{}] for component entity [{}]", result.isPresent(), result.orElse(null));
    } else {
        log.debug("Saved result: [{}]", result.isPresent());
    }
    return result;
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) ComponentDescriptorEntity(org.thingsboard.server.dao.model.nosql.ComponentDescriptorEntity)

Example 15 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class AbstractServiceTest method getOrCreateDescriptor.

private ComponentDescriptor getOrCreateDescriptor(ComponentScope scope, ComponentType type, String clazz, String configurationDescriptorResource, String actions) throws IOException {
    ComponentDescriptor descriptor = componentDescriptorService.findByClazz(clazz);
    if (descriptor == null) {
        descriptor = new ComponentDescriptor();
        descriptor.setName("test");
        descriptor.setClazz(clazz);
        descriptor.setScope(scope);
        descriptor.setType(type);
        descriptor.setActions(actions);
        descriptor.setConfigurationDescriptor(readFromResource(configurationDescriptorResource));
        componentDescriptorService.saveComponent(descriptor);
    }
    return descriptor;
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor)

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