Search in sources :

Example 11 with IDatabaseConnection

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

the class GwtDatasourceEditorEntryPoint method showEditDatabaseDialog.

public void showEditDatabaseDialog(final DialogListener dialogListener, final String databaseName) {
    String cacheBuster = String.valueOf(new java.util.Date().getTime());
    String url = ConnectionController.getServiceURL("get", new String[][] { { "name", databaseName }, { "ts", cacheBuster } });
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setHeader("Accept", "application/json");
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                Window.alert(exception.toString());
            }

            @SuppressWarnings("deprecation")
            public void onResponseReceived(Request request, Response response) {
                IDatabaseConnection conn = null;
                if (response.getStatusCode() == Response.SC_OK) {
                    AutoBean<IDatabaseConnection> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnection.class, response.getText());
                    conn = bean.as();
                }
                ConnectionController connectionController = wizard.getConnectionController();
                connectionController.init();
                DatasourceModel datasourceModel = connectionController.getDatasourceModel();
                if (datasourceModel == null) {
                    datasourceModel = new DatasourceModel();
                }
                datasourceModel.setSelectedRelationalConnection(conn);
                // This is important for edit mode of datasource model
                datasourceModel.setEditing(true);
                connectionController.setDatasourceModel(datasourceModel);
                connectionController.showEditConnectionDialog(dialogListener, conn);
            }
        });
    } catch (Exception e) {
        Window.alert("Cannot edit datasource");
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) AutoBean(com.google.web.bindery.autobean.shared.AutoBean) XulException(org.pentaho.ui.xul.XulException) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) DatasourceModel(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceModel) RequestCallback(com.google.gwt.http.client.RequestCallback) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionController(org.pentaho.platform.dataaccess.datasource.wizard.controllers.ConnectionController)

Example 12 with IDatabaseConnection

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

the class AnalysisImportDialogController method handleParam.

protected boolean handleParam(StringBuilder name, StringBuilder value) {
    if (name.length() == 0 && value.length() == 0) {
        return false;
    }
    boolean hasParameters = false;
    boolean connectionFound = false;
    String paramName = name.toString();
    // Unescape quotes is used, because value can contain &quot; elements.
    String paramValue = DataSourceInfoUtil.unescapeQuotes(value.toString());
    if (paramName.equalsIgnoreCase("Datasource")) {
        for (IDatabaseConnection connection : importDialogModel.getConnectionList()) {
            if (connection.getName().equals(paramValue)) {
                importDialogModel.setConnection(connection);
                connectionFound = true;
            }
        }
        // always add the Datasource so if the toggle is selected it displays -
        // it may be JNDI and not in DSW
        importDialogModel.addParameter(paramName, paramValue);
        hasParameters = !connectionFound;
    } else {
        if (!paramName.equalsIgnoreCase("overwrite") && !paramName.equalsIgnoreCase("Provider")) {
            importDialogModel.addParameter(paramName, paramValue);
            // this is the default value so do not treat it as a param to flip to manual mode
            if ((paramName.equalsIgnoreCase("EnableXmla") && paramValue.equalsIgnoreCase("true"))) {
                hasParameters = false;
            } else {
                hasParameters = true;
            }
        }
    }
    name.setLength(0);
    value.setLength(0);
    return hasParameters;
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 13 with IDatabaseConnection

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

the class AnalysisImportDialogModel method setConnection.

@Bindable
public void setConnection(IDatabaseConnection value) {
    IDatabaseConnection previousValue = connection;
    connection = value;
    firePropertyChange("connection", previousValue, value);
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 14 with IDatabaseConnection

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

the class ConnectionController method showEditConnectionDialog.

@SuppressWarnings("deprecation")
public void showEditConnectionDialog(DialogListener dialogListener) {
    IDatabaseConnection connection = datasourceModel.getSelectedRelationalConnection();
    showEditConnectionDialog(dialogListener, connection);
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 15 with IDatabaseConnection

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

the class ConnectionController method addConnection.

@Bindable
public void addConnection() {
    RequestBuilder addConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("add"));
    addConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
        addConnectionBuilder.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) {
                try {
                    if (response.getStatusCode() == Response.SC_OK) {
                        datasourceModel.getGuiStateModel().addConnection(currentConnection);
                        datasourceModel.setSelectedRelationalConnection(currentConnection);
                        DialogListener dialogListener = connectionSetter.getOuterListener();
                        if (dialogListener != null) {
                            dialogListener.onDialogAccept(currentConnection);
                        }
                    } else {
                        openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
                        MessageHandler.getString(// $NON-NLS-1$
                        "ConnectionController.ERROR_0001_UNABLE_TO_ADD_CONNECTION"));
                    }
                } 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) DialogListener(org.pentaho.ui.xul.util.DialogController.DialogListener) ConnectionDialogListener(org.pentaho.platform.dataaccess.datasource.wizard.ConnectionDialogListener) DatabaseDialogListener(org.pentaho.ui.database.event.DatabaseDialogListener) 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)

Aggregations

IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)102 Test (org.junit.Test)32 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