use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class PermissionsPanel method prepareRequests.
/**
* @return
*/
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));
// $NON-NLS-1$//$NON-NLS-2$
String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/acl";
RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, url);
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("Content-Type", "application/xml");
// default
if (isInheritsAcls(fileInfo)) {
removeAllAces(fileInfo);
} else {
// Check if any of the permission sets should be replaced with ALL.
// Any non-inherited Ace with a permission set containing PERM_GRANT_PERM should be replaced
// with a single PERM_ALL.
NodeList aces = fileInfo.getElementsByTagName(ACES_ELEMENT_NAME);
for (int i = 0; i < aces.getLength(); i++) {
Element ace = (Element) aces.item(i);
NodeList perms = ace.getElementsByTagName(PERMISSIONS_ELEMENT_NAME);
for (int j = 0; j < perms.getLength(); j++) {
Element perm = (Element) perms.item(j);
if (perm.getFirstChild() != null) {
if (Integer.parseInt(perm.getFirstChild().getNodeValue()) == PERM_GRANT_PERM) {
replacePermissionsWithAll(ace, fileInfo);
break;
}
}
}
}
}
// set request data in builder itself
builder.setRequestData(fileInfo.toString());
// add builder to list to return to parent for execution
requestBuilders.add(builder);
return requestBuilders;
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class PermissionsPanel method setAdmin.
private void setAdmin() {
try {
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "api/repo/files/canAdminister";
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
// $NON-NLS-1$ //$NON-NLS-2$
requestBuilder.setHeader("accept", "text/plain");
// $NON-NLS-1$ //$NON-NLS-2$
requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
requestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable caught) {
isAdmin = false;
}
public void onResponseReceived(Request request, Response response) {
// $NON-NLS-1$
isAdmin = "true".equalsIgnoreCase(response.getText());
}
});
} catch (RequestException e) {
isAdmin = false;
}
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class AbstractFilePickList method reloadFavorites.
public void reloadFavorites(final T pickListItem, final String command) {
final String url = GWT.getHostPageBaseURL() + "api/user-settings/favorites";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
// showError(exception);
}
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == Response.SC_NO_CONTENT && FILE_PICK_ADD.equals(command)) {
filePickList = new ArrayList<T>();
add(filePickList.size(), pickListItem);
} else if (response.getStatusCode() == Response.SC_OK) {
try {
JSONArray jsonArr = (JSONArray) JSONParser.parse(response.getText());
filePickList = new ArrayList<T>();
T filePickItem;
for (int i = 0; i < jsonArr.size(); i++) {
filePickItem = createFilePickItem(jsonArr.get(i).isObject());
filePickList.add(filePickItem);
}
if (FILE_PICK_ADD.equals(command)) {
add(filePickList.size(), pickListItem);
} else if (FILE_PICK_REMOVE.equals(command)) {
filePickList.remove(pickListItem);
fireItemsChangedEvent();
}
} catch (Exception e) {
if (FILE_PICK_ADD.equals(command)) {
add(filePickList.size(), pickListItem);
} else if (FILE_PICK_REMOVE.equals(command)) {
filePickList.remove(pickListItem);
fireItemsChangedEvent();
}
}
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class AbstractFilePickList method save.
/**
* Convert the FilePickList to JSON and save it to a user setting
*
* @param settingName
*/
public void save(String settingName) {
String url = GWT.getHostPageBaseURL() + "api/user-settings/" + settingName;
RequestBuilder builder = new CsrfRequestBuilder(RequestBuilder.POST, url);
try {
builder.setHeader("accept", "application/json");
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.sendRequest(toJson().toString(), new RequestCallback() {
public void onError(Request request, Throwable exception) {
MessageDialogBox dialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("couldNotSetUserSettings"), true, false, true);
dialog.center();
}
public void onResponseReceived(Request request, Response response) {
fireOnSavedEvent();
}
});
} catch (RequestException e) {
// showError(e);
}
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class SelectUserOrRoleDialog method fetchAllRoles.
public void fetchAllRoles(final ArrayList<String> existing, final Document fileInfo) {
try {
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "api/userrolelist/permission-roles";
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("couldNotGetRoles"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
true);
dialogBox.center();
}
public void onResponseReceived(Request request, Response response) {
JsArrayString roles = parseRolesJson(JsonUtils.escapeJsonForEval(response.getText()));
// filter out existing
rolesListBox.clear();
PermissionsPanel permPanel = new PermissionsPanel(null);
for (int i = 0; i < roles.length(); i++) {
String role = roles.get(i);
if (!existing.contains(role)) {
rolesListBox.addItem(role);
} else {
if (!permPanel.getNames(fileInfo, 1).contains(role) && permPanel.getNames(fileInfo, 0).contains(role)) {
// we have equal user/role pair(s) and user already in existing list
rolesListBox.addItem(role);
}
}
}
}
});
} catch (RequestException e) {
Window.alert(e.getMessage());
}
}
Aggregations