Search in sources :

Example 81 with IDatabaseConnection

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

the class TablesSelectionStep method fetchTables.

protected void fetchTables() {
    showWaitingDialog();
    IDatabaseConnection connection = ((MultiTableDatasource) parentDatasource).getConnection();
    processAvailableTables(connection, schemas.getValue());
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 82 with IDatabaseConnection

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

the class InMemoryConnectionServiceImplTest method testGetConnections.

@Test
public void testGetConnections() {
    try {
        InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
        List<IDatabaseConnection> conns = serv.getConnections();
        assertTrue(conns != null && conns.size() == 0);
        IDatabaseConnection connection = new DatabaseConnection();
        connection.setName("Connection 1");
        serv.addConnection(connection);
        conns = serv.getConnections();
        assertTrue(conns != null && conns.size() > 0);
    } catch (Exception ex) {
        fail();
    }
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Test(org.junit.Test)

Example 83 with IDatabaseConnection

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

the class InMemoryConnectionServiceImplTest method testUpdateConnection.

@Test
public void testUpdateConnection() {
    try {
        InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
        List<IDatabaseConnection> conns = serv.getConnections();
        assertTrue(conns != null && conns.size() == 0);
        IDatabaseConnection connection = new DatabaseConnection();
        connection.setName("Connection 1");
        connection.setUsername("admin");
        connection.setPassword("password");
        serv.addConnection(connection);
        conns = serv.getConnections();
        assertTrue(conns.get(0).getUsername().equals("admin"));
        assertTrue(conns.get(0).getPassword().equals("password"));
        connection = new DatabaseConnection();
        connection.setName("Connection 1");
        connection.setUsername("root");
        connection.setPassword("pass");
        serv.updateConnection(connection);
        List<IDatabaseConnection> conns1 = serv.getConnections();
        assertTrue(conns1 != null && conns1.size() > 0);
        assertTrue(conns1.size() == conns.size());
        assertTrue(conns1.get(0).getUsername().equals("root"));
        assertTrue(conns1.get(0).getPassword().equals("pass"));
    } catch (Exception ex) {
        fail();
    }
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Test(org.junit.Test)

Example 84 with IDatabaseConnection

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

the class DatasourceInMemoryServiceHelperTest method setUp.

@Before
public void setUp() throws Exception {
    URL resource = getClass().getClassLoader().getResource(getClass().getPackage().getName().replace(".", "/") + "/DatasourceInMemoryServiceHelperTest.csv");
    csvFile = resource.getPath();
    sqlConnection = mock(Connection.class);
    when(resultSet.getMetaData()).thenReturn(rsMetaData);
    when(statment.executeQuery(eq(SAMPLE_VALID_QUERY))).thenReturn(resultSet);
    when(sqlConnection.createStatement(anyInt(), anyInt())).thenReturn(statment);
    Map<String, String> attributesPrivateDriver = new HashMap<>();
    attributesPrivateDriver.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, PrivateSQLDriver.class.getName());
    when(genericConnPrivateDriver.getAttributes()).thenReturn(attributesPrivateDriver);
    when(genericConnPrivateDriver.getDatabaseType()).thenReturn(genericDBType);
    Map<String, String> attributesWithNoExistClass = new HashMap<>();
    attributesWithNoExistClass.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "org.test.NoExistDriver");
    when(genericConnWithNoExistClass.getAttributes()).thenReturn(attributesWithNoExistClass);
    when(genericConnWithNoExistClass.getDatabaseType()).thenReturn(genericDBType);
    Map<String, String> attributesNonDriverClass = new HashMap<>();
    attributesNonDriverClass.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, String.class.getName());
    when(genericConnWithNoDriverClass.getAttributes()).thenReturn(attributesNonDriverClass);
    when(genericConnWithNoDriverClass.getDatabaseType()).thenReturn(genericDBType);
    Map<String, String> attributesWithoutClass = new HashMap<>();
    attributesWithoutClass.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "");
    when(genericConnWithoutClass.getAttributes()).thenReturn(attributesWithoutClass);
    when(genericConnWithoutClass.getDatabaseType()).thenReturn(genericDBType);
    Map<String, String> attributesWithClass = new HashMap<>();
    attributesWithClass.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, TestSQLDriver.class.getName());
    when(genericConnWithClass.getAttributes()).thenReturn(attributesWithClass);
    when(genericConnWithClass.getDatabaseType()).thenReturn(genericDBType);
    when(service.getDatasourceByName(anyString())).thenAnswer(new Answer<IDatabaseConnection>() {

        @Override
        public IDatabaseConnection answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getArguments()[0].equals(GENERIC_CONN_PRIVATE_DRIVER)) {
                return genericConnPrivateDriver;
            }
            if (invocation.getArguments()[0].equals(GENERIC_CONN_NOT_DRIVER_CLASS)) {
                return genericConnWithNoDriverClass;
            }
            if (invocation.getArguments()[0].equals(GENERIC_CONN_NOT_FOUND_CLASS)) {
                return genericConnWithNoExistClass;
            }
            if (invocation.getArguments()[0].equals(GENERIC_CONN_WITHOUT_DRIVER_CLASS)) {
                return genericConnWithoutClass;
            }
            if (invocation.getArguments()[0].equals(GENERIC_CONN_DRIVER_CLASS)) {
                return genericConnWithClass;
            }
            if (invocation.getArguments()[0].equals(CONN_CAN_NOT_PREPARED)) {
                return null;
            }
            // throw exception for check if we get exception from getting connection
            throw new DatasourceMgmtServiceException();
        }
    });
    when(resLoader.getPluginSetting(this.anyClass(), anyString(), anyString())).thenReturn(SimpleDataAccessPermissionHandler.class.getName());
    when(policy.isAllowed(anyString())).thenReturn(true);
    pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getArguments()[0].equals(IDatasourceMgmtService.class)) {
                return service;
            }
            if (invocation.getArguments()[0].equals(IAuthorizationPolicy.class)) {
                return policy;
            }
            if (invocation.getArguments()[0].equals(IPluginResourceLoader.class)) {
                return resLoader;
            }
            return null;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) HashMap(java.util.HashMap) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Connection(java.sql.Connection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Matchers.anyString(org.mockito.Matchers.anyString) URL(java.net.URL) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) SimpleDataAccessPermissionHandler(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.SimpleDataAccessPermissionHandler) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) Before(org.junit.Before)

