Search in sources :

Example 31 with RequestBuilder

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

the class EmailAdminPanelController method getEmailConfig.

private void getEmailConfig() {
    String serviceUrl = GWT.getHostPageBaseURL() + "api/emailconfig/getEmailConfig?cb=" + System.currentTimeMillis();
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, serviceUrl);
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            }

            public void onResponseReceived(Request request, Response response) {
                emailConfig = JsEmailConfiguration.parseJsonString(response.getText());
                authenticationCheckBox.setValue(Boolean.parseBoolean(emailConfig.isAuthenticate() + ""));
                authenticationPanel.setVisible(Boolean.parseBoolean(emailConfig.isAuthenticate() + ""));
                smtpHostTextBox.setValue(emailConfig.getSmtpHost());
                portTextBox.setValue(emailConfig.getSmtpPort() + "");
                useStartTLSCheckBox.setValue(Boolean.parseBoolean(emailConfig.isUseStartTls() + ""));
                useSSLCheckBox.setValue(Boolean.parseBoolean(emailConfig.isUseSsl() + ""));
                fromAddressTextBox.setValue(emailConfig.getDefaultFrom());
                fromNameTextBox.setValue(emailConfig.getFromName());
                userNameTextBox.setValue(emailConfig.getUserId());
                // If password is non-empty.. disable the text-box
                String password = emailConfig.getPassword();
                passwordTextBox.setValue(password);
                String protocol = emailConfig.getSmtpProtocol();
                protocolsListBox.setSelectedIndex(-1);
                if (!StringUtils.isEmpty(protocol)) {
                    for (int i = 0; i < protocolsListBox.getItemCount(); ++i) {
                        if (protocol.equalsIgnoreCase(protocolsListBox.getItemText(i))) {
                            protocolsListBox.setSelectedIndex(i);
                            break;
                        }
                    }
                }
            }
        });
    } catch (RequestException e) {
    // ignored
    }
}
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)

Example 32 with RequestBuilder

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

the class PermissionsPanel method saveSecuritySettings.

private void saveSecuritySettings() {
    JSONObject jsNewRoleAssignments = new JSONObject();
    JSONArray jsLogicalRoleAssignments = new JSONArray();
    int x = 0;
    for (Map.Entry<String, List<String>> roleAssignment : newRoleAssignments.entrySet()) {
        JSONArray jsLogicalRoles = new JSONArray();
        int y = 0;
        for (String logicalRoleName : roleAssignment.getValue()) {
            jsLogicalRoles.set(y++, new JSONString(logicalRoleName));
        }
        JSONObject jsRoleAssignment = new JSONObject();
        jsRoleAssignment.put("roleName", new JSONString(roleAssignment.getKey()));
        jsRoleAssignment.put("logicalRoles", jsLogicalRoles);
        jsLogicalRoleAssignments.set(x++, jsRoleAssignment);
    }
    jsNewRoleAssignments.put("assignments", jsLogicalRoleAssignments);
    RequestBuilder saveSettingRequestBuilder = new RequestBuilder(RequestBuilder.PUT, GWT.getHostPageBaseURL() + "api/userroledao/roleAssignments");
    saveSettingRequestBuilder.setHeader("Content-Type", "application/json");
    saveSettingRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        saveSettingRequestBuilder.sendRequest(jsNewRoleAssignments.toString(), new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    masterRoleMap.putAll(newRoleAssignments);
                    newRoleAssignments.clear();
                }
            }
        });
    } catch (RequestException e) {
    // ignored
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) JSONArray(com.google.gwt.json.client.JSONArray) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) JSONObject(com.google.gwt.json.client.JSONObject) RequestCallback(com.google.gwt.http.client.RequestCallback) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) JSONString(com.google.gwt.json.client.JSONString)

Example 33 with RequestBuilder

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

the class AdhocRunInBackgroundCommand method parseFolderId.

private RequestBuilder parseFolderId(Response response) {
    String folderId = null;
    Document repository = XMLParser.parse(response.getText());
    NodeList fileNodeList = repository.getElementsByTagName("file");
    for (int i = 0; i < fileNodeList.getLength(); i++) {
        Element element = (Element) fileNodeList.item(i);
        Node pathNode = element.getElementsByTagName("path").item(0);
        if (getOutputLocationPath().equals(pathNode.getFirstChild().getNodeValue())) {
            folderId = element.getElementsByTagName("id").item(0).getFirstChild().getNodeValue();
        }
    }
    RequestBuilder scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.POST, contextURL + "plugin/reporting/api/jobs/" + jobId + "/schedule?confirm=true&folderId=" + folderId + "&newName=" + getOutputName() + "&recalculateFinished=" + getRecalculateFinished());
    scheduleFileRequestBuilder.setHeader("Content-Type", "application/json");
    scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    return scheduleFileRequestBuilder;
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) Node(com.google.gwt.xml.client.Node) Document(com.google.gwt.xml.client.Document)

Example 34 with RequestBuilder

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

the class CheckForSoftwareUpdatesCommand method performOperation.

