Search in sources :

Example 6 with ActionExpressionType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType in project midpoint by Evolveum.

the class ModifyExecutor 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);
    ActionParameterValueType deltaParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_DELTA, true, true, NAME);
    PipelineData deltaData = expressionHelper.evaluateParameter(deltaParameterValue, ObjectDeltaType.class, 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) {
            PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
            ObjectType objectType = prismObject.asObjectable();
            long started = operationsHelper.recordStart(context, objectType);
            Throwable exception = null;
            try {
                ObjectDelta<?> delta = createDelta(objectType, deltaData);
                result.addParam("delta", delta);
                operationsHelper.applyDelta(delta, 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 modify " : "Modified ") + 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;
}
Also used : ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ActionParameterValueType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem)

Example 7 with ActionExpressionType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType in project midpoint by Evolveum.

the class PurgeSchemaExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    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 PrismObjectValue && ((PrismObjectValue<Objectable>) value).asObjectable() instanceof ResourceType) {
            PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue) value).asPrismObject();
            ResourceType resourceType = resourceTypePrismObject.asObjectable();
            long started = operationsHelper.recordStart(context, resourceType);
            ObjectDelta delta = createDelta(resourceTypePrismObject.asObjectable());
            try {
                if (delta != null) {
                    operationsHelper.applyDelta(delta, ModelExecuteOptions.createRaw(), context, result);
                    context.println("Purged schema information from " + resourceTypePrismObject);
                    output.addValue(operationsHelper.getObject(ResourceType.class, resourceTypePrismObject.getOid(), true, context, result).getValue(), item.getResult());
                } else {
                    context.println("There's no schema information to be purged in " + value);
                    output.addValue(resourceTypePrismObject.getValue(), item.getResult());
                }
                operationsHelper.recordEnd(context, resourceType, started, null);
            } catch (Throwable ex) {
                operationsHelper.recordEnd(context, resourceType, started, ex);
                Throwable exception = processActionException(ex, NAME, value, context);
                context.println("Couldn't purge schema information from " + resourceTypePrismObject + exceptionSuffix(exception));
            }
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    return output;
}
Also used : PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 8 with ActionExpressionType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType 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;
}
Also used : PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 9 with ActionExpressionType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType in project midpoint by Evolveum.

the class TestParseScriptingExpression method assertPrismPropertyValueLocal.

@SuppressWarnings("unchecked")
@Override
protected void assertPrismPropertyValueLocal(PrismPropertyValue<ExpressionPipelineType> value) throws SchemaException {
    ExpressionPipelineType pipe = value.getValue();
    JAXBElement<ExpressionSequenceType> sequenceJaxb1 = (JAXBElement<ExpressionSequenceType>) pipe.getScriptingExpression().get(0);
    assertEquals("Wrong element name (1)", SchemaConstants.S_SEQUENCE, sequenceJaxb1.getName());
    assertEquals("Wrong element type (1)", ExpressionSequenceType.class, sequenceJaxb1.getValue().getClass());
    JAXBElement<SearchExpressionType> searchJaxb1_1 = (JAXBElement<SearchExpressionType>) sequenceJaxb1.getValue().getScriptingExpression().get(0);
    assertEquals("Wrong first element name", SchemaConstants.S_SEARCH, searchJaxb1_1.getName());
    assertEquals("Wrong element type (1.1)", SearchExpressionType.class, searchJaxb1_1.getValue().getClass());
    assertEquals(new QName("RoleType"), searchJaxb1_1.getValue().getType());
    assertNotNull(searchJaxb1_1.getValue().getSearchFilter());
    JAXBElement<ActionExpressionType> actionJaxb1_2 = (JAXBElement<ActionExpressionType>) sequenceJaxb1.getValue().getScriptingExpression().get(1);
    assertEquals("Wrong element type (1.2)", ActionExpressionType.class, actionJaxb1_2.getValue().getClass());
    assertEquals("log", actionJaxb1_2.getValue().getType());
    JAXBElement<ExpressionSequenceType> sequenceJaxb2 = (JAXBElement<ExpressionSequenceType>) pipe.getScriptingExpression().get(1);
    assertEquals("Wrong second element name", SchemaConstants.S_SEQUENCE, sequenceJaxb2.getName());
    assertEquals("Wrong element type (2)", ExpressionSequenceType.class, sequenceJaxb2.getValue().getClass());
    JAXBElement<ActionExpressionType> actionJaxb2_1 = (JAXBElement<ActionExpressionType>) sequenceJaxb2.getValue().getScriptingExpression().get(0);
    JAXBElement<ActionExpressionType> actionJaxb2_2 = (JAXBElement<ActionExpressionType>) sequenceJaxb2.getValue().getScriptingExpression().get(1);
    JAXBElement<SearchExpressionType> searchJaxb2_3 = (JAXBElement<SearchExpressionType>) sequenceJaxb2.getValue().getScriptingExpression().get(2);
    assertEquals("Wrong element name (2.1)", SchemaConstants.S_ACTION, actionJaxb2_1.getName());
    assertEquals("Wrong element type (2.1)", ActionExpressionType.class, actionJaxb2_1.getValue().getClass());
    assertEquals("Wrong element name (2.2)", SchemaConstants.S_ACTION, actionJaxb2_2.getName());
    assertEquals("Wrong element type (2.2)", ActionExpressionType.class, actionJaxb2_2.getValue().getClass());
    assertEquals("Wrong element name (2.3)", SchemaConstants.S_SEARCH, searchJaxb2_3.getName());
    assertEquals("Wrong element type (2.3)", SearchExpressionType.class, searchJaxb2_3.getValue().getClass());
}
Also used : ExpressionPipelineType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExpressionPipelineType) ExpressionSequenceType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExpressionSequenceType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) SearchExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.SearchExpressionType) ActionExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType)