Example 85 with IDatabaseConnection

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

the class AnalysisImportDialogController method init.

public void init() {
    try {
        connectionAutoBeanFactory = GWT.create(IConnectionAutoBeanFactory.class);
        resBundle = (ResourceBundle) super.getXulDomContainer().getResourceBundles().get(0);
        // connectionService = new ConnectionServiceGwtImpl();
        importDialogModel = new AnalysisImportDialogModel();
        connectionList = (XulMenuList) document.getElementById("connectionList");
        analysisParametersTree = (XulTree) document.getElementById("analysisParametersTree");
        importDialog = (XulDialog) document.getElementById("importDialog");
        analysisParametersDialog = (XulDialog) document.getElementById("analysisParametersDialog");
        paramNameTextBox = (XulTextbox) document.getElementById("paramNameTextBox");
        paramNameTextBox.addPropertyChangeListener(new ParametersChangeListener());
        paramValueTextBox = (XulTextbox) document.getElementById("paramValueTextBox");
        paramValueTextBox.addPropertyChangeListener(new ParametersChangeListener());
        analysisPreferencesDeck = (XulDeck) document.getElementById("analysisPreferencesDeck");
        availableRadio = (XulRadio) document.getElementById("availableRadio");
        manualRadio = (XulRadio) document.getElementById("manualRadio");
        hiddenArea = (XulVbox) document.getElementById("analysisImportCard");
        schemaNameLabel = (XulLabel) document.getElementById("schemaNameLabel");
        analysisFileLabel = (XulLabel) document.getElementById("analysisFileLabel");
        uploadAnalysisButton = (XulButton) document.getElementById("uploadAnalysisButton");
        acceptButton = (XulButton) document.getElementById("importDialog_accept");
        acceptButton.setDisabled(true);
        parametersAcceptButton = (XulButton) document.getElementById("analysisParametersDialog_accept");
        parametersAcceptButton.setDisabled(true);
        bf.setBindingType(Binding.Type.ONE_WAY);
        bf.createBinding(connectionList, "selectedIndex", importDialogModel, "connection", new BindingConvertor<Integer, IDatabaseConnection>() {

            @Override
            public Integer targetToSource(IDatabaseConnection connection) {
                return -1;
            }

            @Override
            public IDatabaseConnection sourceToTarget(Integer value) {
                if (value >= 0) {
                    return importDialogModel.getConnectionList().get(value);
                }
                return null;
            }
        });
        bf.createBinding(manualRadio, "checked", this, "preference", new PreferencesBindingConvertor());
        bf.createBinding(this, "connectionNames", connectionList, "elements");
        Binding domainBinding = bf.createBinding(importDialogModel, "connectionList", this, "relationalConnections");
        Binding analysisParametersBinding = bf.createBinding(importDialogModel, "analysisParameters", analysisParametersTree, "elements");
        domainBinding.fireSourceChanged();
        analysisParametersBinding.fireSourceChanged();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Binding(org.pentaho.ui.xul.binding.Binding) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IConnectionAutoBeanFactory(org.pentaho.ui.database.event.IConnectionAutoBeanFactory) XulException(org.pentaho.ui.xul.XulException) RequestException(com.google.gwt.http.client.RequestException)

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