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;
}
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!");
}
}
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);
}
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;
}
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;
}
Aggregations