Example 10 with ActionExpressionType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType in project midpoint by Evolveum.

the class TestParseScriptingExpressionXsiType method assertPrismPropertyValueLocal.

@SuppressWarnings("unchecked")
@Override
protected void assertPrismPropertyValueLocal(PrismPropertyValue<ExpressionPipelineType> value) throws SchemaException {
    ExpressionPipelineType pipe = value.getValue();
    JAXBElement<ExpressionSequenceType> sequenceJaxb1 = (JAXBElement<ExpressionSequenceType>) pipe.getScriptingExpression().get(0);
    assertEquals("Wrong element name (1)", SchemaConstants.S_SEQUENCE, sequenceJaxb1.getName());
    assertEquals("Wrong element type (1)", ExpressionSequenceType.class, sequenceJaxb1.getValue().getClass());
    JAXBElement<SearchExpressionType> searchJaxb1_1 = (JAXBElement<SearchExpressionType>) sequenceJaxb1.getValue().getScriptingExpression().get(0);
    assertEquals("Wrong first element name", SchemaConstants.S_SEARCH, searchJaxb1_1.getName());
    assertEquals("Wrong element type (1.1)", SearchExpressionType.class, searchJaxb1_1.getValue().getClass());
    assertEquals(new QName("RoleType"), searchJaxb1_1.getValue().getType());
    assertNotNull(searchJaxb1_1.getValue().getSearchFilter());
    JAXBElement<ActionExpressionType> actionJaxb1_2 = (JAXBElement<ActionExpressionType>) sequenceJaxb1.getValue().getScriptingExpression().get(1);
    assertEquals("Wrong element type (1.2)", ActionExpressionType.class, actionJaxb1_2.getValue().getClass());
    assertEquals("log", actionJaxb1_2.getValue().getType());
    JAXBElement<ExpressionSequenceType> sequenceJaxb2 = (JAXBElement<ExpressionSequenceType>) pipe.getScriptingExpression().get(1);
    assertEquals("Wrong second element name", SchemaConstants.S_SEQUENCE, sequenceJaxb2.getName());
    assertEquals("Wrong element type (2)", ExpressionSequenceType.class, sequenceJaxb2.getValue().getClass());
    JAXBElement<ActionExpressionType> actionJaxb2_1 = (JAXBElement<ActionExpressionType>) sequenceJaxb2.getValue().getScriptingExpression().get(0);
    JAXBElement<ActionExpressionType> actionJaxb2_2 = (JAXBElement<ActionExpressionType>) sequenceJaxb2.getValue().getScriptingExpression().get(1);
    JAXBElement<SearchExpressionType> searchJaxb2_3 = (JAXBElement<SearchExpressionType>) sequenceJaxb2.getValue().getScriptingExpression().get(2);
    assertEquals("Wrong element name (2.1)", SchemaConstants.S_ACTION, actionJaxb2_1.getName());
    assertEquals("Wrong element type (2.1)", ActionExpressionType.class, actionJaxb2_1.getValue().getClass());
    assertEquals("Wrong element name (2.2)", SchemaConstants.S_ACTION, actionJaxb2_2.getName());
    assertEquals("Wrong element type (2.2)", ActionExpressionType.class, actionJaxb2_2.getValue().getClass());
    assertEquals("Wrong element name (2.3)", SchemaConstants.S_SEARCH, searchJaxb2_3.getName());
    assertEquals("Wrong element type (2.3)", SearchExpressionType.class, searchJaxb2_3.getValue().getClass());
}
Also used : ExpressionPipelineType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExpressionPipelineType) ExpressionSequenceType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExpressionSequenceType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) SearchExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.SearchExpressionType) ActionExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType)

Aggregations

PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)13 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)12 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)7 PrismValue (com.evolveum.midpoint.prism.PrismValue)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)6 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)5 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)3 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 ActionExpressionType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType)2 ActionParameterValueType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType)2 ExpressionPipelineType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExpressionPipelineType)2 ExpressionSequenceType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExpressionSequenceType)2 SearchExpressionType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.SearchExpressionType)2 JAXBElement (javax.xml.bind.JAXBElement)2 QName (javax.xml.namespace.QName)2 ValidationResult (com.evolveum.midpoint.model.api.validator.ValidationResult)1 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)1 CustomEvent (com.evolveum.midpoint.notifications.api.events.CustomEvent)1