Search in sources :

Example 6 with DriverDef

use of org.kie.workbench.common.screens.datasource.management.model.DriverDef in project kie-wb-common by kiegroup.

the class DataSourceDefEditorServiceImpl method testConnection.

@Override
public TestResult testConnection(DataSourceDef dataSourceDef, Module module) {
    TestResult result = new TestResult(false);
    if (isEmpty(dataSourceDef.getConnectionURL())) {
        result.setMessage("A valid connection url is required");
        return result;
    }
    if (isEmpty(dataSourceDef.getUser()) || isEmpty(dataSourceDef.getPassword())) {
        result.setMessage("A valid user and password are required");
        return result;
    }
    DriverDefInfo driverDefInfo = null;
    if (isEmpty(dataSourceDef.getDriverUuid())) {
        result.setMessage("A valid driver is required");
        return result;
    }
    if (module != null) {
        driverDefInfo = dataSourceDefQueryService.findModuleDriver(dataSourceDef.getDriverUuid(), module.getRootPath());
    } else {
        driverDefInfo = dataSourceDefQueryService.findGlobalDriver(dataSourceDef.getDriverUuid());
    }
    if (driverDefInfo == null) {
        result.setMessage("Data source driver: " + dataSourceDef.getUuid() + " was not found");
        return result;
    }
    DriverDefEditorContent driverDefEditorContent = driverDefService.loadContent(driverDefInfo.getPath());
    DriverDef driverDef = driverDefEditorContent.getDef();
    URI uri;
    try {
        uri = artifactResolver.resolve(driverDef.getGroupId(), driverDef.getArtifactId(), driverDef.getVersion());
    } catch (Exception e) {
        result.setMessage("Connection could not be tested due to the following error: " + e.getMessage());
        return result;
    }
    if (uri == null) {
        result.setMessage("Driver artifact: " + driverDef.getGroupId() + ":" + driverDef.getArtifactId() + ":" + driverDef.getVersion() + " was not found");
        return result;
    }
    try {
        Properties properties = new Properties();
        properties.put("user", dataSourceDef.getUser());
        properties.put("password", dataSourceDef.getPassword());
        URLConnectionFactory connectionFactory = new URLConnectionFactory(uri.toURL(), driverDef.getDriverClass(), dataSourceDef.getConnectionURL(), properties);
        Connection conn = connectionFactory.createConnection();
        if (conn == null) {
            result.setMessage("It was not possible to open connection");
        } else {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Connection was successfully obtained: " + conn);
            stringBuilder.append("\n");
            stringBuilder.append("*** DatabaseProductName: " + conn.getMetaData().getDatabaseProductName());
            stringBuilder.append("\n");
            stringBuilder.append("*** DatabaseProductVersion: " + conn.getMetaData().getDatabaseProductVersion());
            stringBuilder.append("\n");
            stringBuilder.append("*** DriverName: " + conn.getMetaData().getDriverName());
            stringBuilder.append("\n");
            stringBuilder.append("*** DriverVersion: " + conn.getMetaData().getDriverVersion());
            stringBuilder.append("\n");
            conn.close();
            stringBuilder.append("Connection was successfully released.");
            stringBuilder.append("\n");
            result.setTestPassed(true);
            result.setMessage(stringBuilder.toString());
        }
        return result;
    } catch (Exception e) {
        result.setMessage(e.getMessage());
        return result;
    }
}
Also used : URLConnectionFactory(org.kie.workbench.common.screens.datasource.management.util.URLConnectionFactory) DriverDefInfo(org.kie.workbench.common.screens.datasource.management.model.DriverDefInfo) DriverDefEditorContent(org.kie.workbench.common.screens.datasource.management.model.DriverDefEditorContent) Connection(java.sql.Connection) TestResult(org.kie.workbench.common.screens.datasource.management.model.TestResult) DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef) Properties(java.util.Properties) URI(java.net.URI)

Example 7 with DriverDef

use of org.kie.workbench.common.screens.datasource.management.model.DriverDef in project kie-wb-common by kiegroup.

the class DataSourceRuntimeManagerTest method setup.