protected void performOperation(boolean feedback) {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/version/softwareUpdates";
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    requestBuilder.setHeader("accept", "text/plain");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("softwareUpdates"), Messages.getString("noUpdatesAvailable"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                true);
                dialogBox.center();
            }

            public void onResponseReceived(Request request, Response response) {
                Document doc = XMLParser.parse(response.getText());
                // $NON-NLS-1$
                NodeList updates = doc.getElementsByTagName("update");
                if (updates.getLength() > 0) {
                    FlexTable updateTable = new FlexTable();
                    // $NON-NLS-1$
                    updateTable.setStyleName("backgroundContentTable");
                    // $NON-NLS-1$
                    updateTable.setWidget(0, 0, new Label(Messages.getString("version")));
                    // $NON-NLS-1$
                    updateTable.setWidget(0, 1, new Label(Messages.getString("type")));
                    // $NON-NLS-1$
                    updateTable.setWidget(0, 2, new Label(Messages.getString("os")));
                    // $NON-NLS-1$
                    updateTable.setWidget(0, 3, new Label(Messages.getString("link")));
                    // $NON-NLS-1$
                    updateTable.getCellFormatter().setStyleName(0, 0, "backgroundContentHeaderTableCell");
                    // $NON-NLS-1$
                    updateTable.getCellFormatter().setStyleName(0, 1, "backgroundContentHeaderTableCell");
                    // $NON-NLS-1$
                    updateTable.getCellFormatter().setStyleName(0, 2, "backgroundContentHeaderTableCell");
                    // $NON-NLS-1$
                    updateTable.getCellFormatter().setStyleName(0, 3, "backgroundContentHeaderTableCellRight");
                    for (int i = 0; i < updates.getLength(); i++) {
                        Element updateElement = (Element) updates.item(i);
                        // $NON-NLS-1$
                        String version = updateElement.getAttribute("version");
                        // $NON-NLS-1$
                        String type = updateElement.getAttribute("type");
                        // $NON-NLS-1$
                        String os = updateElement.getAttribute("os");
                        // String title = updateElement.getAttribute("title");
                        // $NON-NLS-1$
                        String downloadURL = updateElement.getElementsByTagName("downloadurl").item(0).toString();
                        // $NON-NLS-1$ //$NON-NLS-2$
                        downloadURL = downloadURL.substring(downloadURL.indexOf("http"), downloadURL.indexOf("]"));
                        updateTable.setWidget(i + 1, 0, new Label(version));
                        updateTable.setWidget(i + 1, 1, new Label(type));
                        updateTable.setWidget(i + 1, 2, new Label(os));
                        updateTable.setWidget(i + 1, 3, new HTML("<A HREF=\"" + downloadURL + "\" target=\"_blank\" title=\"" + downloadURL + "\">" + Messages.getString("download") + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                        "</A>"));
                        // $NON-NLS-1$
                        updateTable.getCellFormatter().setStyleName(i + 1, 0, "backgroundContentTableCell");
                        // $NON-NLS-1$
                        updateTable.getCellFormatter().setStyleName(i + 1, 1, "backgroundContentTableCell");
                        // $NON-NLS-1$
                        updateTable.getCellFormatter().setStyleName(i + 1, 2, "backgroundContentTableCell");
                        // $NON-NLS-1$
                        updateTable.getCellFormatter().setStyleName(i + 1, 3, "backgroundContentTableCellRight");
                        if (i == updates.getLength() - 1) {
                            // last
                            // $NON-NLS-1$
                            updateTable.getCellFormatter().setStyleName(i + 1, 0, "backgroundContentTableCellBottom");
                            // $NON-NLS-1$
                            updateTable.getCellFormatter().setStyleName(i + 1, 1, "backgroundContentTableCellBottom");
                            // $NON-NLS-1$
                            updateTable.getCellFormatter().setStyleName(i + 1, 2, "backgroundContentTableCellBottom");
                            // $NON-NLS-1$
                            updateTable.getCellFormatter().setStyleName(i + 1, 3, "backgroundContentTableCellBottomRight");
                        }
                    }
                    PromptDialogBox versionPromptDialog = new PromptDialogBox(Messages.getString("softwareUpdateAvailable"), Messages.getString("ok"), null, false, true, // $NON-NLS-1$ //$NON-NLS-2$
                    updateTable);
                    versionPromptDialog.center();
                } else {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("softwareUpdates"), Messages.getString("noUpdatesAvailable"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                    true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // showError(e);
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) Request(com.google.gwt.http.client.Request) FlexTable(com.google.gwt.user.client.ui.FlexTable) Label(com.google.gwt.user.client.ui.Label) HTML(com.google.gwt.user.client.ui.HTML) Document(com.google.gwt.xml.client.Document) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback)

Example 35 with RequestBuilder

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

the class ExecuteGlobalActionsCommand method performOperation.

protected void performOperation() {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/system/refresh/globalActions";
    RequestBuilder requestBuilder = new CsrfRequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("accept", "text/plain");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), Messages.getString("globalActionsExecutedSuccessfully"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                true);
                dialogBox.center();
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) 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