Search in sources :

Example 1 with ValidationItem

use of com.evolveum.midpoint.schema.validator.ValidationItem in project midpoint by Evolveum.

the class TestInitialObjects method testInitialObject.

private <O extends ObjectType> void testInitialObject(ObjectValidator validator, StringBuilder errorsSb, File file) throws SchemaException, IOException {
    PrismObject<O> object = getPrismContext().parseObject(file);
    ValidationResult validationResult = validator.validate(object);
    if (validationResult.isEmpty() || isIgnoredWarning(validationResult)) {
        display("Checked " + object + ": no warnings");
        return;
    }
    displayDumpable("Validation warnings for " + object, validationResult);
    for (ValidationItem valItem : validationResult.getItems()) {
        errorsSb.append(file.getName());
        errorsSb.append(" ");
        errorsSb.append(object);
        errorsSb.append(" ");
        valItem.shortDump(errorsSb);
        errorsSb.append("\n");
    }
}
Also used : ValidationItem(com.evolveum.midpoint.schema.validator.ValidationItem) ValidationResult(com.evolveum.midpoint.schema.validator.ValidationResult)

Example 2 with ValidationItem

use of com.evolveum.midpoint.schema.validator.ValidationItem in project midpoint-studio by Evolveum.

the class VerifyAction method processFiles.

private void processFiles(AnActionEvent evt, MidPointService mm, Environment env, List<VirtualFile> files) {
    ObjectValidator validator = new ObjectValidator(MidPointUtils.DEFAULT_PRISM_CONTEXT);
    validator.setAllWarnings();
    MidPointClient client = new MidPointClient(evt.getProject(), env);
    for (VirtualFile file : files) {
        RunnableUtils.runReadAction(() -> {
            try {
                List<MidPointObject> objects = MidPointUtils.parseProjectFile(evt.getProject(), file, NOTIFICATION_KEY);
                for (MidPointObject obj : objects) {
                    try {
                        PrismObject object = client.parseObject(obj.getContent());
                        ValidationResult validationResult = validator.validate(object);
                        for (ValidationItem validationItem : validationResult.getItems()) {
                            String msg = buildValidationItem(object, validationItem);
                            mm.printToConsole(env, VerifyAction.class, msg);
                        }
                    } catch (Exception ex) {
                        mm.printToConsole(env, VerifyAction.class, "Couldn't parse object '" + obj.getName() + "'(" + obj.getType() + ") from file '" + file.getPath() + "', reason: " + ex.getMessage());
                    }
                }
            } catch (Exception ex) {
                mm.printToConsole(env, VerifyAction.class, "Couldn't parse objects from file '" + file.getPath() + "', reason: " + ex.getMessage());
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PrismObject(com.evolveum.midpoint.prism.PrismObject) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) ValidationItem(com.evolveum.midpoint.schema.validator.ValidationItem) ObjectValidator(com.evolveum.midpoint.schema.validator.ObjectValidator) ValidationResult(com.evolveum.midpoint.schema.validator.ValidationResult) IOException(java.io.IOException)

Example 3 with ValidationItem

use of com.evolveum.midpoint.schema.validator.ValidationItem in project midpoint by Evolveum.

the class VerifyConsumerWorker method write.

@Override
protected void write(Writer writer, ObjectType object) throws IOException {
    PrismObject<?> prismObject = object.asPrismObject();
    ValidationResult validationResult = validator.validate(prismObject);
    for (ValidationItem validationItem : validationResult.getItems()) {
        writeValidationItem(writer, prismObject, validationItem);
    }
}
Also used : ValidationItem(com.evolveum.midpoint.schema.validator.ValidationItem) ValidationResult(com.evolveum.midpoint.schema.validator.ValidationResult)

Aggregations

ValidationItem (com.evolveum.midpoint.schema.validator.ValidationItem)3 ValidationResult (com.evolveum.midpoint.schema.validator.ValidationResult)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectValidator (com.evolveum.midpoint.schema.validator.ObjectValidator)1 MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)1 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IOException (java.io.IOException)1