Search in sources :

Example 76 with IDatabaseConnection

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

the class WizardConnectionController method testConnection.

@Bindable
public void testConnection() {
    RequestBuilder testConnectionBuilder = new RequestBuilder(RequestBuilder.PUT, ConnectionController.getServiceURL("test"));
    testConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        // AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
        AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
        testConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                displayErrorMessage(exception);
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                Boolean testPassed = new Boolean(response.getText());
                try {
                    if (testPassed) {
                        openSuccesDialog(MessageHandler.getString("SUCCESS"), // $NON-NLS-1$
                        MessageHandler.getString(// $NON-NLS-1$
                        "ConnectionController.CONNECTION_TEST_SUCCESS"));
                    } else {
                        openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
                        MessageHandler.getString(// $NON-NLS-1$
                        "ConnectionController.ERROR_0003_CONNECTION_TEST_FAILED"));
                    }
                } catch (Exception e) {
                    displayErrorMessage(e);
                }
            }
        });
    } catch (RequestException e) {
        displayErrorMessage(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 77 with IDatabaseConnection

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

the class WizardRelationalDatasourceController method init.

@Bindable
public void init(final DatasourceModel datasourceModel) {
    this.datasourceModel = datasourceModel;
    bf = new GwtBindingFactory(document);
    // $NON-NLS-1$
    sampleDataTree = (XulTree) document.getElementById("relationalSampleDataTable");
    // $NON-NLS-1$
    aggregationEditorDialog = (XulDialog) document.getElementById("relationalAggregationEditorDialog");
    // $NON-NLS-1$
    sampleDataDialog = (XulDialog) document.getElementById("relationalSampleDataDialog");
    // $NON-NLS-1$
    errorDialog = (XulDialog) document.getElementById("errorDialog");
    // $NON-NLS-1$
    errorLabel = (XulLabel) document.getElementById("errorLabel");
    // $NON-NLS-1$
    applyQueryConfirmationDialog = (XulDialog) document.getElementById("applyQueryConfirmationDialog");
    // $NON-NLS-1$
    errorLabel = (XulLabel) document.getElementById("errorLabel");
    // $NON-NLS-1$
    successDialog = (XulDialog) document.getElementById("successDialog");
    // $NON-NLS-1$
    successLabel = (XulLabel) document.getElementById("successLabel");
    // $NON-NLS-1$
    datasourceName = (XulTextbox) document.getElementById("datasourceName");
    // $NON-NLS-1$
    connections = (XulListbox) document.getElementById("connectionList");
    // $NON-NLS-1$
    query = (XulTextbox) document.getElementById("query");
    // $NON-NLS-1$
    connectionDialog = (XulDialog) document.getElementById("connectionDialog");
    // $NON-NLS-1$
    previewResultsDialog = (XulDialog) document.getElementById("previewResultsDialog");
    // $NON-NLS-1$
    previewResultsTable = (XulTree) document.getElementById("previewResultsTable");
    // $NON-NLS-1$
    previewResultsTreeCols = (XulTreeCols) document.getElementById("previewResultsTreeCols");
    // $NON-NLS-1$
    previewLimit = (XulTextbox) document.getElementById("previewLimit");
    // $NON-NLS-1$
    editConnectionButton = (XulButton) document.getElementById("editConnection");
    // $NON-NLS-1$
    removeConnectionButton = (XulButton) document.getElementById("removeConnection");
    // $NON-NLS-1$
    editQueryButton = (XulButton) document.getElementById("editQuery");
    // $NON-NLS-1$
    previewButton = (XulButton) document.getElementById("preview");
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(datasourceModel.getGuiStateModel(), "relationalPreviewValidated", previewButton, // $NON-NLS-1$ //$NON-NLS-2$
    "!disabled");
    List<Binding> bindingsThatNeedInitialized = new ArrayList<Binding>();
    BindingConvertor<IDatabaseConnection, Boolean> buttonConvertor = new BindingConvertor<IDatabaseConnection, Boolean>() {

        @Override
        public Boolean sourceToTarget(IDatabaseConnection value) {
            return !(value == null);
        }

        @Override
        public IDatabaseConnection targetToSource(Boolean value) {
            return null;
        }
    };
    bf.setBindingType(Binding.Type.ONE_WAY);
    final Binding domainBinding = bf.createBinding(datasourceModel.getGuiStateModel(), "connections", this, // $NON-NLS-1$ //$NON-NLS-2$
    "relationalConnections");
    // $NON-NLS-1$
    bf.createBinding(this, connectionNamesListProp, connections, "elements");
    bf.createBinding(datasourceModel, "selectedRelationalConnection", editConnectionButton, "!disabled", // $NON-NLS-1$ //$NON-NLS-2$
    buttonConvertor);
    bf.createBinding(datasourceModel, "selectedRelationalConnection", removeConnectionButton, "!disabled", // $NON-NLS-1$ //$NON-NLS-2$
    buttonConvertor);
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    bf.createBinding(datasourceModel, "selectedRelationalConnection", connections, "selectedIndex", new // $NON-NLS-1$ //$NON-NLS-2$
    BindingConvertor<IDatabaseConnection, Integer>() {

        @Override
        public Integer sourceToTarget(IDatabaseConnection connection) {
            if (connection != null) {
                return datasourceModel.getGuiStateModel().getConnectionIndex(connection);
            }
            return -1;
        }

        @Override
        public IDatabaseConnection targetToSource(Integer value) {
            if (value >= 0) {
                return datasourceModel.getGuiStateModel().getConnections().get(value);
            }
            return null;
        }
    });
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    bf.createBinding(datasourceModel.getGuiStateModel(), "previewLimit", previewLimit, // $NON-NLS-1$ //$NON-NLS-2$
    "value");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(datasourceModel, "query", query, "value");
    try {
        // Fires the population of the model listbox. This cascades down to the categories and columns. In essence, this
        // call initializes the entire UI.
        domainBinding.fireSourceChanged();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
    for (Binding b : bindingsThatNeedInitialized) {
        try {
            b.fireSourceChanged();
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
}
Also used : Binding(org.pentaho.ui.xul.binding.Binding) GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory) ArrayList(java.util.ArrayList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) XulException(org.pentaho.ui.xul.XulException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 78 with IDatabaseConnection

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

the class JdbcDatasourceResourceTest method testGetConnection.

@Test
public void testGetConnection() throws Exception {
    IDatabaseConnection mockIDatabaseConnection = mock(IDatabaseConnection.class);
    doReturn(mockIDatabaseConnection).when(jdbcDatasourceResource.service).getConnectionByName("Name");
    Response mockResponse = mock(Response.class);
    doReturn(mockResponse).when(jdbcDatasourceResource).buildOkResponse(mockIDatabaseConnection);
    Response response = jdbcDatasourceResource.getConnection("Name");
    verify(jdbcDatasourceResource, times(1)).getConnection("Name");
    assertEquals(response, mockResponse);
}
Also used : Response(javax.ws.rs.core.Response) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 79 with IDatabaseConnection

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

the class JdbcDatasourceResourceTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
    doReturn("").when(mockDatabaseConnection).getPassword();
    doReturn("id").when(mockDatabaseConnection).getName();
    IDatabaseConnection mockSavedConn = mock(IDatabaseConnection.class);
    doReturn(mockSavedConn).when(jdbcDatasourceResource.service).getConnectionByName("id");
    doReturn("password").when(mockSavedConn).getPassword();
    doReturn(true).when(jdbcDatasourceResource.service).updateConnection(mockDatabaseConnection);
    doNothing().when(jdbcDatasourceResource).validateAccess();
    Response mockResponse = mock(Response.class);
    doReturn(mockResponse).when(jdbcDatasourceResource).buildOkResponse();
    Response response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
    verify(jdbcDatasourceResource, times(1)).addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
    assertEquals(response, mockResponse);
}
Also used : Response(javax.ws.rs.core.Response) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 80 with IDatabaseConnection

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

the class TablesSelectionStep method refresh.

@Override
public void refresh() {
    IDatabaseConnection connection = ((MultiTableDatasource) parentDatasource).getConnection();
    joinSelectionServiceGwtImpl.retrieveSchemas(connection, new XulServiceCallback<List>() {

        public void error(String message, Throwable error) {
            error.printStackTrace();
            mtdatasource.displayErrors(new JoinError(message, error.getMessage()));
        }

        public void success(List schemaValues) {
            schemas.removePropertyChangeListener(schemaSelection);
            joinGuiModel.setSchemas(schemaValues);
            schemas.addPropertyChangeListener(schemaSelection);
            fetchTables();
        }
    });
}
Also used : XulMenuList(org.pentaho.ui.xul.components.XulMenuList) ArrayList(java.util.ArrayList) List(java.util.List) AbstractModelList(org.pentaho.ui.xul.util.AbstractModelList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

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