Search in sources :

Example 51 with Response

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

the class ConnectionController method overwriteCheck.

@Bindable
public void overwriteCheck() {
    if (!saveConnectionConfirmationDialog.isHidden()) {
        closeSaveConnectionConfirmationDialog();
    }
    if (!renameConnectionConfirmationDialog.isHidden()) {
        closeRenameConnectionConfirmationDialog();
    }
    if (datasourceModel.isEditing() && previousConnectionName.equals(currentConnection.getName())) {
        // if editing and no name change, proceed.
        updateConnection();
    } else {
        // either new connection, or editing involved a name change.
        RequestBuilder checkConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getServiceURL("getid", new String[][] { { "name", currentConnection.getName() } }));
        checkConnectionBuilder.setHeader("Content-Type", "application/json");
        try {
            checkConnectionBuilder.sendRequest(null, new RequestCallback() {

                public void onResponseReceived(Request request, Response response) {
                    switch(response.getStatusCode()) {
                        case Response.SC_OK:
                            existingConnectionId = response.getText();
                            showOverwriteConnectionConfirmationDialog();
                            break;
                        case Response.SC_NOT_FOUND:
                            saveConnection();
                            break;
                        default:
                            // TODO: error message
                            saveConnection();
                    }
                }

                public void onError(Request request, Throwable exception) {
                    displayErrorMessage(exception);
                }
            });
        } catch (Exception 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) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 52 with Response

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

the class ConnectionController method deleteConnection.

@Bindable
public void deleteConnection() {
    removeConfirmationDialog.hide();
    RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, getServiceURL("deletebyname", new String[][] { { "name", datasourceModel.getSelectedRelationalConnection().getName() } }));
    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) {
                        openSuccesDialog(MessageHandler.getString("SUCCESS"), // $NON-NLS-1$
                        MessageHandler.getString(// $NON-NLS-1$
                        "ConnectionController.CONNECTION_DELETED"));
                        datasourceModel.getGuiStateModel().deleteConnection(datasourceModel.getSelectedRelationalConnection().getName());
                        List<IDatabaseConnection> connections = datasourceModel.getGuiStateModel().getConnections();
                        if (connections != null && connections.size() > 0) {
                            datasourceModel.setSelectedRelationalConnection(connections.get(connections.size() - 1));
                        } else {
                            datasourceModel.setSelectedRelationalConnection(null);
                        }
                    } else {
                        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);
    }
}
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) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) List(java.util.List) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 53 with Response

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

the class JdbcDatasourceService method remove.

/* (non-Javadoc)
   * @see org.pentaho.platform.dataaccess.datasource.ui.service.IUIDatasourceAdminService#remove(org.pentaho.platform
   * .dataaccess.datasource.IDatasourceInfo)
   */
@Override
public void remove(IDatasourceInfo dsInfo, Object callback) {
    final XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) callback;
    RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, getBaseURL() + NameUtils.URLEncode("deletebyname?name={0}", dsInfo.getId()));
    try {
        deleteConnectionBuilder.sendRequest(null, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                responseCallback.success(response.getStatusCode() == Response.SC_OK);
            }

            public void onError(Request request, Throwable error) {
                responseCallback.error(error.getLocalizedMessage(), error);
            }
        });
    } catch (RequestException e) {
        responseCallback.error(e.getLocalizedMessage(), e);
    }
}
Also used : XulServiceCallback(org.pentaho.ui.xul.XulServiceCallback) 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)

Example 54 with Response

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

the class WizardConnectionController 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 55 with Response

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

the class WizardConnectionController 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 = AutoBeanUtils.getAutoBean(currentConnection);
        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) {
                        IDatabaseConnection conn = AutobeanUtilities.connectionBeanToImpl(currentConnection);
                        datasourceModel.getGuiStateModel().addConnection(conn);
                        datasourceModel.setSelectedRelationalConnection(conn);
                    } 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) 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

Response (com.google.gwt.http.client.Response)168 Request (com.google.gwt.http.client.Request)166 RequestCallback (com.google.gwt.http.client.RequestCallback)165 RequestException (com.google.gwt.http.client.RequestException)158 RequestBuilder (com.google.gwt.http.client.RequestBuilder)108 JSONException (com.google.gwt.json.client.JSONException)55 HttpException (com.willshex.gson.web.service.client.HttpException)55 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)17 BlockUsersRequest (com.willshex.blogwt.shared.api.user.call.BlockUsersRequest)12 BlockUsersResponse (com.willshex.blogwt.shared.api.user.call.BlockUsersResponse)12 ChangePasswordRequest (com.willshex.blogwt.shared.api.user.call.ChangePasswordRequest)12 ChangePasswordResponse (com.willshex.blogwt.shared.api.user.call.ChangePasswordResponse)12 ChangeUserAccessRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessRequest)12 ChangeUserAccessResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessResponse)12 ChangeUserDetailsRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsRequest)12 ChangeUserDetailsResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsResponse)12 CheckUsernameRequest (com.willshex.blogwt.shared.api.user.call.CheckUsernameRequest)12 CheckUsernameResponse (com.willshex.blogwt.shared.api.user.call.CheckUsernameResponse)12 FollowUsersRequest (com.willshex.blogwt.shared.api.user.call.FollowUsersRequest)12 FollowUsersResponse (com.willshex.blogwt.shared.api.user.call.FollowUsersResponse)12