Search in sources :

Example 21 with PipelineItem

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

the class GenerateValueExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    PolicyItemsDefinitionType itemsDefinition = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAMETER_ITEMS, false, false, PARAMETER_ITEMS, input, context, PolicyItemsDefinitionType.class, globalResult);
    if (itemsDefinition == null) {
        itemsDefinition = new PolicyItemsDefinitionType().policyItemDefinition(new PolicyItemDefinitionType().target(new PolicyItemTargetType().path(new ItemPathType(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE)))).execute(false));
    }
    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> object = ((PrismObjectValue) value).asPrismObject();
            ObjectType objectBean = object.asObjectable();
            long started = operationsHelper.recordStart(context, objectBean);
            Throwable exception = null;
            try {
                LOGGER.trace("Generating value(s) for {}", objectBean);
                modelInteraction.generateValue(object, itemsDefinition, context.getTask(), result);
                operationsHelper.recordEnd(context, objectBean, started, null);
            } catch (Throwable e) {
                operationsHelper.recordEnd(context, objectBean, started, e);
                exception = processActionException(e, NAME, value, context);
            }
            context.println((exception != null ? "Attempted to generate value(s) for " : "Generated value(s) for ") + objectBean.toString() + 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 : PolicyItemsDefinitionType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemsDefinitionType) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PolicyItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) PolicyItemTargetType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemTargetType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 22 with PipelineItem

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

the class NotifyExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    String subtype = expressionHelper.getArgumentAsString(expression.getParameter(), PARAM_SUBTYPE, input, context, null, PARAM_SUBTYPE, globalResult);
    EventHandlerType handler = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_HANDLER, false, false, PARAM_HANDLER, input, context, EventHandlerType.class, globalResult);
    EventStatusType status = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_STATUS, false, false, PARAM_STATUS, input, context, EventStatusType.class, globalResult);
    EventOperationType operation = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_OPERATION, false, false, PARAM_OPERATION, input, context, EventOperationType.class, globalResult);
    boolean forWholeInput = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_FOR_WHOLE_INPUT, input, context, false, PARAM_SUBTYPE, globalResult);
    if (handler != null) {
        // TODO explain that the reason is that handler is not null
        checkRootAuthorization(globalResult, NAME);
    }
    if (status == null) {
        status = EventStatusType.SUCCESS;
    }
    if (operation == null) {
        operation = EventOperationType.ADD;
    }
    if (notificationManager == null) {
        throw new IllegalStateException("Notification manager is unavailable");
    }
    int eventCount = 0;
    if (forWholeInput) {
        Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, input.getData(), operation, status, context.getChannel());
        notificationManager.processEvent(event, context.getTask(), globalResult);
        eventCount++;
    } else {
        for (PipelineItem item : input.getData()) {
            PrismValue value = item.getValue();
            OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
            context.checkTaskStop();
            Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, value, operation, status, context.getChannel());
            notificationManager.processEvent(event, context.getTask(), result);
            eventCount++;
            operationsHelper.trimAndCloneResult(result, globalResult, context);
        }
    }
    context.println("Produced " + eventCount + " event(s)");
    return input;
}
Also used : CustomEvent(com.evolveum.midpoint.notifications.api.events.CustomEvent) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) EventHandlerType(com.evolveum.midpoint.xml.ns._public.common.common_3.EventHandlerType) EventStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.EventStatusType) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEvent(com.evolveum.midpoint.notifications.api.events.CustomEvent) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EventOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.EventOperationType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 23 with PipelineItem

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

Example 24 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem 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()) {
                pcv.keepPaths(keep);
            } else {
                pcv.removePaths(remove);
            }
        }
    }
    return input;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 25 with PipelineItem

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

the class PipelineData method create.

public static PipelineData create(PrismValue value) {
    PipelineData d = createEmpty();
    d.add(new PipelineItem(value, newOperationResult()));
    return d;
}
Also used : PipelineItem(com.evolveum.midpoint.model.api.PipelineItem)

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