Search in sources :

Example 1 with PolicyItemsDefinitionType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemsDefinitionType in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method generateValue.

@Override
public <O extends ObjectType> void generateValue(PrismObject<O> object, PolicyItemsDefinitionType policyItemsDefinition, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
    String oid = object.getOid();
    OperationResult result = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
    Class<O> clazz = (Class<O>) object.asObjectable().getClass();
    ValuePolicyType valuePolicy = null;
    try {
        valuePolicy = getValuePolicy(object, task, result);
    } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
        LOGGER.error("Failed to get value policy for generating value. ", e);
        result.recordFatalError("Error while getting value policy. Reason: " + e.getMessage(), e);
        throw e;
    }
    Collection<PropertyDelta<?>> deltasToExecute = new ArrayList<>();
    for (PolicyItemDefinitionType policyItemDefinition : policyItemsDefinition.getPolicyItemDefinition()) {
        OperationResult generateValueResult = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
        ItemPath path = getPath(policyItemDefinition);
        if (path == null) {
            LOGGER.error("No item path defined in the target for policy item definition. Cannot generate value");
            generateValueResult.recordFatalError("No item path defined in the target for policy item definition. Cannot generate value");
            continue;
        }
        result.addParam("policyItemPath", path);
        PrismPropertyDefinition<?> propertyDef = getItemDefinition(object, path);
        if (propertyDef == null) {
            LOGGER.error("No definition for property {} in object. Is the path referencing prism property?" + path, object);
            generateValueResult.recordFatalError("No definition for property " + path + " in object " + object + ". Is the path referencing prism property?");
            continue;
        }
        LOGGER.trace("Default value policy: {}", valuePolicy);
        try {
            generateValue(object, valuePolicy, policyItemDefinition, task, generateValueResult);
        } catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
            LOGGER.error("Failed to generate value for {} " + policyItemDefinition, e);
            generateValueResult.recordFatalError("Failed to generate value for " + policyItemDefinition + ". Reason: " + e.getMessage(), e);
            policyItemDefinition.setResult(generateValueResult.createOperationResultType());
            continue;
        }
        collectDeltasForGeneratedValuesIfNeeded(object, policyItemDefinition, deltasToExecute, path, propertyDef);
        generateValueResult.computeStatusIfUnknown();
    }
    result.computeStatus();
    if (!result.isAcceptable()) {
        return;
    }
    try {
        if (!deltasToExecute.isEmpty()) {
            modelCrudService.modifyObject(clazz, oid, deltasToExecute, null, task, result);
        }
    } catch (ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | ObjectAlreadyExistsException | PolicyViolationException | SecurityViolationException e) {
        LOGGER.error("Could not execute deltas for generated values. Reason: " + e.getMessage(), e);
        result.recordFatalError("Could not execute deltas for gegenerated values. Reason: " + e.getMessage(), e);
        throw e;
    }
}
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) PolicyItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with PolicyItemsDefinitionType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemsDefinitionType 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)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 PolicyItemDefinitionType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemDefinitionType)2 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)1 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)1 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 PolicyItemTargetType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemTargetType)1 PolicyItemsDefinitionType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemsDefinitionType)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1