use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class ConnectionPageNetwork method createHandlerTab.
private void createHandlerTab(final NetworkHandlerDescriptor descriptor) throws DBException {
IObjectPropertyConfigurator<DBWHandlerConfiguration> configurator;
try {
String implName = descriptor.getHandlerType().getImplName();
UIPropertyConfiguratorDescriptor configDescriptor = UIPropertyConfiguratorRegistry.getInstance().getDescriptor(implName);
if (configDescriptor == null) {
return;
}
configurator = configDescriptor.createConfigurator();
} catch (DBException e) {
log.error("Can't create network configurator '" + descriptor.getId() + "'", e);
return;
}
TabItem tabItem = new TabItem(handlersFolder, SWT.NONE);
tabItem.setText(descriptor.getLabel());
tabItem.setToolTipText(descriptor.getDescription());
Composite composite = new Composite(handlersFolder, SWT.NONE);
tabItem.setControl(composite);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
final Button useHandlerCheck = UIUtils.createCheckbox(composite, NLS.bind(CoreMessages.dialog_tunnel_checkbox_use_handler, descriptor.getLabel()), false);
useHandlerCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
HandlerBlock handlerBlock = configurations.get(descriptor);
DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(wizard.getPageSettings().getActiveDataSource().getId());
handlerConfiguration.setEnabled(useHandlerCheck.getSelection());
enableHandlerContent(descriptor);
}
});
Composite handlerComposite = UIUtils.createComposite(composite, 1);
configurations.put(descriptor, new HandlerBlock(configurator, handlerComposite, useHandlerCheck, tabItem));
handlerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
configurator.createControl(handlerComposite, this::updatePageCompletion);
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class ConnectionPageNetwork method activatePage.
@Override
public void activatePage() {
DataSourceDescriptor dataSource = wizard.getPageSettings().getActiveDataSource();
DBPDriver driver = wizard.getSelectedDriver();
NetworkHandlerRegistry registry = NetworkHandlerRegistry.getInstance();
if (prevDataSource == null || prevDataSource != dataSource) {
for (TabItem item : handlersFolder.getItems()) {
item.dispose();
}
for (NetworkHandlerDescriptor descriptor : registry.getDescriptors(dataSource)) {
try {
createHandlerTab(descriptor);
} catch (DBException e) {
log.warn(e);
}
}
prevDataSource = dataSource;
handlersFolder.layout(true, true);
// for (TabItem item : handlersFolder.getItems()) {
// ((Composite)item.getControl()).layout(false);
// }
}
TabItem selectItem = null;
for (NetworkHandlerDescriptor descriptor : registry.getDescriptors(dataSource)) {
DBWHandlerConfiguration configuration = dataSource.getConnectionConfiguration().getHandler(descriptor.getId());
if (configuration == null) {
configuration = new DBWHandlerConfiguration(descriptor, dataSource);
}
HandlerBlock handlerBlock = configurations.get(descriptor);
if (handlerBlock == null) {
continue;
}
// handlerBlock.useHandlerCheck.setSelection(configuration.isEnabled());
if (selectItem == null && configuration.isEnabled()) {
selectItem = handlerBlock.tabItem;
}
if (!handlerBlock.loadedConfigs.containsKey(dataSource.getId())) {
handlerBlock.configurator.loadSettings(configuration);
handlerBlock.loadedConfigs.put(dataSource.getId(), configuration);
}
enableHandlerContent(descriptor);
}
if (selectItem != null) {
handlersFolder.setSelection(selectItem);
} else {
handlersFolder.setSelection(0);
}
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class DataSourceSerializerModern method parseDataSources.
@Override
public void parseDataSources(File configFile, DBPDataSourceConfigurationStorage configurationStorage, boolean refresh, DataSourceRegistry.ParseResults parseResults) throws IOException {
// Read secured creds file
File mdFolder = registry.getProject().getMetadataFolder(false);
if (mdFolder.exists()) {
File credFile = new File(mdFolder, DBPDataSourceRegistry.CREDENTIALS_CONFIG_FILE_PREFIX + configurationStorage.getConfigurationFileSuffix() + DBPDataSourceRegistry.CREDENTIALS_CONFIG_FILE_EXT);
if (credFile.exists()) {
try {
String credJson = loadConfigFile(credFile, true);
Map<String, Map<String, Map<String, String>>> res = CONFIG_GSON.fromJson(credJson, new TypeToken<Map<String, Map<String, Map<String, String>>>>() {
}.getType());
secureProperties.putAll(res);
} catch (Exception e) {
log.error("Error decrypting secure credentials", e);
}
}
}
boolean decryptProject = CommonUtils.toBoolean(registry.getProject().getProjectProperty(DBPProject.PROP_SECURE_PROJECT));
String configJson = loadConfigFile(configFile, decryptProject);
{
Map<String, Object> jsonMap = JSONUtils.parseMap(CONFIG_GSON, new StringReader(configJson));
// Folders
for (Map.Entry<String, Map<String, Object>> folderMap : JSONUtils.getNestedObjects(jsonMap, "folders")) {
String name = folderMap.getKey();
String description = JSONUtils.getObjectProperty(folderMap.getValue(), RegistryConstants.ATTR_DESCRIPTION);
String parentFolder = JSONUtils.getObjectProperty(folderMap.getValue(), RegistryConstants.ATTR_PARENT);
DataSourceFolder parent = parentFolder == null ? null : registry.findFolderByPath(parentFolder, true);
DataSourceFolder folder = parent == null ? registry.findFolderByPath(name, true) : parent.getChild(name);
if (folder == null) {
folder = new DataSourceFolder(registry, parent, name, description);
registry.addDataSourceFolder(folder);
} else {
folder.setDescription(description);
}
}
// Connection types
for (Map.Entry<String, Map<String, Object>> ctMap : JSONUtils.getNestedObjects(jsonMap, "connection-types")) {
String id = ctMap.getKey();
Map<String, Object> ctConfig = ctMap.getValue();
String name = JSONUtils.getObjectProperty(ctConfig, RegistryConstants.ATTR_NAME);
String description = JSONUtils.getObjectProperty(ctConfig, RegistryConstants.ATTR_DESCRIPTION);
String color = JSONUtils.getObjectProperty(ctConfig, RegistryConstants.ATTR_COLOR);
Boolean autoCommit = JSONUtils.getObjectProperty(ctConfig, "auto-commit");
Boolean confirmExecute = JSONUtils.getObjectProperty(ctConfig, "confirm-execute");
Boolean confirmDataChange = JSONUtils.getObjectProperty(ctConfig, "confirm-data-change");
DBPConnectionType ct = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getConnectionType(id, null);
if (ct == null) {
ct = new DBPConnectionType(id, name, color, description, CommonUtils.toBoolean(autoCommit), CommonUtils.toBoolean(confirmExecute), CommonUtils.toBoolean(confirmDataChange));
DBWorkbench.getPlatform().getDataSourceProviderRegistry().addConnectionType(ct);
}
deserializeModifyPermissions(ctConfig, ct);
}
// Drivers
// TODO: add drivers deserialization
// Virtual models
Map<String, DBVModel> modelMap = new LinkedHashMap<>();
for (Map.Entry<String, Map<String, Object>> vmMap : JSONUtils.getNestedObjects(jsonMap, "virtual-models")) {
String id = vmMap.getKey();
DBVModel model = new DBVModel(id, vmMap.getValue());
modelMap.put(id, model);
}
// Network profiles
for (Map.Entry<String, Map<String, Object>> vmMap : JSONUtils.getNestedObjects(jsonMap, "network-profiles")) {
String profileId = vmMap.getKey();
Map<String, Object> profileMap = vmMap.getValue();
DBWNetworkProfile profile = new DBWNetworkProfile();
profile.setProfileName(profileId);
profile.setProfileName(profileId);
profile.setProperties(JSONUtils.deserializeStringMap(profileMap, "properties"));
for (Map.Entry<String, Map<String, Object>> handlerMap : JSONUtils.getNestedObjects(profileMap, "handlers")) {
DBWHandlerConfiguration configuration = parseNetworkHandlerConfig(null, profile, handlerMap);
if (configuration != null) {
profile.updateConfiguration(configuration);
}
}
registry.updateNetworkProfile(profile);
}
// Auth profiles
for (Map.Entry<String, Map<String, Object>> vmMap : JSONUtils.getNestedObjects(jsonMap, "auth-profiles")) {
String profileId = vmMap.getKey();
Map<String, Object> profileMap = vmMap.getValue();
DBAAuthProfile profile = new DBAAuthProfile();
profile.setProfileId(profileId);
profile.setProfileName(JSONUtils.getString(profileMap, RegistryConstants.ATTR_NAME));
profile.setAuthModelId(JSONUtils.getString(profileMap, RegistryConstants.ATTR_AUTH_MODEL));
profile.setSavePassword(JSONUtils.getBoolean(profileMap, RegistryConstants.ATTR_SAVE_PASSWORD));
SecureCredentials authCreds = readSecuredCredentials(null, profile, null);
profile.setUserName(authCreds.getUserName());
profile.setUserPassword(authCreds.getUserPassword());
profile.setProperties(authCreds.getProperties());
registry.updateAuthProfile(profile);
}
// Connections
for (Map.Entry<String, Map<String, Object>> conMap : JSONUtils.getNestedObjects(jsonMap, "connections")) {
Map<String, Object> conObject = conMap.getValue();
// Primary settings
String id = conMap.getKey();
String dsProviderID = CommonUtils.toString(conObject.get(RegistryConstants.ATTR_PROVIDER));
if (CommonUtils.isEmpty(dsProviderID)) {
log.warn("Empty datasource provider for datasource '" + id + "'");
continue;
}
DataSourceProviderDescriptor provider = DataSourceProviderRegistry.getInstance().getDataSourceProvider(dsProviderID);
if (provider == null) {
log.warn("Can't find datasource provider " + dsProviderID + " for datasource '" + id + "'");
provider = (DataSourceProviderDescriptor) DataSourceProviderRegistry.getInstance().makeFakeProvider(dsProviderID);
}
String driverId = CommonUtils.toString(conObject.get(RegistryConstants.ATTR_DRIVER));
DriverDescriptor driver = provider.getDriver(driverId);
if (driver == null) {
log.warn("Can't find driver " + driverId + " in datasource provider " + provider.getId() + " for datasource '" + id + "'. Create new driver");
driver = provider.createDriver(driverId);
driver.setName(driverId);
driver.setDescription("Missing driver " + driverId);
driver.setDriverClassName("java.sql.Driver");
driver.setTemporary(true);
provider.addDriver(driver);
}
DataSourceDescriptor dataSource = registry.getDataSource(id);
boolean newDataSource = (dataSource == null);
if (newDataSource) {
DBPDataSourceOrigin origin;
Map<String, Object> originProperties = JSONUtils.deserializeProperties(conObject, TAG_ORIGIN);
if (CommonUtils.isEmpty(originProperties) || !originProperties.containsKey(ATTR_ORIGIN_TYPE)) {
origin = DataSourceOriginLocal.INSTANCE;
} else {
String originID = CommonUtils.toString(originProperties.remove(ATTR_ORIGIN_TYPE));
origin = new DataSourceOriginLazy(originID, originProperties);
}
dataSource = new DataSourceDescriptor(registry, configurationStorage, origin, id, driver, new DBPConnectionConfiguration());
} else {
// Clean settings - they have to be loaded later by parser
dataSource.getConnectionConfiguration().setProperties(Collections.emptyMap());
dataSource.getConnectionConfiguration().setHandlers(Collections.emptyList());
dataSource.clearFilters();
}
dataSource.setName(JSONUtils.getString(conObject, RegistryConstants.ATTR_NAME));
dataSource.setDescription(JSONUtils.getString(conObject, RegistryConstants.TAG_DESCRIPTION));
dataSource.setSavePassword(JSONUtils.getBoolean(conObject, RegistryConstants.ATTR_SAVE_PASSWORD));
dataSource.setTemplate(JSONUtils.getBoolean(conObject, RegistryConstants.ATTR_TEMPLATE));
DataSourceNavigatorSettings navSettings = dataSource.getNavigatorSettings();
navSettings.setShowSystemObjects(JSONUtils.getBoolean(conObject, DataSourceSerializerModern.ATTR_NAVIGATOR_SHOW_SYSTEM_OBJECTS));
navSettings.setShowUtilityObjects(JSONUtils.getBoolean(conObject, DataSourceSerializerModern.ATTR_NAVIGATOR_SHOW_UTIL_OBJECTS));
navSettings.setShowOnlyEntities(JSONUtils.getBoolean(conObject, DataSourceSerializerModern.ATTR_NAVIGATOR_SHOW_ONLY_ENTITIES));
navSettings.setHideFolders(JSONUtils.getBoolean(conObject, DataSourceSerializerModern.ATTR_NAVIGATOR_HIDE_FOLDERS));
navSettings.setHideSchemas(JSONUtils.getBoolean(conObject, DataSourceSerializerModern.ATTR_NAVIGATOR_HIDE_SCHEMAS));
navSettings.setHideVirtualModel(JSONUtils.getBoolean(conObject, DataSourceSerializerModern.ATTR_NAVIGATOR_HIDE_VIRTUAL));
navSettings.setMergeEntities(JSONUtils.getBoolean(conObject, DataSourceSerializerModern.ATTR_NAVIGATOR_MERGE_ENTITIES));
dataSource.setConnectionReadOnly(JSONUtils.getBoolean(conObject, RegistryConstants.ATTR_READ_ONLY));
final String folderPath = JSONUtils.getString(conObject, RegistryConstants.ATTR_FOLDER);
if (folderPath != null) {
dataSource.setFolder(registry.findFolderByPath(folderPath, true));
}
dataSource.setLockPasswordHash(CommonUtils.toString(conObject.get(RegistryConstants.ATTR_LOCK_PASSWORD)));
// Connection settings
{
Map<String, Object> cfgObject = JSONUtils.getObject(conObject, "configuration");
DBPConnectionConfiguration config = dataSource.getConnectionConfiguration();
config.setHostName(JSONUtils.getString(cfgObject, RegistryConstants.ATTR_HOST));
config.setHostPort(JSONUtils.getString(cfgObject, RegistryConstants.ATTR_PORT));
config.setServerName(JSONUtils.getString(cfgObject, RegistryConstants.ATTR_SERVER));
config.setDatabaseName(JSONUtils.getString(cfgObject, RegistryConstants.ATTR_DATABASE));
config.setUrl(JSONUtils.getString(cfgObject, RegistryConstants.ATTR_URL));
if (!passwordReadCanceled) {
final SecureCredentials creds = readSecuredCredentials(dataSource, null, null);
config.setUserName(creds.getUserName());
if (dataSource.isSavePassword()) {
config.setUserPassword(creds.getUserPassword());
}
}
{
// Still try to read credentials directly from configuration (#6564)
String userName = JSONUtils.getString(cfgObject, RegistryConstants.ATTR_USER);
if (!CommonUtils.isEmpty(userName))
config.setUserName(userName);
String userPassword = JSONUtils.getString(cfgObject, RegistryConstants.ATTR_PASSWORD);
if (!CommonUtils.isEmpty(userPassword))
config.setUserPassword(userPassword);
}
config.setClientHomeId(JSONUtils.getString(cfgObject, RegistryConstants.ATTR_HOME));
config.setConfigProfileName(JSONUtils.getString(cfgObject, "config-profile"));
config.setConnectionType(DataSourceProviderRegistry.getInstance().getConnectionType(JSONUtils.getString(cfgObject, RegistryConstants.ATTR_TYPE), DBPConnectionType.DEFAULT_TYPE));
String colorValue = JSONUtils.getString(cfgObject, RegistryConstants.ATTR_COLOR);
if (!CommonUtils.isEmpty(colorValue)) {
config.setConnectionColor(colorValue);
}
int keepAlive = JSONUtils.getInteger(cfgObject, RegistryConstants.ATTR_KEEP_ALIVE);
if (keepAlive > 0) {
config.setKeepAliveInterval(keepAlive);
}
config.setProperties(JSONUtils.deserializeStringMap(cfgObject, RegistryConstants.TAG_PROPERTIES));
config.setProviderProperties(JSONUtils.deserializeStringMap(cfgObject, RegistryConstants.TAG_PROVIDER_PROPERTIES));
config.setAuthModelId(JSONUtils.getString(cfgObject, RegistryConstants.ATTR_AUTH_MODEL));
config.setAuthProperties(JSONUtils.deserializeStringMapOrNull(cfgObject, "auth-properties"));
// Events
for (Map.Entry<String, Map<String, Object>> eventObject : JSONUtils.getNestedObjects(cfgObject, RegistryConstants.TAG_EVENTS)) {
DBPConnectionEventType eventType = CommonUtils.valueOf(DBPConnectionEventType.class, eventObject.getKey(), DBPConnectionEventType.BEFORE_CONNECT);
Map<String, Object> eventCfg = eventObject.getValue();
DBRShellCommand command = new DBRShellCommand("");
command.setEnabled(JSONUtils.getBoolean(eventCfg, RegistryConstants.ATTR_ENABLED));
command.setShowProcessPanel(JSONUtils.getBoolean(eventCfg, RegistryConstants.ATTR_SHOW_PANEL));
command.setWaitProcessFinish(JSONUtils.getBoolean(eventCfg, RegistryConstants.ATTR_WAIT_PROCESS));
if (command.isWaitProcessFinish()) {
command.setWaitProcessTimeoutMs(JSONUtils.getInteger(eventCfg, RegistryConstants.ATTR_WAIT_PROCESS_TIMEOUT));
}
command.setTerminateAtDisconnect(JSONUtils.getBoolean(eventCfg, RegistryConstants.ATTR_TERMINATE_AT_DISCONNECT));
command.setPauseAfterExecute(JSONUtils.getInteger(eventCfg, RegistryConstants.ATTR_PAUSE_AFTER_EXECUTE));
command.setWorkingDirectory(JSONUtils.getString(eventCfg, RegistryConstants.ATTR_WORKING_DIRECTORY));
command.setCommand(JSONUtils.getString(eventCfg, RegistryConstants.ATTR_COMMAND));
config.setEvent(eventType, command);
}
// Handlers
for (Map.Entry<String, Map<String, Object>> handlerObject : JSONUtils.getNestedObjects(cfgObject, RegistryConstants.TAG_HANDLERS)) {
DBWHandlerConfiguration configuration = parseNetworkHandlerConfig(dataSource, null, handlerObject);
if (configuration != null) {
dataSource.getConnectionConfiguration().updateHandler(configuration);
}
}
// Bootstrap
Map<String, Object> bootstrapCfg = JSONUtils.getObject(cfgObject, RegistryConstants.TAG_BOOTSTRAP);
DBPConnectionBootstrap bootstrap = config.getBootstrap();
if (bootstrapCfg.containsKey(RegistryConstants.ATTR_AUTOCOMMIT)) {
bootstrap.setDefaultAutoCommit(JSONUtils.getBoolean(bootstrapCfg, RegistryConstants.ATTR_AUTOCOMMIT));
}
if (bootstrapCfg.containsKey(RegistryConstants.ATTR_TXN_ISOLATION)) {
bootstrap.setDefaultTransactionIsolation(JSONUtils.getInteger(bootstrapCfg, RegistryConstants.ATTR_TXN_ISOLATION));
}
bootstrap.setDefaultCatalogName(JSONUtils.getString(bootstrapCfg, RegistryConstants.ATTR_DEFAULT_CATALOG));
bootstrap.setDefaultSchemaName(JSONUtils.getString(bootstrapCfg, RegistryConstants.ATTR_DEFAULT_SCHEMA));
String defObjectName = JSONUtils.getString(bootstrapCfg, RegistryConstants.ATTR_DEFAULT_OBJECT);
if (!CommonUtils.isEmpty(defObjectName) && CommonUtils.isEmpty(bootstrap.getDefaultSchemaName())) {
bootstrap.setDefaultSchemaName(JSONUtils.getString(bootstrapCfg, defObjectName));
}
if (bootstrapCfg.containsKey(RegistryConstants.ATTR_IGNORE_ERRORS)) {
bootstrap.setIgnoreErrors(JSONUtils.getBoolean(bootstrapCfg, RegistryConstants.ATTR_IGNORE_ERRORS));
}
bootstrap.setInitQueries(JSONUtils.deserializeStringList(bootstrapCfg, RegistryConstants.TAG_QUERY));
}
// Permissions
{
deserializeModifyPermissions(conObject, dataSource);
}
// Filters
for (Map<String, Object> filterCfg : JSONUtils.getObjectList(conObject, RegistryConstants.TAG_FILTERS)) {
String typeName = JSONUtils.getString(filterCfg, RegistryConstants.ATTR_TYPE);
String objectID = JSONUtils.getString(filterCfg, RegistryConstants.ATTR_ID);
if (!CommonUtils.isEmpty(typeName)) {
DBSObjectFilter filter = readObjectFiler(filterCfg);
dataSource.updateObjectFilter(typeName, objectID, filter);
}
}
// Preferences
dataSource.getPreferenceStore().getProperties().putAll(JSONUtils.deserializeStringMap(conObject, RegistryConstants.TAG_CUSTOM_PROPERTIES));
// Virtual model
String vmID = CommonUtils.toString(conObject.get("virtual-model-id"), id);
DBVModel dbvModel = modelMap.get(vmID);
if (dbvModel != null) {
dataSource.setVirtualModel(dbvModel);
}
// Add to the list
if (newDataSource) {
registry.addDataSourceToList(dataSource);
parseResults.addedDataSources.add(dataSource);
} else {
parseResults.updatedDataSources.add(dataSource);
}
}
// Saved filters
for (Map<String, Object> ctMap : JSONUtils.getObjectList(jsonMap, "saved-filters")) {
DBSObjectFilter filter = readObjectFiler(ctMap);
registry.addSavedFilter(filter);
}
}
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class DataSourceSerializerModern method saveDataSources.
@Override
public void saveDataSources(DBRProgressMonitor monitor, DBPDataSourceConfigurationStorage configurationStorage, List<DataSourceDescriptor> localDataSources, File configFile) throws DBException {
ByteArrayOutputStream dsConfigBuffer = new ByteArrayOutputStream(10000);
try (OutputStreamWriter osw = new OutputStreamWriter(dsConfigBuffer, StandardCharsets.UTF_8)) {
try (JsonWriter jsonWriter = CONFIG_GSON.newJsonWriter(osw)) {
jsonWriter.setIndent("\t");
jsonWriter.beginObject();
// Save folders
if (configurationStorage.isDefault()) {
jsonWriter.name("folders");
jsonWriter.beginObject();
// Folders (only for default storage)
for (DataSourceFolder folder : registry.getAllFolders()) {
saveFolder(jsonWriter, folder);
}
jsonWriter.endObject();
}
Map<String, DBVModel> virtualModels = new LinkedHashMap<>();
Map<String, DBPConnectionType> connectionTypes = new LinkedHashMap<>();
Map<String, Map<String, DBPDriver>> drivers = new LinkedHashMap<>();
{
// Save connections
jsonWriter.name("connections");
jsonWriter.beginObject();
for (DataSourceDescriptor dataSource : localDataSources) {
// Skip temporary
if (!dataSource.isDetached()) {
saveDataSource(jsonWriter, dataSource);
if (dataSource.getVirtualModel().hasValuableData()) {
virtualModels.put(dataSource.getVirtualModel().getId(), dataSource.getVirtualModel());
}
DBPConnectionType connectionType = dataSource.getConnectionConfiguration().getConnectionType();
/*if (!connectionType.isPredefined()) */
{
connectionTypes.put(connectionType.getId(), connectionType);
}
DBPDriver driver = dataSource.getDriver();
if (driver.isCustom() && !driver.getProviderDescriptor().isTemporary()) {
Map<String, DBPDriver> driverMap = drivers.computeIfAbsent(driver.getProviderId(), s -> new LinkedHashMap<>());
driverMap.put(driver.getId(), driver);
}
}
}
jsonWriter.endObject();
}
if (configurationStorage.isDefault()) {
if (!virtualModels.isEmpty()) {
// Save virtual models
jsonWriter.name("virtual-models");
jsonWriter.beginObject();
for (DBVModel model : virtualModels.values()) {
model.serialize(monitor, jsonWriter);
}
jsonWriter.endObject();
}
// Network profiles
List<DBWNetworkProfile> profiles = registry.getNetworkProfiles();
if (!CommonUtils.isEmpty(profiles)) {
jsonWriter.name("network-profiles");
jsonWriter.beginObject();
for (DBWNetworkProfile np : profiles) {
jsonWriter.name(np.getProfileId());
jsonWriter.beginObject();
JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_NAME, np.getProfileName());
JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_DESCRIPTION, np.getProfileDescription());
jsonWriter.name("handlers");
jsonWriter.beginObject();
for (DBWHandlerConfiguration configuration : np.getConfigurations()) {
if (configuration.hasValuableInfo()) {
saveNetworkHandlerConfiguration(jsonWriter, null, np, configuration);
}
}
jsonWriter.endObject();
jsonWriter.endObject();
}
jsonWriter.endObject();
}
// Auth profiles
List<DBAAuthProfile> authProfiles = registry.getAllAuthProfiles();
if (!CommonUtils.isEmpty(authProfiles)) {
jsonWriter.name("auth-profiles");
jsonWriter.beginObject();
for (DBAAuthProfile authProfile : authProfiles) {
jsonWriter.name(authProfile.getProfileId());
jsonWriter.beginObject();
JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_NAME, authProfile.getProfileName());
JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_DESCRIPTION, authProfile.getProfileDescription());
JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_AUTH_MODEL, authProfile.getAuthModelId());
if (authProfile.isSavePassword()) {
JSONUtils.field(jsonWriter, RegistryConstants.ATTR_SAVE_PASSWORD, authProfile.isSavePassword());
}
// Save all auth properties in secure storage
saveSecuredCredentials(null, authProfile, null, new SecureCredentials(authProfile));
jsonWriter.endObject();
}
jsonWriter.endObject();
}
// Filters
List<DBSObjectFilter> savedFilters = registry.getSavedFilters();
if (!CommonUtils.isEmpty(savedFilters)) {
jsonWriter.name("saved-filters");
jsonWriter.beginArray();
for (DBSObjectFilter cf : savedFilters) {
if (!cf.isEmpty()) {
saveObjectFiler(jsonWriter, null, null, cf);
}
}
jsonWriter.endArray();
}
// Connection types
if (!CommonUtils.isEmpty(connectionTypes)) {
jsonWriter.name("connection-types");
jsonWriter.beginObject();
for (DBPConnectionType ct : connectionTypes.values()) {
jsonWriter.name(ct.getId());
jsonWriter.beginObject();
JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_NAME, ct.getName());
JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_COLOR, ct.getColor());
JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_DESCRIPTION, ct.getDescription());
JSONUtils.field(jsonWriter, "auto-commit", ct.isAutocommit());
JSONUtils.field(jsonWriter, "confirm-execute", ct.isConfirmExecute());
JSONUtils.field(jsonWriter, "confirm-data-change", ct.isConfirmDataChange());
serializeModifyPermissions(jsonWriter, ct);
jsonWriter.endObject();
}
jsonWriter.endObject();
}
// Drivers
if (!CommonUtils.isEmpty(drivers)) {
jsonWriter.name("drivers");
jsonWriter.beginObject();
for (Map.Entry<String, Map<String, DBPDriver>> dmap : drivers.entrySet()) {
jsonWriter.name(dmap.getKey());
jsonWriter.beginObject();
for (DBPDriver driver : dmap.getValue().values()) {
((DriverDescriptor) driver).serialize(jsonWriter, true);
}
jsonWriter.endObject();
}
jsonWriter.endObject();
}
}
jsonWriter.endObject();
jsonWriter.flush();
}
} catch (IOException e) {
log.error("IO error while saving datasources json", e);
}
String jsonString = new String(dsConfigBuffer.toByteArray(), StandardCharsets.UTF_8);
boolean encryptProject = CommonUtils.toBoolean(registry.getProject().getProjectProperty(DBPProject.PROP_SECURE_PROJECT));
saveConfigFile(configFile, jsonString, false, encryptProject);
{
saveSecureCredentialsFile(monitor.getNestedMonitor(), configFile.getParentFile(), configurationStorage);
}
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class DataSourceSerializerModern method saveDataSource.
private void saveDataSource(@NotNull JsonWriter json, @NotNull DataSourceDescriptor dataSource) throws IOException {
json.name(dataSource.getId());
json.beginObject();
JSONUtils.field(json, RegistryConstants.ATTR_PROVIDER, dataSource.getDriver().getProviderDescriptor().getId());
JSONUtils.field(json, RegistryConstants.ATTR_DRIVER, dataSource.getDriver().getId());
DBPDataSourceOrigin origin = dataSource.getOrigin();
if (origin != DataSourceOriginLocal.INSTANCE) {
Map<String, Object> originProps = new LinkedHashMap<>();
originProps.put(ATTR_ORIGIN_TYPE, origin.getType());
originProps.putAll(origin.getConfiguration());
JSONUtils.serializeProperties(json, TAG_ORIGIN, originProps);
}
JSONUtils.field(json, RegistryConstants.ATTR_NAME, dataSource.getName());
JSONUtils.fieldNE(json, RegistryConstants.TAG_DESCRIPTION, dataSource.getDescription());
JSONUtils.field(json, RegistryConstants.ATTR_SAVE_PASSWORD, dataSource.isSavePassword());
if (dataSource.isTemplate()) {
JSONUtils.field(json, RegistryConstants.ATTR_TEMPLATE, dataSource.isTemplate());
}
DataSourceNavigatorSettings navSettings = dataSource.getNavigatorSettings();
if (navSettings.isShowSystemObjects())
JSONUtils.field(json, ATTR_NAVIGATOR_SHOW_SYSTEM_OBJECTS, true);
if (navSettings.isShowUtilityObjects())
JSONUtils.field(json, ATTR_NAVIGATOR_SHOW_UTIL_OBJECTS, true);
if (navSettings.isShowOnlyEntities())
JSONUtils.field(json, ATTR_NAVIGATOR_SHOW_ONLY_ENTITIES, true);
if (navSettings.isHideFolders())
JSONUtils.field(json, ATTR_NAVIGATOR_HIDE_FOLDERS, true);
if (navSettings.isHideSchemas())
JSONUtils.field(json, ATTR_NAVIGATOR_HIDE_SCHEMAS, true);
if (navSettings.isHideVirtualModel())
JSONUtils.field(json, ATTR_NAVIGATOR_HIDE_VIRTUAL, true);
if (navSettings.isMergeEntities())
JSONUtils.field(json, ATTR_NAVIGATOR_MERGE_ENTITIES, true);
JSONUtils.field(json, RegistryConstants.ATTR_READ_ONLY, dataSource.isConnectionReadOnly());
if (dataSource.getFolder() != null) {
JSONUtils.field(json, RegistryConstants.ATTR_FOLDER, dataSource.getFolder().getFolderPath());
}
final String lockPasswordHash = dataSource.getLockPasswordHash();
if (!CommonUtils.isEmpty(lockPasswordHash)) {
JSONUtils.field(json, RegistryConstants.ATTR_LOCK_PASSWORD, lockPasswordHash);
}
if (dataSource.hasSharedVirtualModel()) {
JSONUtils.field(json, "virtual-model-id", dataSource.getVirtualModel().getId());
}
{
// Connection info
DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
json.name("configuration");
json.beginObject();
JSONUtils.fieldNE(json, RegistryConstants.ATTR_HOST, connectionInfo.getHostName());
JSONUtils.fieldNE(json, RegistryConstants.ATTR_PORT, connectionInfo.getHostPort());
JSONUtils.fieldNE(json, RegistryConstants.ATTR_SERVER, connectionInfo.getServerName());
JSONUtils.fieldNE(json, RegistryConstants.ATTR_DATABASE, connectionInfo.getDatabaseName());
JSONUtils.fieldNE(json, RegistryConstants.ATTR_URL, connectionInfo.getUrl());
saveSecuredCredentials(dataSource, null, null, new SecureCredentials(dataSource));
JSONUtils.fieldNE(json, RegistryConstants.ATTR_HOME, connectionInfo.getClientHomeId());
if (connectionInfo.getConnectionType() != null) {
JSONUtils.field(json, RegistryConstants.ATTR_TYPE, connectionInfo.getConnectionType().getId());
}
JSONUtils.fieldNE(json, RegistryConstants.ATTR_COLOR, connectionInfo.getConnectionColor());
// Save other
if (connectionInfo.getKeepAliveInterval() > 0) {
JSONUtils.field(json, RegistryConstants.ATTR_KEEP_ALIVE, connectionInfo.getKeepAliveInterval());
}
JSONUtils.fieldNE(json, "config-profile", connectionInfo.getConfigProfileName());
JSONUtils.serializeProperties(json, RegistryConstants.TAG_PROPERTIES, connectionInfo.getProperties());
JSONUtils.serializeProperties(json, RegistryConstants.TAG_PROVIDER_PROPERTIES, connectionInfo.getProviderProperties());
JSONUtils.fieldNE(json, RegistryConstants.ATTR_AUTH_MODEL, connectionInfo.getAuthModelId());
JSONUtils.serializeProperties(json, "auth-properties", connectionInfo.getAuthProperties());
// Save events
if (!ArrayUtils.isEmpty(connectionInfo.getDeclaredEvents())) {
json.name(RegistryConstants.TAG_EVENTS);
json.beginObject();
for (DBPConnectionEventType eventType : connectionInfo.getDeclaredEvents()) {
DBRShellCommand command = connectionInfo.getEvent(eventType);
if (!command.isEnabled()) {
continue;
}
json.name(eventType.name());
json.beginObject();
JSONUtils.field(json, RegistryConstants.ATTR_ENABLED, command.isEnabled());
JSONUtils.field(json, RegistryConstants.ATTR_SHOW_PANEL, command.isShowProcessPanel());
JSONUtils.field(json, RegistryConstants.ATTR_WAIT_PROCESS, command.isWaitProcessFinish());
if (command.isWaitProcessFinish()) {
JSONUtils.field(json, RegistryConstants.ATTR_WAIT_PROCESS_TIMEOUT, command.getWaitProcessTimeoutMs());
}
JSONUtils.field(json, RegistryConstants.ATTR_TERMINATE_AT_DISCONNECT, command.isTerminateAtDisconnect());
JSONUtils.field(json, RegistryConstants.ATTR_PAUSE_AFTER_EXECUTE, command.getPauseAfterExecute());
JSONUtils.fieldNE(json, RegistryConstants.ATTR_WORKING_DIRECTORY, command.getWorkingDirectory());
JSONUtils.fieldNE(json, RegistryConstants.ATTR_COMMAND, command.getCommand());
json.endObject();
}
json.endObject();
}
// Save network handlers' configurations
if (!CommonUtils.isEmpty(connectionInfo.getHandlers())) {
json.name(RegistryConstants.TAG_HANDLERS);
json.beginObject();
for (DBWHandlerConfiguration configuration : connectionInfo.getHandlers()) {
if (configuration.isEnabled()) {
saveNetworkHandlerConfiguration(json, dataSource, null, configuration);
}
}
json.endObject();
}
// Save bootstrap info
{
DBPConnectionBootstrap bootstrap = connectionInfo.getBootstrap();
if (bootstrap.hasData()) {
json.name(RegistryConstants.TAG_BOOTSTRAP);
json.beginObject();
if (bootstrap.getDefaultAutoCommit() != null) {
JSONUtils.field(json, RegistryConstants.ATTR_AUTOCOMMIT, bootstrap.getDefaultAutoCommit());
}
if (bootstrap.getDefaultTransactionIsolation() != null) {
JSONUtils.field(json, RegistryConstants.ATTR_TXN_ISOLATION, bootstrap.getDefaultTransactionIsolation());
}
JSONUtils.fieldNE(json, RegistryConstants.ATTR_DEFAULT_CATALOG, bootstrap.getDefaultCatalogName());
JSONUtils.fieldNE(json, RegistryConstants.ATTR_DEFAULT_SCHEMA, bootstrap.getDefaultSchemaName());
if (bootstrap.isIgnoreErrors()) {
JSONUtils.field(json, RegistryConstants.ATTR_IGNORE_ERRORS, true);
}
JSONUtils.serializeStringList(json, RegistryConstants.TAG_QUERY, bootstrap.getInitQueries());
json.endObject();
}
}
json.endObject();
}
// Permissions
serializeModifyPermissions(json, dataSource);
{
// Filters
Collection<FilterMapping> filterMappings = dataSource.getObjectFilters();
if (!CommonUtils.isEmpty(filterMappings)) {
json.name(RegistryConstants.TAG_FILTERS);
json.beginArray();
for (FilterMapping filter : filterMappings) {
if (filter.defaultFilter != null && !filter.defaultFilter.isEmpty()) {
saveObjectFiler(json, filter.typeName, null, filter.defaultFilter);
}
for (Map.Entry<String, DBSObjectFilter> cf : filter.customFilters.entrySet()) {
if (!cf.getValue().isEmpty()) {
saveObjectFiler(json, filter.typeName, cf.getKey(), cf.getValue());
}
}
}
json.endArray();
}
}
// Preferences
{
// Save only properties who are differs from default values
SimplePreferenceStore prefStore = dataSource.getPreferenceStore();
Map<String, String> props = new TreeMap<>();
for (String propName : prefStore.preferenceNames()) {
String propValue = prefStore.getString(propName);
String defValue = prefStore.getDefaultString(propName);
if (propValue != null && !CommonUtils.equalObjects(propValue, defValue)) {
props.put(propName, propValue);
}
}
if (!props.isEmpty()) {
JSONUtils.serializeProperties(json, RegistryConstants.TAG_CUSTOM_PROPERTIES, props);
}
}
json.endObject();
}
Aggregations