use of org.jkiss.dbeaver.model.net.DBWNetworkProfile in project dbeaver by serge-rider.
the class PrefPageProjectNetworkProfiles method performDefaults.
@Override
protected void performDefaults() {
super.performDefaults();
profilesTable.removeAll();
if (projectMeta != null) {
for (DBWNetworkProfile profile : projectMeta.getDataSourceRegistry().getNetworkProfiles()) {
TableItem item = new TableItem(profilesTable, SWT.NONE);
item.setText(profile.getProfileName());
item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_DOCUMENT));
item.setData(profile);
if (selectedProfile == null) {
selectedProfile = profile;
profilesTable.select(0);
}
for (NetworkHandlerDescriptor nhd : allHandlers) {
HandlerBlock handlerBlock = configurations.get(nhd);
DBWHandlerConfiguration configuration = profile.getConfiguration(nhd);
if (configuration != null) {
handlerBlock.loadedConfigs.put(profile, configuration);
}
}
}
}
updateControlsState();
}
use of org.jkiss.dbeaver.model.net.DBWNetworkProfile in project dbeaver by serge-rider.
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.DBWNetworkProfile in project dbeaver by serge-rider.
the class ConnectionPageNetworkHandler method updateProfileList.
private void updateProfileList() {
DBPConnectionConfiguration cfg = site.getActiveDataSource().getConnectionConfiguration();
String profileId = cfg.getConfigProfileName();
activeProfile = CommonUtils.isEmpty(profileId) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileId);
// Refresh profile list
profileCombo.removeAll();
profileCombo.add("");
for (DBWNetworkProfile profile : site.getProject().getDataSourceRegistry().getNetworkProfiles()) {
profileCombo.add(profile.getProfileName());
if (CommonUtils.equalObjects(profileId, profile.getProfileName())) {
profileCombo.select(profileCombo.getItemCount() - 1);
}
}
// Update settings from profile
if (activeProfile != null) {
}
// Update page controls
handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
if (handlerConfiguration == null) {
handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, site.getActiveDataSource());
}
useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
configurator.loadSettings(handlerConfiguration);
enableHandlerContent();
}
use of org.jkiss.dbeaver.model.net.DBWNetworkProfile in project dbeaver by dbeaver.
the class ConnectionPageNetworkHandler method updateProfileList.
private void updateProfileList() {
DBPConnectionConfiguration cfg = site.getActiveDataSource().getConnectionConfiguration();
String profileId = cfg.getConfigProfileName();
activeProfile = CommonUtils.isEmpty(profileId) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileId);
// Refresh profile list
profileCombo.removeAll();
profileCombo.add("");
for (DBWNetworkProfile profile : site.getProject().getDataSourceRegistry().getNetworkProfiles()) {
profileCombo.add(profile.getProfileName());
if (CommonUtils.equalObjects(profileId, profile.getProfileName())) {
profileCombo.select(profileCombo.getItemCount() - 1);
}
}
// Update settings from profile
if (activeProfile != null) {
}
// Update page controls
handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
if (handlerConfiguration == null) {
handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, site.getActiveDataSource());
}
useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
configurator.loadSettings(handlerConfiguration);
enableHandlerContent();
}
use of org.jkiss.dbeaver.model.net.DBWNetworkProfile in project dbeaver by dbeaver.
the class PrefPageProjectNetworkProfiles method performOk.
@Override
public boolean performOk() {
saveHandlerSettings();
for (TableItem item : profilesTable.getItems()) {
DBWNetworkProfile profile = (DBWNetworkProfile) item.getData();
saveSettings(profile);
projectMeta.getDataSourceRegistry().updateNetworkProfile(profile);
}
projectMeta.getDataSourceRegistry().flushConfig();
return super.performOk();
}
Aggregations