Search in sources :

Example 11 with ScriptExecutionException

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;
}
Also used : ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Operation(com.evolveum.midpoint.schema.statistics.Operation) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 12 with ScriptExecutionException

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;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 13 with ScriptExecutionException

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;
}
Also used : ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Operation(com.evolveum.midpoint.schema.statistics.Operation) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) Protector(com.evolveum.midpoint.prism.crypto.Protector)

Example 14 with ScriptExecutionException

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with ScriptExecutionException

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");
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Aggregations

ScriptExecutionException (com.evolveum.midpoint.util.exception.ScriptExecutionException)15 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)4 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)4 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)4 PrismValue (com.evolveum.midpoint.prism.PrismValue)3 Operation (com.evolveum.midpoint.schema.statistics.Operation)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)2 Task (com.evolveum.midpoint.task.api.Task)2 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)2 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)2 ScriptExecutionResult (com.evolveum.midpoint.model.api.ScriptExecutionResult)1 EvaluatedStateTrigger (com.evolveum.midpoint.model.api.context.EvaluatedStateTrigger)1 ValidationResult (com.evolveum.midpoint.model.api.validator.ValidationResult)1