Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.obeonetwork.dsl.database.drivers,
liquibase,
org.obeonetwork.utils.common.ui
org.obeonetwork.utils.common.ui,
org.eclipse.swt
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.obeonetwork.dsl.database.liquibasegen
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.obeonetwork.dsl.database.liquibasegen;

import java.util.Objects;

public record ConnectionInformation(String url, String username, String password) {
public ConnectionInformation {
Objects.requireNonNull(url);
Objects.requireNonNull(username);
Objects.requireNonNull(password);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
import static org.obeonetwork.dsl.database.liquibasegen.Activator.getLiquibaseVersion;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.eclipse.core.commands.AbstractHandler;
Expand All @@ -28,6 +32,7 @@
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
import org.obeonetwork.dsl.database.liquibasegen.ConnectionInformation;
import org.obeonetwork.dsl.database.liquibasegen.LiquibaseUpdater;
import org.obeonetwork.dsl.database.liquibasegen.ui.ConnectionInformationDialog;
import org.obeonetwork.utils.common.ui.handlers.EventHelper;
Expand All @@ -42,6 +47,8 @@
*/
@SuppressWarnings("restriction")
public class ChangelogHandler extends AbstractHandler {
private static final String CREDENTIALS_PROPERTIES_FILE_NAME = "credentials.properties";

private final static String LIQUIBASE_PROPERTIES_FILE_NAME = "liquibase.properties"; //$NON-NLS-1$

private Shell shell;
Expand Down Expand Up @@ -89,15 +96,46 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
* @throws IOException
*/
private boolean openConnectionInformationDialog(File liquibasePropertiesFile) throws IOException {
Properties liquibaseProperties = new Properties();
InputStream inputStream = new FileInputStream(liquibasePropertiesFile.getLocation().toOSString());
liquibaseProperties.load(inputStream);

java.io.File credentialsPropertiesFile = Paths.get(liquibasePropertiesFile.getParent().getLocationURI()).resolve(CREDENTIALS_PROPERTIES_FILE_NAME).toFile();

Properties credentialsProperties = new Properties();
// Check if credentials file exist
if (!credentialsPropertiesFile.exists()) {
Properties liquibaseProperties = new Properties();
InputStream inputStream = new FileInputStream(liquibasePropertiesFile.getLocation().toOSString());
liquibaseProperties.load(inputStream);

// initialize credentials file using default values in liquibase file
credentialsProperties.setProperty("url.1", liquibaseProperties.getProperty("url", ""));
credentialsProperties.setProperty("username.1", liquibaseProperties.getProperty("username", ""));
credentialsProperties.setProperty("password.1", liquibaseProperties.getProperty("password", ""));

final FileOutputStream credentialsFos = new FileOutputStream(credentialsPropertiesFile);
credentialsProperties.store(credentialsFos, "Credentials for database connections"+System.lineSeparator()+System.lineSeparator()+
"url.X = //url/database" +System.lineSeparator()+
"username.X = username"+System.lineSeparator()+
"password.X = password"+System.lineSeparator());
inputStream.close();
credentialsFos.close();
}else {
final FileInputStream credentialsFis = new FileInputStream(credentialsPropertiesFile);
credentialsProperties.load(credentialsFis);
credentialsFis.close();
}

int count = 1;
List<ConnectionInformation> connectionInformations = new ArrayList<>();
while (credentialsProperties.getProperty("url."+count)!=null) {
connectionInformations.add(new ConnectionInformation(credentialsProperties.getProperty("url."+count,""),
credentialsProperties.getProperty("username."+count,""),
credentialsProperties.getProperty("password."+count,"")));
count++;
}

ConnectionInformationDialog connectionInformationDialog = new ConnectionInformationDialog(
shell,
liquibaseProperties.getProperty("url", ""), //$NON-NLS-1$ //$NON-NLS-2$
liquibaseProperties.getProperty("username", ""), //$NON-NLS-1$ //$NON-NLS-2$
liquibaseProperties.getProperty("password", "")); //$NON-NLS-1$ //$NON-NLS-2$
connectionInformations);

connectionInformationDialog.open();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*******************************************************************************/
package org.obeonetwork.dsl.database.liquibasegen.ui;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
Expand All @@ -18,11 +22,13 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.obeonetwork.dsl.database.liquibasegen.ConnectionInformation;

/**
* Creates a dialog for defining the identifiers of the database.
Expand All @@ -35,6 +41,7 @@ public class ConnectionInformationDialog extends Dialog {
private String url;
private String username;
private String password;
private List<ConnectionInformation> connectionInformations;

/**
* Create the dialog.
Expand All @@ -43,11 +50,12 @@ public class ConnectionInformationDialog extends Dialog {
* @param username
* @param password
*/
public ConnectionInformationDialog(Shell parentShell, String url, String username, String password) {
public ConnectionInformationDialog(Shell parentShell, List<ConnectionInformation> connectionInformations) {
super(parentShell);
this.url = url;
this.username = username;
this.password = password;
this.connectionInformations = connectionInformations;
url = connectionInformations.get(0).url();
username = "";
password = "";
}

/**
Expand All @@ -69,16 +77,6 @@ protected Control createDialogArea(Composite parent) {
lblNewLabel.setLayoutData(gd_lblNewLabel);
lblNewLabel.setText("URL");

Text urlText = new Text(composite, SWT.BORDER);
urlText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
urlText.setText(url);
urlText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
url = ((Text) e.widget).getText();
}
});

Composite composite_1 = new Composite(container, SWT.NONE);
composite_1.setLayout(new GridLayout(2, false));
GridData gd_composite_1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
Expand All @@ -92,16 +90,6 @@ public void modifyText(ModifyEvent e) {
lblNewLabel_1.setLayoutData(gd_lblNewLabel_1);
lblNewLabel_1.setText("Username");

Text usernameText = new Text(composite_1, SWT.BORDER);
usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
usernameText.setText(username);
usernameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
username = ((Text) e.widget).getText();
}
});

Composite composite_2 = new Composite(container, SWT.NONE);
composite_2.setLayout(new GridLayout(2, false));
composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
Expand All @@ -113,7 +101,43 @@ public void modifyText(ModifyEvent e) {
lblNewLabel_2.setLayoutData(gd_lblNewLabel_2);
lblNewLabel_2.setText("Password");

Text usernameText = new Text(composite_1, SWT.BORDER);
Text passwordText = new Text(composite_2, SWT.BORDER);

Combo urlCombo = new Combo(composite, SWT.BORDER);
urlCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
connectionInformations.stream().map(ConnectionInformation::url).forEach(ciUrl -> urlCombo.add(ciUrl));
urlCombo.addModifyListener(new ModifyListener() {

@Override
public void modifyText(ModifyEvent e) {
url = ((Combo) e.widget).getText();
Optional<ConnectionInformation> selectedConInf = connectionInformations.stream().filter(ci -> ci.url().equals(url)).findFirst();
selectedConInf.ifPresentOrElse(
(ci) -> {usernameText.setText( ci.username());
username = ci.username();
},
() -> {usernameText.setText("");
username="";});
selectedConInf.ifPresentOrElse(
(ci) -> {passwordText.setText(ci.password());
password=ci.password();},
() -> {passwordText.setText("");
password="";});
}
});


usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
usernameText.setText(username);
usernameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
username = ((Text) e.widget).getText();
}
});


passwordText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
passwordText.setText(password);
passwordText.addModifyListener(new ModifyListener() {
Expand Down