Search in sources :

Example 91 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.

the class ConnectionController method handleDialogAccept.

@Bindable
public void handleDialogAccept() {
    // first, test the connection
    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) {
                saveConnectionConfirmationDialog.show();
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                try {
                    if (response.getStatusCode() == Response.SC_OK) {
                        // test is ok, now check if we are renaming
                        renameCheck();
                    } else {
                        // confirm if we should continu saving this invalid connection.
                        saveConnectionConfirmationDialog.show();
                    }
                } 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 92 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.

the class ConnectionController method overwriteConnection.

@Bindable
public void overwriteConnection() {
    if (!saveConnectionConfirmationDialog.isHidden()) {
        closeSaveConnectionConfirmationDialog();
    }
    if (!renameConnectionConfirmationDialog.isHidden()) {
        closeRenameConnectionConfirmationDialog();
    }
    if (!overwriteConnectionConfirmationDialog.isHidden()) {
        overwriteConnectionConfirmationDialog.hide();
    }
    existingConnectionName = currentConnection.getName();
    currentConnection.setId(existingConnectionId);
    if (previousConnectionName != null) {
        RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, getServiceURL("deletebyname", new String[][] { { "name", previousConnectionName } }));
        try {
            deleteConnectionBuilder.sendRequest(null, 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) {
                            openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
                            MessageHandler.getString(// $NON-NLS-1$
                            "ConnectionController.ERROR_0002_UNABLE_TO_DELETE_CONNECTION"));
                        }
                    } catch (Exception e) {
                        displayErrorMessage(e);
                    }
                }
            });
        } catch (RequestException e) {
            displayErrorMessage(e);
        }
    }
    updateConnection();
}
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) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 93 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.

the class ConnectionController method testConnection.

@Bindable
public void testConnection() {
    RequestBuilder testConnectionBuilder = new RequestBuilder(RequestBuilder.PUT, getServiceURL("test"));
    testConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(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 94 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.

the class ConnectionController method updateConnection.

@Bindable
public void updateConnection() {
    RequestBuilder updateConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("update"));
    updateConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
        updateConnectionBuilder.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().updateConnection(existingConnectionName, 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_0004_UNABLE_TO_UPDATE_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)

Example 95 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.

the class ConnectionController method reloadConnections.

public void reloadConnections() {
    String cacheBuster = String.valueOf(new java.util.Date().getTime());
    String[][] params = new String[][] { { "ts", cacheBuster } };
    RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getServiceURL("list", params));
    listConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        listConnectionBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), MessageHandler.getString("DatasourceEditor.ERROR_0002_UNABLE_TO_SHOW_DIALOG", exception.getLocalizedMessage()));
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
                List<IDatabaseConnection> connectionBeanList = bean.as().getDatabaseConnections();
                List<IDatabaseConnection> connectionImplList = new ArrayList<IDatabaseConnection>();
                for (IDatabaseConnection connectionBean : connectionBeanList) {
                    try {
                        // take anything except connections where STANDARD_CONNECTION == false
                        if ((connectionBean.getAttributes() == null) || (connectionBean.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == null) || (connectionBean.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == Boolean.TRUE.toString())) {
                            connectionImplList.add(AutobeanUtilities.connectionBeanToImpl(connectionBean));
                        }
                    } catch (Exception e) {
                    // skip invalid connections that couldn't be converted to IDatabaseConnection
                    }
                }
                if (datasourceModel != null) {
                    datasourceModel.getGuiStateModel().setConnections(connectionImplList);
                }
            }
        });
    } catch (RequestException e) {
        MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), "DatasourceEditor.ERROR_0004_CONNECTION_SERVICE_NULL");
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) AutoBean(com.google.web.bindery.autobean.shared.AutoBean) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Aggregations

RequestBuilder (com.google.gwt.http.client.RequestBuilder)132 RequestException (com.google.gwt.http.client.RequestException)116 RequestCallback (com.google.gwt.http.client.RequestCallback)113 Response (com.google.gwt.http.client.Response)111 Request (com.google.gwt.http.client.Request)110 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)27 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)22 JSONString (com.google.gwt.json.client.JSONString)19 ArrayList (java.util.ArrayList)16 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)13 JSONObject (com.google.gwt.json.client.JSONObject)11 JsArrayString (com.google.gwt.core.client.JsArrayString)9 JSONArray (com.google.gwt.json.client.JSONArray)8 List (java.util.List)8 HTML (com.google.gwt.user.client.ui.HTML)7 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)7 EmptyRequestCallback (org.pentaho.mantle.client.EmptyRequestCallback)7 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)6 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)6