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