Search in sources :

Example 6 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.

the class DeleteExecutor 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()) {
        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 {
                operationsHelper.applyDelta(createDeleteDelta(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 delete " : "Deleted ") + 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 : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 7 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.

the class PipelineData method getDataAsReferences.

public Collection<ObjectReferenceType> getDataAsReferences(QName defaultTargetType) throws ScriptExecutionException {
    Collection<ObjectReferenceType> retval = new ArrayList<>(data.size());
    for (PipelineItem item : data) {
        PrismValue value = item.getValue();
        if (value instanceof PrismObjectValue) {
            PrismObjectValue objectValue = (PrismObjectValue) value;
            ObjectReferenceType ref = new ObjectReferenceType();
            // todo check the definition is present
            ref.setType(objectValue.asPrismObject().getDefinition().getTypeName());
            // todo check if oid is present
            ref.setOid(objectValue.getOid());
            retval.add(ref);
        } else if (value instanceof PrismPropertyValue) {
            Object realValue = ((PrismPropertyValue) value).getRealValue();
            if (realValue instanceof String) {
                ObjectReferenceType ref = new ObjectReferenceType();
                ref.setType(defaultTargetType);
                // todo implement search by name
                ref.setOid((String) realValue);
                retval.add(ref);
            } else if (realValue instanceof ObjectReferenceType) {
                retval.add((ObjectReferenceType) realValue);
            } else {
                throw new ScriptExecutionException("Unsupported reference type: " + value.getClass());
            }
        } else if (value instanceof PrismReferenceValue) {
            PrismReferenceValue referenceValue = (PrismReferenceValue) value;
            ObjectReferenceType ref = new ObjectReferenceType();
            ref.setupReferenceValue(referenceValue);
            retval.add(ref);
        }
    }
    return retval;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException)

Example 8 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.

the class EnableDisableExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    boolean isEnable = NAME_ENABLE.equals(expression.getType());
    boolean raw = getParamRaw(expression, input, context, globalResult);
    boolean dryRun = getParamDryRun(expression, input, context, globalResult);
    for (PipelineItem item : input.getData()) {
        PrismValue value = item.getValue();
        OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
        result.addParam("operation", expression.getType());
        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 {
                if (objectType instanceof FocusType) {
                    operationsHelper.applyDelta(createEnableDisableDelta((FocusType) objectType, isEnable), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
                } else if (objectType instanceof ShadowType) {
                    operationsHelper.applyDelta(createEnableDisableDelta((ShadowType) objectType, isEnable), context, result);
                } else {
                    throw new ScriptExecutionException("Item is not a FocusType nor ShadowType: " + value.toString());
                }
                operationsHelper.recordEnd(context, objectType, started, null);
            } catch (Throwable ex) {
                operationsHelper.recordEnd(context, objectType, started, ex);
                exception = processActionException(ex, expression.getType(), value, context);
            }
            context.println((exception != null ? "Attempted to " + expression.getType() : (isEnable ? "Enabled " : "Disabled ")) + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject"), expression.getType(), value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    return input;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) 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 PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem 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 10 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem 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)

Aggregations

PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)25 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)20 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)16 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)13 PrismValue (com.evolveum.midpoint.prism.PrismValue)8 ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)6 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)6 Task (com.evolveum.midpoint.task.api.Task)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)6 Test (org.testng.annotations.Test)6 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)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 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)2 ActionParameterValueType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType)2 HashSet (java.util.HashSet)2 ValidationResult (com.evolveum.midpoint.model.api.validator.ValidationResult)1 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)1