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
}
}
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);
}
}
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);
}
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;
}
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());
}
}
Aggregations