Search in sources :

Example 1 with ValidationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValidationResultType in project midpoint by Evolveum.

the class ValidateExecutor 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, globalResult);
        context.checkTaskStop();
        if (value instanceof PrismObjectValue && ((PrismObjectValue<?>) value).asObjectable() instanceof ResourceType) {
            // noinspection unchecked
            PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue<ResourceType>) value).asPrismObject();
            ResourceType resourceType = resourceTypePrismObject.asObjectable();
            Operation op = operationsHelper.recordStart(context, resourceType);
            try {
                ValidationResult validationResult = resourceValidator.validate(resourceTypePrismObject, Scope.THOROUGH, null, context.getTask(), result);
                PrismContainerDefinition<ValidationResultType> pcd = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(SchemaConstantsGenerated.C_VALIDATION_RESULT);
                PrismContainer<ValidationResultType> pc = pcd.instantiate();
                // noinspection unchecked
                pc.add(validationResult.toValidationResultType().asPrismContainerValue());
                context.println("Validated " + resourceTypePrismObject + ": " + validationResult.getIssues().size() + " issue(s)");
                operationsHelper.recordEnd(context, op, null, result);
                output.add(new PipelineItem(pc.getValue(), item.getResult()));
            } catch (SchemaException | RuntimeException e) {
                operationsHelper.recordEnd(context, op, e, result);
                context.println("Error validation " + resourceTypePrismObject + ": " + e.getMessage());
                // noinspection ThrowableNotThrown
                processActionException(e, NAME, value, context);
                output.add(item);
            }
        } else {
            // noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, item.getResult());
    }
    return output;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ScriptExecutionException(com.evolveum.midpoint.util.exception.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) Operation(com.evolveum.midpoint.schema.statistics.Operation) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ValidationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValidationResultType)

Aggregations

PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)1 ValidationResult (com.evolveum.midpoint.model.api.validator.ValidationResult)1 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Operation (com.evolveum.midpoint.schema.statistics.Operation)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ScriptExecutionException (com.evolveum.midpoint.util.exception.ScriptExecutionException)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 ValidationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValidationResultType)1