use of com.evolveum.midpoint.util.exception.ScriptExecutionException in project midpoint by Evolveum.
the class DiscoverConnectorsExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException, SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
boolean rebind = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_REBIND_RESOURCES, input, context, false, PARAM_REBIND_RESOURCES, globalResult);
PipelineData output = PipelineData.createEmpty();
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof ConnectorHostType) {
PrismObject<ConnectorHostType> connectorHostTypePrismObject = ((PrismObjectValue) value).asPrismObject();
Set<ConnectorType> newConnectors;
Operation op = operationsHelper.recordStart(context, connectorHostTypePrismObject.asObjectable());
Throwable exception = null;
try {
newConnectors = modelService.discoverConnectors(connectorHostTypePrismObject.asObjectable(), context.getTask(), result);
operationsHelper.recordEnd(context, op, null, result);
} catch (CommunicationException | SecurityViolationException | SchemaException | ConfigurationException | ObjectNotFoundException | ExpressionEvaluationException | RuntimeException e) {
operationsHelper.recordEnd(context, op, e, result);
exception = processActionException(e, NAME, value, context);
newConnectors = Collections.emptySet();
}
context.println((exception != null ? "Attempted to discover " : "Discovered " + newConnectors.size()) + " new connector(s) from " + connectorHostTypePrismObject + exceptionSuffix(exception));
for (ConnectorType connectorType : newConnectors) {
output.addValue(connectorType.asPrismObject().getValue(), item.getResult(), item.getVariables());
}
try {
if (rebind) {
rebindConnectors(newConnectors, context, result);
}
} catch (ScriptExecutionException e) {
// noinspection ThrowableNotThrown
// TODO better message
processActionException(e, NAME, value, context);
}
} else {
// noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Input item is not a PrismObject<ConnectorHost>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, item.getResult());
}
// TODO configurable output (either connector hosts or discovered connectors)
return output;
}
use of com.evolveum.midpoint.util.exception.ScriptExecutionException in project midpoint by Evolveum.
the class ScriptingExpressionEvaluator method evaluateExpression.
private ExecutionContext evaluateExpression(@NotNull ExecuteScriptType executeScript, VariablesMap initialVariables, boolean privileged, boolean recordProgressAndIterationStatistics, Task task, OperationResult result) throws ScriptExecutionException {
Validate.notNull(executeScript.getScriptingExpression(), "Scripting expression must be present");
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
try {
VariablesMap frozenVariables = VariablesUtil.initialPreparation(initialVariables, executeScript.getVariables(), expressionFactory, modelObjectResolver, prismContext, expressionProfile, task, result);
PipelineData pipelineData = PipelineData.parseFrom(executeScript.getInput(), frozenVariables, prismContext);
ExecutionContext context = new ExecutionContext(executeScript.getOptions(), task, this, privileged, recordProgressAndIterationStatistics, frozenVariables);
PipelineData output = evaluateExpression(executeScript.getScriptingExpression().getValue(), pipelineData, context, result);
context.setFinalOutput(output);
result.computeStatusIfUnknown();
context.computeResults();
return context;
} catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | RuntimeException | CommunicationException | ConfigurationException | SecurityViolationException e) {
result.recordFatalError("Couldn't execute script", e);
throw new ScriptExecutionException("Couldn't execute script: " + e.getMessage(), e);
} catch (Throwable t) {
result.recordFatalError("Couldn't execute script", t);
throw t;
}
}
use of com.evolveum.midpoint.util.exception.ScriptExecutionException in project midpoint by Evolveum.
the class ReencryptExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException, SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
Protector protector = prismContext.getDefaultProtector();
boolean dryRun = operationsHelper.getDryRun(expression, input, context, globalResult);
PipelineData output = PipelineData.createEmpty();
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue) {
@SuppressWarnings({ "unchecked", "raw" }) PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectBean = prismObject.asObjectable();
Operation op = operationsHelper.recordStart(context, objectBean);
try {
Collection<? extends ItemDelta<?, ?>> modifications = CryptoUtil.computeReencryptModifications(protector, prismObject);
if (!modifications.isEmpty()) {
result.addArbitraryObjectCollectionAsParam("modifications", modifications);
if (dryRun) {
context.println("Would reencrypt (this is dry run) " + prismObject.toString() + ": " + modifications.size() + " modification(s)");
} else {
cacheRepositoryService.modifyObject(objectBean.getClass(), objectBean.getOid(), modifications, result);
context.println("Reencrypted " + prismObject + ": " + modifications.size() + " modification(s)");
}
}
result.computeStatus();
operationsHelper.recordEnd(context, op, null, result);
} catch (Throwable ex) {
result.recordFatalError("Couldn't reencrypt object", ex);
operationsHelper.recordEnd(context, op, ex, result);
Throwable exception = processActionException(ex, NAME, value, context);
context.println("Couldn't reencrypt " + prismObject.toString() + drySuffix(dryRun) + exceptionSuffix(exception));
}
PrismPropertyValue<String> oidVal = prismContext.itemFactory().createPropertyValue(objectBean.getOid());
output.add(new PipelineItem(oidVal, item.getResult()));
} else {
// noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, item.getResult());
}
return output;
}
use of com.evolveum.midpoint.util.exception.ScriptExecutionException in project midpoint by Evolveum.
the class FilterContentEvaluator method evaluate.
public PipelineData evaluate(FilterContentExpressionType expression, PipelineData input, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
List<ItemPath> keep = convert(expression.getKeep());
List<ItemPath> remove = convert(expression.getRemove());
if (keep.isEmpty() && remove.isEmpty()) {
// nothing to do here
return input;
}
for (PipelineItem pipelineItem : input.getData()) {
PrismValue value = pipelineItem.getValue();
if (!(value instanceof PrismContainerValue)) {
String message = "In 'select' commands in keep/remove mode, we can act only on prism container values, not on " + value;
if (context.isContinueOnAnyError()) {
LOGGER.error(message);
} else {
throw new ScriptExecutionException(message);
}
} else {
PrismContainerValue<?> pcv = (PrismContainerValue) value;
if (!keep.isEmpty()) {
try {
pcv.keepPaths(keep);
} catch (SchemaException e) {
throw new ScriptExecutionException(e.getMessage(), e);
}
} else {
try {
pcv.removePaths(remove);
} catch (SchemaException e) {
throw new ScriptExecutionException(e.getMessage(), e);
}
}
}
}
return input;
}
use of com.evolveum.midpoint.util.exception.ScriptExecutionException in project midpoint by Evolveum.
the class AbstractBasicScriptingTest method test365AssignToJackDryAndRaw.
/**
* MID-6141
*/
@Test
public void test365AssignToJackDryAndRaw() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
ScriptingExpressionType expression = parseScriptingExpression(ASSIGN_TO_JACK_DRY_AND_RAW);
when();
try {
evaluator.evaluateExpression(expression, task, result);
fail("unexpected success");
} catch (ScriptExecutionException e) {
displayExpectedException(e);
assertThat(e).hasMessageContaining("previewChanges is not supported in raw mode");
}
}
Aggregations