Search in sources :

Example 31 with PluginMetaData

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

the class BasePluginService method findSystemPlugins.

@Override
public List<PluginMetaData> findSystemPlugins() {
    log.trace("Executing findSystemPlugins");
    List<PluginMetaData> plugins = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(300);
    TextPageData<PluginMetaData> pageData = null;
    do {
        pageData = findSystemPlugins(pageLink);
        plugins.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    return plugins;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ArrayList(java.util.ArrayList)

Example 32 with PluginMetaData

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

the class BasePluginService method updateLifeCycleState.

private void updateLifeCycleState(PluginId pluginId, ComponentLifecycleState state) {
    Validator.validateId(pluginId, "Incorrect plugin id for state change request.");
    PluginMetaData plugin = pluginDao.findById(pluginId);
    if (plugin != null) {
        plugin.setState(state);
        pluginDao.save(plugin);
    } else {
        throw new DatabaseException("Plugin not found!");
    }
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) DatabaseException(org.thingsboard.server.dao.exception.DatabaseException)

Example 33 with PluginMetaData

use of org.thingsboard.server.common.data.plugin.PluginMetaData 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 34 with PluginMetaData

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

the class BasePluginService method findAllTenantPluginsByTenantId.

@Override
public List<PluginMetaData> findAllTenantPluginsByTenantId(TenantId tenantId) {
    log.trace("Executing findAllTenantPluginsByTenantId, tenantId [{}]", tenantId);
    Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
    List<PluginMetaData> plugins = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(300);
    TextPageData<PluginMetaData> pageData = null;
    do {
        pageData = findAllTenantPluginsByTenantIdAndPageLink(tenantId, pageLink);
        plugins.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    return plugins;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ArrayList(java.util.ArrayList)

Example 35 with PluginMetaData

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

the class PluginMetaDataEntity method toData.

@Override
public PluginMetaData toData() {
    PluginMetaData data = new PluginMetaData(new PluginId(id));
    data.setTenantId(new TenantId(tenantId));
    data.setCreatedTime(UUIDs.unixTimestamp(id));
    data.setName(name);
    data.setConfiguration(configuration);
    data.setClazz(clazz);
    data.setPublicAccess(publicAccess);
    data.setState(state);
    data.setApiToken(apiToken);
    data.setAdditionalInfo(additionalInfo);
    return data;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) PluginId(org.thingsboard.server.common.data.id.PluginId)

Aggregations

PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)50 Test (org.junit.Test)24 TenantId (org.thingsboard.server.common.data.id.TenantId)17 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)14 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)13 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)13 PluginId (org.thingsboard.server.common.data.id.PluginId)8 TelemetryStoragePlugin (org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 ArrayList (java.util.ArrayList)4 TextPageData (org.thingsboard.server.common.data.page.TextPageData)4 List (java.util.List)3 UUID (java.util.UUID)3 Before (org.junit.Before)3 Tenant (org.thingsboard.server.common.data.Tenant)3 ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)3 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2