Search in sources :

Example 86 with RequestBuilder

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

the class WizardConnectionController method deleteConnection.

@Bindable
public void deleteConnection() {
    removeConfirmationDialog.hide();
    RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, ConnectionController.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) 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 87 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder 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 88 with RequestBuilder

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

the class AnalysisImportDialogController method reloadConnections.

private void reloadConnections() {
    String cacheBuster = "?ts=" + new java.util.Date().getTime();
    RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getBaseURL() + "list" + cacheBuster);
    listConnectionBuilder.setHeader("Content-Type", "application/json");
    listConnectionBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        listConnectionBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                exception.printStackTrace();
                MessageHandler.getInstance().showErrorDialog(exception.getMessage());
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
                List<IDatabaseConnection> databaseConnections = bean.as().getDatabaseConnections();
                List<IDatabaseConnection> standardDatabaseConnections = new ArrayList();
                // take anything except connections where STANDARD_CONNECTION == false
                for (IDatabaseConnection databaseConnection : databaseConnections) {
                    if ((databaseConnection.getAttributes() == null) || (databaseConnection.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == null) || (databaseConnection.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == Boolean.TRUE.toString())) {
                        standardDatabaseConnections.add(databaseConnection);
                    }
                }
                importDialogModel.setConnectionList(standardDatabaseConnections);
            }
        });
    } 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) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) AutoBean(com.google.web.bindery.autobean.shared.AutoBean) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) XulMenuList(org.pentaho.ui.xul.components.XulMenuList) List(java.util.List) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 89 with RequestBuilder

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

the class AnalysisImportDialogController method editDatasource.

public void editDatasource(final IDatasourceInfo datasourceInfo) {
    this.datasourceInfo = datasourceInfo;
    boolean isEditMode = datasourceInfo != null;
    // MONDRIAN-1731 uploadAnalysisButton.setDisabled(isEditMode);
    acceptButton.setLabel(isEditMode ? resBundle.getString("importDialog.SAVE") : resBundle.getString("importDialog.IMPORT"));
    if (!isEditMode) {
        return;
    }
    String url = GWT.getModuleBaseURL();
    int indexOfContent = url.indexOf("content");
    if (indexOfContent > -1) {
        url = url.substring(0, indexOfContent);
        url = url + "plugin/data-access/api/datasource/" + NameUtils.URLEncode(datasourceInfo.getId()) + "/getAnalysisDatasourceInfo";
    }
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable e) {
                logger.log(Level.ALL, e.getMessage());
            }

            public void onResponseReceived(Request request, final Response response) {
                boolean paramHandled, hasParameters = false;
                String responseValue = response.getText();
                StringBuilder name = new StringBuilder();
                StringBuilder value = new StringBuilder();
                int state = 0;
                char ch;
                int i, len = responseValue.length();
                for (i = 0; i < len; i++) {
                    ch = responseValue.charAt(i);
                    switch(state) {
                        case // new name/value pair
                        0:
                            paramHandled = handleParam(name, value);
                            if (!hasParameters) {
                                hasParameters = paramHandled;
                            }
                            switch(ch) {
                                case ';':
                                    break;
                                default:
                                    state = 1;
                                    name.append(ch);
                            }
                            break;
                        case // looking for equals
                        1:
                            switch(ch) {
                                case '=':
                                    state = 2;
                                    break;
                                default:
                                    name.append(ch);
                            }
                            break;
                        case // about to parse the value
                        2:
                            switch(ch) {
                                case '"':
                                    state = 3;
                                    break;
                                case ';':
                                    state = 0;
                                    break;
                                default:
                                    value.append(ch);
                                    state = 4;
                            }
                            break;
                        case // parse value till closing quote.
                        3:
                            switch(ch) {
                                case '"':
                                    state = 0;
                                    break;
                                default:
                                    value.append(ch);
                            }
                            break;
                        case 4:
                            switch(ch) {
                                case ';':
                                    state = 0;
                                    break;
                                default:
                                    value.append(ch);
                            }
                            break;
                        default:
                    }
                }
                paramHandled = handleParam(name, value);
                if (!hasParameters) {
                    hasParameters = paramHandled;
                }
                schemaNameLabel.setValue(datasourceInfo.getId() + ".mondrian.xml");
                importDialogModel.setUploadedFile(datasourceInfo.getId());
                int preference;
                XulRadio radio;
                if (hasParameters) {
                    preference = PARAMETER_MODE;
                    radio = manualRadio;
                } else {
                    preference = DATASOURCE_MODE;
                    radio = availableRadio;
                }
                setPreference(preference);
                radio.setSelected(true);
            }
        });
    } catch (Exception e) {
        logger.log(Level.ALL, e.getMessage());
    }
}
Also used : Response(com.google.gwt.http.client.Response) XulRadio(org.pentaho.ui.xul.components.XulRadio) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) XulException(org.pentaho.ui.xul.XulException) RequestException(com.google.gwt.http.client.RequestException)

Example 90 with RequestBuilder

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

the class DatasourceServiceManagerGwtImpl method remove.

/* (non-Javadoc)
   * @see org.pentaho.platform.dataaccess.datasource.wizard.service.IXulAsyncDatasourceServiceManager#remove(org
   * .pentaho.platform.dataaccess.datasource.IDatasourceInfo)
   */
@Override
public void remove(IDatasourceInfo dsInfo, final Object xulCallback) {
    final String removeURL;
    String datasourceId = NameUtils.URLEncode(dsInfo.getId());
    if (dsInfo.getType() == MetadataUIDatasourceService.TYPE) {
        removeURL = getWebAppRoot() + "plugin/data-access/api/datasource/metadata/" + datasourceId + "/remove";
    } else if (dsInfo.getType() == MondrianUIDatasourceService.TYPE) {
        removeURL = getWebAppRoot() + "plugin/data-access/api/datasource/analysis/" + datasourceId + "/remove";
    } else if (dsInfo.getType() == DSWUIDatasourceService.TYPE) {
        removeURL = getWebAppRoot() + "plugin/data-access/api/datasource/dsw/" + datasourceId + "/remove";
    } else {
        removeURL = null;
    }
    AuthenticatedGwtServiceUtil.invokeCommand(new IAuthenticatedGwtCommand<Boolean>() {

        public void execute(final AsyncCallback<Boolean> callback) {
            RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, removeURL);
            try {
                requestBuilder.sendRequest(null, new RequestCallback() {

                    @Override
                    public void onError(Request request, Throwable exception) {
                        callback.onFailure(exception);
                    }

                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        callback.onSuccess(response.getStatusCode() == Response.SC_OK);
                    }
                });
            } catch (RequestException e) {
                XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) xulCallback;
                responseCallback.error(e.getLocalizedMessage(), e);
            }
        }
    }, new AsyncCallback<Boolean>() {

        public void onFailure(Throwable e) {
            XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) xulCallback;
            responseCallback.error(e.getLocalizedMessage(), e);
        }

        public void onSuccess(Boolean arg) {
            XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) xulCallback;
            responseCallback.success(arg);
        }
    });
}
Also used : Response(com.google.gwt.http.client.Response) XulServiceCallback(org.pentaho.ui.xul.XulServiceCallback) 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)

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