use of com.evolveum.midpoint.web.page.admin.configuration.dto.BulkActionDto in project midpoint by Evolveum.
the class PageBulkAction method startPerformed.
private void startPerformed(AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_PERFORM_BULK);
OperationResult result = new OperationResult(OPERATION_PERFORM_BULK);
BulkActionDto bulkActionDto = model.getObject();
if (StringUtils.isEmpty(bulkActionDto.getScript())) {
warn(getString("PageBulkAction.message.emptyString"));
target.add(getFeedbackPanel());
return;
}
Object parsed = null;
try {
parsed = getPrismContext().parserFor(bulkActionDto.getScript()).parseRealValue();
if (parsed == null) {
result.recordFatalError("No bulk action object was provided.");
} else if (!(parsed instanceof ExecuteScriptType) && !(parsed instanceof ScriptingExpressionType)) {
result.recordFatalError("Provided text is not a bulk action object. An instance of {scripting-3}ScriptingExpressionType is expected; you have provided " + parsed.getClass() + " instead.");
}
} catch (SchemaException | RuntimeException e) {
result.recordFatalError("Couldn't parse bulk action object", e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't parse bulk action object", e);
}
if (parsed != null) {
if (bulkActionDto.isAsync()) {
try {
if (parsed instanceof ExecuteScriptType) {
getScriptingService().evaluateExpressionInBackground((ExecuteScriptType) parsed, task, result);
} else {
//noinspection ConstantConditions
getScriptingService().evaluateExpressionInBackground((ScriptingExpressionType) parsed, task, result);
}
result.recordStatus(OperationResultStatus.IN_PROGRESS, task.getName() + " has been successfully submitted to execution");
} catch (SchemaException | SecurityViolationException e) {
result.recordFatalError("Couldn't submit bulk action to execution", e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't submit bulk action to execution", e);
}
} else {
try {
//noinspection ConstantConditions
ScriptExecutionResult executionResult = parsed instanceof ExecuteScriptType ? getScriptingService().evaluateExpression((ExecuteScriptType) parsed, task, result) : getScriptingService().evaluateExpression((ScriptingExpressionType) parsed, task, result);
result.recordStatus(OperationResultStatus.SUCCESS, "Action executed. Returned " + executionResult.getDataOutput().size() + " item(s). Console and data output available via 'Export to XML' function.");
result.addReturn("console", executionResult.getConsoleOutput());
result.addCollectionOfSerializablesAsReturn("data", executionResult.getDataOutput());
} catch (ScriptExecutionException | SchemaException | SecurityViolationException e) {
result.recordFatalError("Couldn't execute bulk action", e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute bulk action", e);
}
}
}
showResult(result);
target.add(getFeedbackPanel());
}
Aggregations