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;
}
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;
}
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;
}
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());
}
}
Aggregations