use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class NewFolderCommand method performOperation.
protected void performOperation(boolean feedback) {
final SolutionFolderActionEvent event = new SolutionFolderActionEvent();
event.setAction(this.getClass().getName());
final TextBox folderNameTextBox = new TextBox();
folderNameTextBox.setTabIndex(1);
folderNameTextBox.setVisibleLength(40);
VerticalPanel vp = new VerticalPanel();
// $NON-NLS-1$
vp.add(new Label(Messages.getString("newFolderName")));
vp.add(folderNameTextBox);
final PromptDialogBox newFolderDialog = new PromptDialogBox(Messages.getString("newFolder"), Messages.getString("ok"), Messages.getString("cancel"), false, true, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
vp);
newFolderDialog.setFocusWidget(folderNameTextBox);
folderNameTextBox.setFocus(true);
final IDialogCallback callback = new IDialogCallback() {
public void cancelPressed() {
newFolderDialog.hide();
}
public void okPressed() {
if (!NameUtils.isValidFolderName(folderNameTextBox.getText())) {
event.setMessage(Messages.getString("containsIllegalCharacters", folderNameTextBox.getText()));
EventBusUtil.EVENT_BUS.fireEvent(event);
return;
}
solutionPath = parentFolder.getPath() + "/" + folderNameTextBox.getText();
// $NON-NLS-1$
String createDirUrl = contextURL + "api/repo/dirs/" + SolutionBrowserPanel.pathToId(solutionPath);
RequestBuilder createDirRequestBuilder = new RequestBuilder(RequestBuilder.PUT, createDirUrl);
try {
createDirRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
createDirRequestBuilder.sendRequest("", new RequestCallback() {
@Override
public void onError(Request createFolderRequest, Throwable exception) {
MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), false, false, true);
dialogBox.center();
event.setMessage(Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
@Override
public void onResponseReceived(Request createFolderRequest, Response createFolderResponse) {
if (createFolderResponse.getStatusCode() == 200) {
NewFolderCommand.this.callback.onHandle(solutionPath);
new RefreshRepositoryCommand().execute(false);
event.setMessage("Success");
FileChooserDialog.setIsDirty(Boolean.TRUE);
setBrowseRepoDirty(Boolean.TRUE);
EventBusUtil.EVENT_BUS.fireEvent(event);
} else {
event.setMessage(StringUtils.isEmpty(createFolderResponse.getText()) || Messages.getString(createFolderResponse.getText()) == null ? // $NON-NLS-1$
Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()) : Messages.getString(createFolderResponse.getText(), folderNameTextBox.getText()));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
});
} catch (RequestException e) {
Window.alert(e.getLocalizedMessage());
event.setMessage(e.getLocalizedMessage());
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
};
newFolderDialog.setCallback(callback);
newFolderDialog.center();
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class UserSettingsManager method getUserSettings.
private void getUserSettings(final AsyncCallback<JsArray<JsSetting>> callback) {
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "api/user-settings/list";
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) {
MessageDialogBox dialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("couldNotGetUserSettings"), true, false, // $NON-NLS-1$ //$NON-NLS-2$
true);
dialog.center();
}
public void onResponseReceived(Request request, Response response) {
JsArray<JsSetting> jsSettings = null;
try {
jsSettings = JsSetting.parseSettingsJson(response.getText());
} catch (Throwable t) {
// happens when there are no settings
}
// CHECKSTYLE IGNORE Indentation FOR NEXT 1 LINES
getInstance().settings = jsSettings;
if (callback != null) {
callback.onSuccess(settings);
}
EventBusUtil.EVENT_BUS.fireEvent(new UserSettingsLoadedEvent(settings));
}
});
} catch (RequestException e) {
// showError(e);
}
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class SchedulesPanel method controlJobs.
private void controlJobs(final Set<JsJob> jobs, String function, final Method method, final boolean refreshData) {
for (final JsJob job : jobs) {
RequestBuilder builder = createRequestBuilder(method, "api/scheduler/" + function);
builder.setHeader(HTTP.CONTENT_TYPE, JSON_CONTENT_TYPE);
JSONObject startJobRequest = new JSONObject();
startJobRequest.put("jobId", new JSONString(job.getJobId()));
try {
builder.sendRequest(startJobRequest.toString(), new RequestCallback() {
public void onError(Request request, Throwable exception) {
// showError(exception);
}
public void onResponseReceived(Request request, Response response) {
final String jobState = response.getText();
job.setState(jobState);
table.redraw();
updateJobScheduleButtonStyle(jobState);
if (refreshData) {
refresh();
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class SchedulesPanel method refresh.
public void refresh() {
String moduleBaseURL = GWT.getModuleBaseURL();
String moduleName = GWT.getModuleName();
String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
final String apiEndpoint = "api/scheduler/getJobs";
RequestBuilder executableTypesRequestBuilder = createRequestBuilder(RequestBuilder.GET, apiEndpoint, contextURL);
executableTypesRequestBuilder.setHeader(HTTP_ACCEPT_HEADER, JSON_CONTENT_TYPE);
try {
executableTypesRequestBuilder.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_OK) {
allJobs = parseJson(JsonUtils.escapeJsonForEval(response.getText()));
filterAndShowData();
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class SchedulesPanel method canAccessJobRequest.
private void canAccessJobRequest(final JsJob job, RequestCallback callback) {
final String jobId = SolutionBrowserPanel.pathToId(job.getFullResourceName());
final String apiEndpoint = "api/repo/files/" + jobId + "/canAccess?cb=" + System.currentTimeMillis() + "&permissions=" + READ_PERMISSION;
final RequestBuilder accessBuilder = createRequestBuilder(RequestBuilder.GET, apiEndpoint);
try {
accessBuilder.sendRequest(null, callback);
} catch (RequestException re) {
// noop
}
}
Aggregations