Search in sources :

Example 1 with ValidationResult

use of com.evolveum.midpoint.model.api.validator.ValidationResult 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, 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);
            try {
                ValidationResult validationResult = resourceValidator.validate(resourceTypePrismObject, Scope.THOROUGH, null, context.getTask(), result);
                PrismContainer pc = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(SchemaConstantsGenerated.C_VALIDATION_RESULT).instantiate();
                pc.add(validationResult.toValidationResultType().asPrismContainerValue());
                context.println("Validated " + resourceTypePrismObject + ": " + validationResult.getIssues().size() + " issue(s)");
                operationsHelper.recordEnd(context, resourceType, started, null);
                output.add(new PipelineItem(pc.getValue(), item.getResult()));
            } catch (SchemaException | RuntimeException e) {
                operationsHelper.recordEnd(context, resourceType, started, e);
                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, globalResult, context);
    }
    return output;
}
Also used : 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) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem)

Example 2 with ValidationResult

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

the class ResourceWizardIssuesModel method load.

@NotNull
@Override
protected WizardIssuesDto load() {
    final WizardIssuesDto issuesDto = new WizardIssuesDto();
    if (!resourceModel.isLoaded()) {
        // e.g. in first two wizard steps (IT PROBABLY DOES NOT WORK AS EXPECTED)
        return issuesDto;
    }
    ResourceValidator validator = wizardPage.getResourceValidator();
    ValidationResult validationResult = validator.validate(resourceModel.getObject(), Scope.QUICK, WebComponentUtil.getCurrentLocale(), wizardPage.createSimpleTask("validate"), new OperationResult("validate"));
    issuesDto.fillFrom(validationResult);
    issuesDto.sortIssues();
    return issuesDto;
}
Also used : ResourceValidator(com.evolveum.midpoint.model.api.validator.ResourceValidator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) WizardIssuesDto(com.evolveum.midpoint.web.component.wizard.resource.dto.WizardIssuesDto) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ValidationResult

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

the class ResourceValidatorImpl method validate.

@NotNull
@Override
public ValidationResult validate(@NotNull PrismObject<ResourceType> resourceObject, @NotNull Scope scope, @Nullable Locale locale, @NotNull Task task, @NotNull OperationResult result) {
    final ResourceType resource = resourceObject.asObjectable();
    final ValidationResult vr = new ValidationResult();
    ResourceBundle bundle = ResourceBundle.getBundle(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH, locale != null ? locale : Locale.getDefault());
    ResourceSchema resourceSchema = null;
    try {
        resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceObject, prismContext);
    } catch (Throwable t) {
        vr.add(Issue.Severity.WARNING, CAT_SCHEMA, C_NO_SCHEMA, getString(bundle, CLASS_DOT + C_NO_SCHEMA, t.getMessage()), ObjectTypeUtil.createObjectRef(resourceObject), ItemPath.EMPTY_PATH);
    }
    ResourceValidationContext ctx = new ResourceValidationContext(resourceObject, scope, task, vr, resourceSchema, bundle);
    SchemaHandlingType schemaHandling = resource.getSchemaHandling();
    if (schemaHandling != null) {
        checkSchemaHandlingDuplicateObjectTypes(ctx, schemaHandling);
        checkSchemaHandlingDefaults(ctx, schemaHandling);
        checkSchemaHandlingObjectTypes(ctx, schemaHandling);
    }
    SynchronizationType synchronization = resource.getSynchronization();
    if (synchronization != null) {
        checkSynchronizationDuplicateObjectTypes(ctx, synchronization);
        int i = 1;
        for (ObjectSynchronizationType objectSync : resource.getSynchronization().getObjectSynchronization()) {
            checkObjectSynchronization(ctx, new ItemPath(ResourceType.F_SYNCHRONIZATION, SynchronizationType.F_OBJECT_SYNCHRONIZATION, i), objectSync);
            i++;
        }
    }
    checkSynchronizationExistenceForSchemaHandlingObjectTypes(ctx);
    checkSchemaHandlingExistenceForSynchronizationObjectTypes(ctx);
    return ctx.validationResult;
}
Also used : RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ValidationResult

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

the class ModelRestService method validateIfRequested.

// currently unused; but potentially useful in future
private <T extends ObjectType> void validateIfRequested(PrismObject<?> object, List<String> options, ResponseBuilder builder, Task task, OperationResult parentResult) {
    if (options != null && options.contains(VALIDATE) && object.asObjectable() instanceof ResourceType) {
        ValidationResult validationResult = resourceValidator.validate((PrismObject<ResourceType>) object, Scope.THOROUGH, null, task, parentResult);
        // TODO move to parentResult, and return the result!
        builder.entity(validationResult.toValidationResultType());
    }
}
Also used : ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult)

Aggregations

ValidationResult (com.evolveum.midpoint.model.api.validator.ValidationResult)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 NotNull (org.jetbrains.annotations.NotNull)2 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)1 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)1 ResourceValidator (com.evolveum.midpoint.model.api.validator.ResourceValidator)1 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)1 WizardIssuesDto (com.evolveum.midpoint.web.component.wizard.resource.dto.WizardIssuesDto)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1