use of com.evolveum.midpoint.model.api.ScriptExecutionException in project midpoint by Evolveum.
the class RecomputeExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && FocusType.class.isAssignableFrom(((PrismObjectValue) value).asPrismObject().getCompileTimeClass())) {
PrismObject<FocusType> focalPrismObject = ((PrismObjectValue) value).asPrismObject();
FocusType focusType = focalPrismObject.asObjectable();
long started = operationsHelper.recordStart(context, focusType);
Throwable exception = null;
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Recomputing object {} with dryRun={}: context:\n{}", focalPrismObject, dryRun);
}
ObjectDelta<? extends FocusType> emptyDelta = ObjectDelta.createEmptyDelta(focusType.getClass(), focusType.getOid(), prismContext, ChangeType.MODIFY);
operationsHelper.applyDelta(emptyDelta, ModelExecuteOptions.createReconcile(), dryRun, context, result);
LOGGER.trace("Recomputing of object {}: {}", focalPrismObject, result.getStatus());
operationsHelper.recordEnd(context, focusType, started, null);
} catch (Throwable e) {
operationsHelper.recordEnd(context, focusType, started, e);
exception = processActionException(e, NAME, value, context);
}
context.println((exception != null ? "Attempted to recompute " : "Recomputed ") + focalPrismObject.toString() + drySuffix(dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject<FocusType>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
use of com.evolveum.midpoint.model.api.ScriptExecutionException in project midpoint by Evolveum.
the class ResolveExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean noFetch = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_NO_FETCH, input, context, false, NAME, globalResult);
PipelineData output = PipelineData.createEmpty();
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismReferenceValue) {
PrismReferenceValue prismReferenceValue = (PrismReferenceValue) value;
String oid = prismReferenceValue.getOid();
QName targetTypeQName = prismReferenceValue.getTargetType();
if (targetTypeQName == null) {
throw new ScriptExecutionException("Couldn't resolve reference, because target type is unknown: " + prismReferenceValue);
}
Class<? extends ObjectType> typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeQName);
if (typeClass == null) {
throw new ScriptExecutionException("Couldn't resolve reference, because target type class is unknown for target type " + targetTypeQName);
}
try {
PrismObjectValue<? extends ObjectType> resolved = operationsHelper.getObject(typeClass, oid, noFetch, context, result).getValue();
output.add(new PipelineItem(resolved, item.getResult()));
} catch (Throwable e) {
//noinspection ThrowableNotThrown
processActionException(e, NAME, value, context);
// to keep track of failed item (may trigger exceptions downstream)
output.add(item);
}
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismReference"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return output;
}
use of com.evolveum.midpoint.model.api.ScriptExecutionException 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());
}
use of com.evolveum.midpoint.model.api.ScriptExecutionException in project midpoint by Evolveum.
the class ScriptingExpressionEvaluator method evaluateExpression.
// main entry point from the outside
private ExecutionContext evaluateExpression(ScriptingExpressionType expression, PipelineData data, ScriptingExpressionEvaluationOptionsType options, Task task, OperationResult result) throws ScriptExecutionException {
ExecutionContext context = new ExecutionContext(options, task);
PipelineData output;
try {
output = evaluateExpression(expression, data, context, result);
} catch (RuntimeException e) {
result.recordFatalError("Couldn't execute script", e);
throw new ScriptExecutionException("Couldn't execute script: " + e.getMessage(), e);
}
result.computeStatusIfUnknown();
context.setFinalOutput(output);
return context;
}
use of com.evolveum.midpoint.model.api.ScriptExecutionException in project midpoint by Evolveum.
the class AddExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean raw = getParamRaw(expression, input, context, globalResult);
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
for (PipelineItem item : input.getData()) {
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
PrismValue value = item.getValue();
if (value instanceof PrismObjectValue) {
@SuppressWarnings({ "unchecked", "raw" }) PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
operationsHelper.applyDelta(createAddDelta(objectType), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
exception = processActionException(ex, NAME, value, context);
}
context.println((exception != null ? "Attempted to add " : "Added ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
Aggregations