use of org.pentaho.mantle.client.dialogs.scheduling.ScheduleParamsDialog in project pentaho-platform by pentaho.
the class RunInBackgroundCommand method performOperation.
protected void performOperation(boolean feedback) {
final String filePath = (this.getSolutionPath() != null) ? this.getSolutionPath() : repositoryFile.getPath();
String urlPath = NameUtils.URLEncode(NameUtils.encodeRepositoryPath(filePath));
RequestBuilder scheduleFileRequestBuilder = createParametersChecker(urlPath);
final boolean isXAction = isXAction(urlPath);
try {
scheduleFileRequestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
MessageDialogBox dialogBox = // $NON-NLS-1$
new MessageDialogBox(Messages.getString("error"), exception.toString(), false, false, true);
dialogBox.center();
}
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == Response.SC_OK) {
final JSONObject scheduleRequest = new JSONObject();
// $NON-NLS-1$
scheduleRequest.put("inputFile", new JSONString(filePath));
// Set date format to append to filename
if (StringUtils.isEmpty(getDateFormat())) {
// $NON-NLS-1$
scheduleRequest.put("appendDateFormat", JSONNull.getInstance());
} else {
// $NON-NLS-1$
scheduleRequest.put("appendDateFormat", new JSONString(getDateFormat()));
}
// Set whether to overwrite the file
if (StringUtils.isEmpty(getOverwriteFile())) {
// $NON-NLS-1$
scheduleRequest.put("overwriteFile", JSONNull.getInstance());
} else {
// $NON-NLS-1$
scheduleRequest.put("overwriteFile", new JSONString(getOverwriteFile()));
}
// Set job name
if (StringUtils.isEmpty(getOutputName())) {
// $NON-NLS-1$
scheduleRequest.put("jobName", JSONNull.getInstance());
} else {
// $NON-NLS-1$
scheduleRequest.put("jobName", new JSONString(getOutputName()));
}
// Set output path location
if (StringUtils.isEmpty(getOutputLocationPath())) {
// $NON-NLS-1$
scheduleRequest.put("outputFile", JSONNull.getInstance());
} else {
// $NON-NLS-1$
scheduleRequest.put("outputFile", new JSONString(getOutputLocationPath()));
}
if (!StringUtils.isEmpty(getUseWorkerNodes())) {
// $NON-NLS-1$
scheduleRequest.put("useWorkerNodes", new JSONString(getUseWorkerNodes()));
}
// BISERVER-9321
scheduleRequest.put("runInBackground", JSONBoolean.getInstance(true));
String responseMessage = response.getText();
final boolean hasParams = hasParameters(responseMessage, isXAction);
RequestBuilder emailValidRequest = // $NON-NLS-1$
new RequestBuilder(RequestBuilder.GET, contextURL + "api/emailconfig/isValid");
// $NON-NLS-1$ //$NON-NLS-2$
emailValidRequest.setHeader("accept", "text/plain");
emailValidRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
try {
emailValidRequest.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
MessageDialogBox dialogBox = // $NON-NLS-1$
new MessageDialogBox(Messages.getString("error"), exception.toString(), false, false, true);
dialogBox.center();
}
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == Response.SC_OK) {
// final boolean isEmailConfValid = Boolean.parseBoolean(response.getText());
// force false for now, I have a feeling PM is going to want this, making it easy to turn back
// on
final boolean isEmailConfValid = false;
if (hasParams) {
ScheduleParamsDialog dialog = new ScheduleParamsDialog(filePath, scheduleRequest, isEmailConfValid);
dialog.center();
dialog.setAfterResponseCallback(scheduleParamsDialogCallback);
} else if (isEmailConfValid) {
ScheduleEmailDialog scheduleEmailDialog = new ScheduleEmailDialog(null, filePath, scheduleRequest, null, null);
scheduleEmailDialog.center();
} else {
// just run it
RequestBuilder scheduleFileRequestBuilder = // $NON-NLS-1$
new RequestBuilder(RequestBuilder.POST, contextURL + "api/scheduler/job");
// $NON-NLS-1$//$NON-NLS-2$
scheduleFileRequestBuilder.setHeader("Content-Type", "application/json");
scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
try {
scheduleFileRequestBuilder.sendRequest(scheduleRequest.toString(), new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), exception.toString(), false, false, // $NON-NLS-1$
true);
dialogBox.center();
}
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == 200) {
MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("runInBackground"), // $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("backgroundExecutionStarted"), false, false, true);
dialogBox.center();
} else {
MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-2$ //$NON-NLS-3$
Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-2$ //$NON-NLS-3$
Messages.getString("serverErrorColon") + " " + response.getStatusCode(), false, false, true);
dialogBox.center();
}
}
});
} catch (RequestException e) {
MessageDialogBox dialogBox = new // $NON-NLS-1$
MessageDialogBox(// $NON-NLS-1$
Messages.getString("error"), // $NON-NLS-1$
e.toString(), false, false, true);
dialogBox.center();
}
}
}
}
});
} catch (RequestException e) {
MessageDialogBox dialogBox = // $NON-NLS-1$
new MessageDialogBox(Messages.getString("error"), e.toString(), false, false, true);
dialogBox.center();
}
} else {
MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), Messages.getString("serverErrorColon") + " " + response.getStatusCode(), false, false, // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
true);
dialogBox.center();
}
}
});
} catch (RequestException e) {
MessageDialogBox dialogBox = // $NON-NLS-1$
new MessageDialogBox(Messages.getString("error"), e.toString(), false, false, true);
dialogBox.center();
}
}
Aggregations