Search in sources :

Example 96 with RequestBuilder

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

the class DatasourceSelectionDialogController method init.

// ~ Methods =========================================================================================================
/**
 * Sets up bindings.
 */
@Bindable
public void init() {
    internalInit();
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "plugin/data-access/api/permissions/hasDataAccess";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setHeader("accept", "application/json");
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                // $NON-NLS-1$
                showMessagebox("Error", exception.getLocalizedMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                boolean hasDataAccess = new Boolean(response.getText());
                DatasourceSelectionDialogController.this.administrator = hasDataAccess;
                addDatasourceButton.setVisible(hasDataAccess);
                editDatasourceButton.setVisible(hasDataAccess);
                removeDatasourceButton.setVisible(hasDataAccess);
                try {
                    removeDatasourceButtonBinding.fireSourceChanged();
                    editDatasourceButtonBinding.fireSourceChanged();
                } catch (Exception e) {
                    // $NON-NLS-1$
                    showMessagebox("Error", e.getLocalizedMessage());
                }
            }
        });
    } catch (RequestException e) {
    // Do Nothing
    }
}
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) XulException(org.pentaho.ui.xul.XulException) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 97 with RequestBuilder

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

the class JdbcDatasourceService method getIds.

@Override
public void getIds(final XulServiceCallback<List<IDatasourceInfo>> callback) {
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, getMetadataBaseURL() + "getDatasourcePermissions");
    requestBuilder.setHeader("Content-Type", "application/json");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                callback.error(exception.getMessage(), exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getText().equals("EDIT")) {
                    String cacheBuster = "?ts=" + new java.util.Date().getTime();
                    RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getBaseURL() + "list" + cacheBuster);
                    listConnectionBuilder.setHeader("Content-Type", "application/json");
                    try {
                        listConnectionBuilder.sendRequest(null, new RequestCallback() {

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

                            @Override
                            public void onResponseReceived(Request request, Response response) {
                                AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
                                List<IDatabaseConnection> connections = bean.as().getDatabaseConnections();
                                List<IDatasourceInfo> datasourceInfos = new ArrayList<IDatasourceInfo>();
                                for (IDatabaseConnection connection : connections) {
                                    // check attributes to make sure we only return "standard" connections which can be managed
                                    Map<String, String> attributes = connection.getAttributes();
                                    if (attributes.containsKey(ATTRIBUTE_STANDARD_CONNECTION)) {
                                        if (attributes.get(ATTRIBUTE_STANDARD_CONNECTION).equals(Boolean.FALSE.toString())) {
                                            continue;
                                        }
                                    }
                                    datasourceInfos.add(new DatasourceInfo(connection.getName(), connection.getName(), TYPE, editable, removable, importable, exportable));
                                }
                                callback.success(datasourceInfos);
                            }
                        });
                    } catch (RequestException e) {
                        callback.error(e.getMessage(), e);
                    }
                }
            }
        });
    } catch (RequestException e) {
        callback.error(e.getMessage(), e);
    }
}
Also used : IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo) DatasourceInfo(org.pentaho.platform.dataaccess.datasource.DatasourceInfo) 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) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)

Example 98 with RequestBuilder

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

the class PerspectiveManager method setupPerspectiveManager.

private void setupPerspectiveManager() {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/plugin-manager/perspectives?ts=" + System.currentTimeMillis();
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    // $NON-NLS-1$//$NON-NLS-2$
    builder.setHeader("Content-Type", "application/json");
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                Window.alert("getPluginPerpectives fail: " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                JsArray<JsPerspective> jsperspectives = JsPerspective.parseJson(JsonUtils.escapeJsonForEval(response.getText()));
                ArrayList<IPluginPerspective> perspectives = new ArrayList<IPluginPerspective>();
                for (int i = 0; i < jsperspectives.length(); i++) {
                    JsPerspective jsperspective = jsperspectives.get(i);
                    // Don't include schedules if user doesn't have schedule permissions
                    if ("${schedules}".equals(jsperspective.getTitle()) && !canSchedule) {
                        continue;
                    }
                    DefaultPluginPerspective perspective = new DefaultPluginPerspective();
                    perspective.setContentUrl(jsperspective.getContentUrl());
                    perspective.setId(jsperspective.getId());
                    perspective.setLayoutPriority(Integer.parseInt(jsperspective.getLayoutPriority()));
                    ArrayList<String> requiredSecurityActions = new ArrayList<String>();
                    if (jsperspective.getRequiredSecurityActions() != null) {
                        for (int j = 0; j < jsperspective.getRequiredSecurityActions().length(); j++) {
                            requiredSecurityActions.add(jsperspective.getRequiredSecurityActions().get(j));
                        }
                    }
                    // will need to iterate over jsoverlays and convert to MantleXulOverlay
                    ArrayList<XulOverlay> overlays = new ArrayList<XulOverlay>();
                    if (jsperspective.getOverlays() != null) {
                        for (int j = 0; j < jsperspective.getOverlays().length(); j++) {
                            JsXulOverlay o = jsperspective.getOverlays().get(j);
                            MantleXulOverlay overlay = new MantleXulOverlay(o.getId(), o.getOverlayUri(), o.getSource(), o.getResourceBundleUri());
                            overlays.add(overlay);
                        }
                    }
                    perspective.setOverlays(overlays);
                    perspective.setRequiredSecurityActions(requiredSecurityActions);
                    perspective.setResourceBundleUri(jsperspective.getResourceBundleUri());
                    perspective.setTitle(jsperspective.getTitle());
                    perspectives.add(perspective);
                }
                setPluginPerspectives(perspectives);
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
    registerFunctions(this);
}
Also used : JsArray(com.google.gwt.core.client.JsArray) RequestBuilder(com.google.gwt.http.client.RequestBuilder) DefaultPluginPerspective(org.pentaho.platform.plugin.services.pluginmgr.perspective.pojo.DefaultPluginPerspective) Request(com.google.gwt.http.client.Request) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) JsXulOverlay(org.pentaho.mantle.client.ui.xul.JsXulOverlay) RequestException(com.google.gwt.http.client.RequestException) JsPerspective(org.pentaho.mantle.client.ui.xul.JsPerspective) Response(com.google.gwt.http.client.Response) XulOverlay(org.pentaho.ui.xul.XulOverlay) JsXulOverlay(org.pentaho.mantle.client.ui.xul.JsXulOverlay) MantleXulOverlay(org.pentaho.mantle.client.objects.MantleXulOverlay) RequestCallback(com.google.gwt.http.client.RequestCallback) MantleXulOverlay(org.pentaho.mantle.client.objects.MantleXulOverlay) IPluginPerspective(org.pentaho.platform.api.engine.perspective.pojo.IPluginPerspective)

