Search in sources :

Example 16 with PipelineData

use of com.evolveum.midpoint.model.impl.scripting.PipelineData in project midpoint by Evolveum.

the class TestResourceExecutor 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) value).asObjectable() instanceof ResourceType) {
            PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue) value).asPrismObject();
            ResourceType resourceType = resourceTypePrismObject.asObjectable();
            long started = operationsHelper.recordStart(context, resourceType);
            Throwable exception = null;
            OperationResult testResult;
            try {
                testResult = modelService.testResource(resourceTypePrismObject.getOid(), context.getTask());
                operationsHelper.recordEnd(context, resourceType, started, null);
            } catch (ObjectNotFoundException | RuntimeException e) {
                operationsHelper.recordEnd(context, resourceType, started, e);
                exception = processActionException(e, NAME, value, context);
                testResult = new OperationResult(TestResourceExecutor.class.getName() + ".testResource");
                testResult.recordFatalError(e);
            }
            result.addSubresult(testResult);
            context.println("Tested " + resourceTypePrismObject + ": " + testResult.getStatus() + exceptionSuffix(exception));
            try {
                PrismObjectValue<ResourceType> resourceValue = operationsHelper.getObject(ResourceType.class, resourceTypePrismObject.getOid(), false, context, result).getValue();
                output.add(new PipelineItem(resourceValue, item.getResult()));
            } catch (ExpressionEvaluationException e) {
                throw new ScriptExecutionException("Error getting resource " + resourceTypePrismObject.getOid() + ": " + e.getMessage(), e);
            }
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    return output;
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) 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) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)13 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)11 ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)6 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)5 Task (com.evolveum.midpoint.task.api.Task)5 Test (org.testng.annotations.Test)4 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)3 ActionParameterValueType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType)3 PrismValue (com.evolveum.midpoint.prism.PrismValue)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 ValidationResult (com.evolveum.midpoint.model.api.validator.ValidationResult)1 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)1 ExpressionHelper (com.evolveum.midpoint.model.impl.scripting.helpers.ExpressionHelper)1 OperationsHelper (com.evolveum.midpoint.model.impl.scripting.helpers.OperationsHelper)1 Item (com.evolveum.midpoint.prism.Item)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1