@Before
public void setup() {
    when(providerFactory.getDataSourceProvider()).thenReturn(dataSourceProvider);
    when(providerFactory.getDriverProvider()).thenReturn(driverProvider);
    runtimeManager = new DataSourceRuntimeManagerMock(providerFactory);
    dataSourceDef = new DataSourceDef();
    dataSourceDef.setUuid(DS1_UUID);
    dataSourceDef.setName(DS1_NAME);
    dataSourceDef.setDriverUuid(DRIVER1_UUID);
    dataSourceDef.setConnectionURL(DS1_CONNECTION_URL);
    dataSourceDef.setUser(DS1_USER);
    dataSourceDef.setPassword(DS1_PASSWORD);
    driverDef = new DriverDef();
    driverDef.setUuid(DRIVER1_UUID);
    driverDef.setName(DRIVER1_NAME);
    driverDef.setDriverClass(DRIVER1_CLASS);
    driverDef.setArtifactId(ARTIFACT_ID);
    driverDef.setGroupId(GROUP_ID);
    driverDef.setVersion(VERSION);
    driverDeploymentInfo = new DriverDeploymentInfo();
    dataSourceDeploymentInfo = new DataSourceDeploymentInfo();
}
Also used : DriverDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DriverDeploymentInfo) DataSourceDef(org.kie.workbench.common.screens.datasource.management.model.DataSourceDef) DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef) DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) Before(org.junit.Before)

Example 8 with DriverDef

use of org.kie.workbench.common.screens.datasource.management.model.DriverDef in project kie-wb-common by kiegroup.

the class NewDriverDefWizard method start.

@Override
public void start() {
    driverDefPage.clear();
    driverDefPage.setComplete(false);
    driverDef = new DriverDef();
    driverDefPage.setDriverDef(driverDef);
    super.start();
}
Also used : DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef)

Example 9 with DriverDef

use of org.kie.workbench.common.screens.datasource.management.model.DriverDef in project kie-wb-common by kiegroup.

the class DriverDefEditorTest method createContent.

private DriverDefEditorContent createContent() {
    DriverDefEditorContent content = new DriverDefEditorContent();
    content.setDef(new DriverDef());
    content.getDef().setUuid(DRIVER_UUID);
    content.getDef().setName(NAME);
    content.getDef().setGroupId(GROUP_ID);
    content.getDef().setArtifactId(ARTIFACT_ID);
    content.getDef().setVersion(VERSION);
    content.getDef().setDriverClass(DRIVER_CLASS);
    return content;
}
Also used : DriverDefEditorContent(org.kie.workbench.common.screens.datasource.management.model.DriverDefEditorContent) DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef)

Example 10 with DriverDef

use of org.kie.workbench.common.screens.datasource.management.model.DriverDef in project kie-wb-common by kiegroup.

the class DriverWizardTestBase method setup.

/**
 * Initializes the wizard page.
 */
protected void setup() {
    mainPanel = new DriverDefMainPanel(mainPanelView);
    driverDef = new DriverDef();
    editorHelper = new DriverDefEditorHelper(translationService, new ClientValidationServiceMock());
    defPage = new DriverDefPage(view, mainPanel, editorHelper, statusChangeEvent);
    defPage.setDriverDef(driverDef);
}
Also used : DriverDefEditorHelper(org.kie.workbench.common.screens.datasource.management.client.editor.driver.DriverDefEditorHelper) DriverDefMainPanel(org.kie.workbench.common.screens.datasource.management.client.editor.driver.DriverDefMainPanel) DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef) ClientValidationServiceMock(org.kie.workbench.common.screens.datasource.management.client.util.ClientValidationServiceMock)

Aggregations

DriverDef (org.kie.workbench.common.screens.datasource.management.model.DriverDef)18 Before (org.junit.Before)6 URI (java.net.URI)4 Properties (java.util.Properties)3 DriverDefEditorContent (org.kie.workbench.common.screens.datasource.management.model.DriverDefEditorContent)3 URLConnectionFactory (org.kie.workbench.common.screens.datasource.management.util.URLConnectionFactory)3 ArrayList (java.util.ArrayList)2 ClientValidationServiceMock (org.kie.workbench.common.screens.datasource.management.client.util.ClientValidationServiceMock)2 DataSourceDef (org.kie.workbench.common.screens.datasource.management.model.DataSourceDef)2 DataSourceDeploymentInfo (org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo)2 DriverDefInfo (org.kie.workbench.common.screens.datasource.management.model.DriverDefInfo)2 DriverDeploymentInfo (org.kie.workbench.common.screens.datasource.management.model.DriverDeploymentInfo)2 URL (java.net.URL)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)1 PoolableConnection (org.apache.commons.dbcp2.PoolableConnection)1 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)1 PoolingDataSource (org.apache.commons.dbcp2.PoolingDataSource)1