Example 99 with RequestBuilder

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

the class GeneralPanel method prepareRequests.

@Override
public List<RequestBuilder> prepareRequests() {
    ArrayList<RequestBuilder> requestBuilders = new ArrayList<RequestBuilder>();
    String moduleBaseURL = GWT.getModuleBaseURL();
    String moduleName = GWT.getModuleName();
    String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    String setMetadataUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/metadata?cb=" + // $NON-NLS-1$//$NON-NLS-2$
    System.currentTimeMillis();
    RequestBuilder setMetadataBuilder = new RequestBuilder(RequestBuilder.PUT, setMetadataUrl);
    setMetadataBuilder.setHeader("Content-Type", "application/json");
    setMetadataBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    // prepare request data
    JSONArray arr = new JSONArray();
    JSONObject metadata = new JSONObject();
    metadata.put("stringKeyStringValueDto", arr);
    for (int i = 0; i < metadataPerms.size(); i++) {
        Set<String> keys = metadataPerms.get(i).keySet();
        for (String key : keys) {
            if (key != null && SolutionBrowserPanel.getInstance().isAdministrator()) {
                if (key.equals(org.pentaho.platform.api.repository2.unified.RepositoryFile.SCHEDULABLE_KEY) && !fileSummary.isFolder() || key.equals(org.pentaho.platform.api.repository2.unified.RepositoryFile.HIDDEN_KEY)) {
                    JSONObject obj = new JSONObject();
                    obj.put("key", new JSONString(key));
                    obj.put("value", metadataPerms.get(i).get(key).isString());
                    arr.set(i, obj);
                }
            }
        }
    }
    // setMetadataBuilder.sendRequest(metadata.toString(), setMetadataCallback);
    if (arr.size() > 0) {
        setMetadataBuilder.setRequestData(metadata.toString());
        requestBuilders.add(setMetadataBuilder);
    }
    return requestBuilders;
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) JSONObject(com.google.gwt.json.client.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.google.gwt.json.client.JSONArray) JSONString(com.google.gwt.json.client.JSONString) JSONString(com.google.gwt.json.client.JSONString)

Example 100 with RequestBuilder

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

the class SelectUserOrRoleDialog method fetchAllUsers.

public void fetchAllUsers(final ArrayList<String> existing, final Document fileInfo) {
    try {
        // $NON-NLS-1$
        final String url = GWT.getHostPageBaseURL() + "api/userrolelist/permission-users";
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
        // This header is required to force Internet Explorer to not cache values from the GET response.
        requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        requestBuilder.setHeader("accept", "application/json");
        requestBuilder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                JsArrayString users = parseUsersJson(JsonUtils.escapeJsonForEval(response.getText()));
                // filter out existing
                usersListBox.clear();
                PermissionsPanel permPanel = new PermissionsPanel(null);
                for (int i = 0; i < users.length(); i++) {
                    String user = users.get(i);
                    if (!existing.contains(user)) {
                        usersListBox.addItem(user);
                    } else {
                        if (!permPanel.getNames(fileInfo, 0).contains(user) && permPanel.getNames(fileInfo, 1).contains(user)) {
                            // we have equal user/role pair(s) and role already in existing list
                            usersListBox.addItem(user);
                        }
                    }
                }
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) RequestException(com.google.gwt.http.client.RequestException) PermissionsPanel(org.pentaho.mantle.client.solutionbrowser.fileproperties.PermissionsPanel)

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