Search in sources :

Example 66 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.

the class ConnectionServiceImplTest method testGetConnectionsPasswords.

@Test
public void testGetConnectionsPasswords() throws Exception {
    doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
    List<IDatabaseConnection> mockConnectionList = new ArrayList<>();
    IDatabaseConnection mockConnection = new DatabaseConnection();
    mockConnectionList.add(mockConnection);
    mockConnection.setPassword("testPassword");
    doReturn(mockConnectionList).when(connectionServiceImpl.datasourceMgmtSvc).getDatasources();
    List<IDatabaseConnection> connectionList = connectionServiceImpl.getConnections();
    verify(connectionServiceImpl).getConnections();
    // Default getConnections() method does not hide password
    assertEquals("testPassword", mockConnectionList.get(0).getPassword());
    // Hide passwords
    connectionList = connectionServiceImpl.getConnections(true);
    verify(connectionServiceImpl).getConnections();
    assertEquals(null, mockConnectionList.get(0).getPassword());
}
Also used : ArrayList(java.util.ArrayList) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 67 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.

the class DSWDatasourceServiceImplTest method testSqlQueries_AreNotSupported_PentahoDataServices.

@Test(expected = SqlQueriesNotSupportedException.class)
public void testSqlQueries_AreNotSupported_PentahoDataServices() throws Exception {
    String connNameDataService = "connToDataService";
    String dbTypeIdDataService = "Pentaho Data Services";
    DatabaseType dbtype = new DatabaseType(dbTypeIdDataService, STRING_DEFAULT, null, 0, STRING_DEFAULT);
    IDatabaseConnection connDataService = new DatabaseConnection();
    connDataService.setDatabaseType(dbtype);
    ConnectionServiceImpl connService = mock(ConnectionServiceImpl.class);
    doReturn(connDataService).when(connService).getConnectionByName(eq(connNameDataService));
    DSWDatasourceServiceImpl service = new DSWDatasourceServiceImpl(connService);
    service.checkSqlQueriesSupported(connNameDataService);
}
Also used : DatabaseType(org.pentaho.database.model.DatabaseType) IDatabaseType(org.pentaho.database.model.IDatabaseType) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Mockito.anyString(org.mockito.Mockito.anyString) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 68 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.

the class DSWDatasourceServiceImplTest method testSqlQueries_Supported_PostgresDb.

@Test
public void testSqlQueries_Supported_PostgresDb() throws Exception {
    String connNamePostgres = "connToPostgresDb";
    String dbTypeIdPostgres = "PostgresDb";
    IDatabaseConnection connDataService = new DatabaseConnection();
    connDataService.setDatabaseType(new DatabaseType(dbTypeIdPostgres, STRING_DEFAULT, null, 0, STRING_DEFAULT));
    ConnectionServiceImpl connService = mock(ConnectionServiceImpl.class);
    doReturn(connDataService).when(connService).getConnectionByName(eq(connNamePostgres));
    DSWDatasourceServiceImpl service = new DSWDatasourceServiceImpl(connService);
    service.checkSqlQueriesSupported(connNamePostgres);
}
Also used : DatabaseType(org.pentaho.database.model.DatabaseType) IDatabaseType(org.pentaho.database.model.IDatabaseType) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Mockito.anyString(org.mockito.Mockito.anyString) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 69 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.

the class AgileMartDatasourceLifecycleManager method startup.

@Override
public void startup() {
    try {
        String agileMartDatasourceName = PentahoSystem.getSystemSetting(SETTINGS_FILE, AGILE_MART_STAGING_DATASOURCE_NAME, null);
        IDatabaseConnection agileMartDatasource = datasourceMgmtService.getDatasourceByName(agileMartDatasourceName);
        IDatabaseConnection newAgileMartDatasource = agileMartDatasourceHelper.getAgileMartDatasource();
        if (agileMartDatasource != null) {
            newAgileMartDatasource.setId(agileMartDatasource.getId());
            datasourceMgmtService.updateDatasourceByName(agileMartDatasource.getName(), newAgileMartDatasource);
        } else {
            datasourceMgmtService.createDatasource(newAgileMartDatasource);
        }
    } catch (Throwable th) {
        log.warn("Error during the create/update of AgileMart Datasource", th);
    }
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 70 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.

the class ConnectionService method createDatabaseConnection.

/**
 * Create a database connection
 *
 * @param driver
 *          String name of the driver to use
 * @param url
 *          String name of the url used to create the connection.
 *
 * @return IDatabaseConnection for the given parameters
 */
@GET
@Path("/createDatabaseConnection")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public IDatabaseConnection createDatabaseConnection(@QueryParam("driver") String driver, @QueryParam("url") String url) {
    for (IDatabaseDialect dialect : dialectService.getDatabaseDialects()) {
        if (dialect.getNativeDriver() != null && dialect.getNativeDriver().equals(driver)) {
            if (dialect.getNativeJdbcPre() != null && url.startsWith(dialect.getNativeJdbcPre())) {
                return dialect.createNativeConnection(url);
            }
        }
    }
    // if no native driver was found, create a custom dialect object.
    IDatabaseConnection conn = genericDialect.createNativeConnection(url);
    conn.getAttributes().put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, driver);
    return conn;
}
Also used : IDatabaseDialect(org.pentaho.database.IDatabaseDialect) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Aggregations

IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)99 Test (org.junit.Test)29 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)29 ArrayList (java.util.ArrayList)18 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 RequestException (com.google.gwt.http.client.RequestException)14 Request (com.google.gwt.http.client.Request)13 RequestBuilder (com.google.gwt.http.client.RequestBuilder)13 RequestCallback (com.google.gwt.http.client.RequestCallback)13 Response (com.google.gwt.http.client.Response)13 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)13 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)11 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)9 List (java.util.List)8 Response (javax.ws.rs.core.Response)8 Path (javax.ws.rs.Path)7 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 Facet (org.codehaus.enunciate.Facet)5 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)5