Search in sources :

Example 1 with ObjectValidator

use of com.evolveum.midpoint.schema.validator.ObjectValidator 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 2 with ObjectValidator

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

the class TestInitialObjects method testInitialObjects.

@Test
public void testInitialObjects() throws Exception {
    ObjectValidator validator = new ObjectValidator(getPrismContext());
    validator.setAllWarnings();
    StringBuilder errorsSb = new StringBuilder();
    for (File file : DIR_INITIAL_OBJECTS.listFiles()) {
        if (file.isFile()) {
            try {
                testInitialObject(validator, errorsSb, file);
            } catch (Throwable e) {
                String msg = "Error processing file " + file.getName() + ": " + e.getMessage();
                logger.error(msg, e);
                displayException(msg, e);
                throw e;
            }
        }
    }
    if (errorsSb.length() != 0) {
        throw new SchemaException(errorsSb.toString());
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectValidator(com.evolveum.midpoint.schema.validator.ObjectValidator) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with ObjectValidator

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

the class VerifyConsumerWorker method init.

@Override
protected void init() {
    validator = new ObjectValidator(context.getPrismContext());
    String warnOption = options.getWarn();
    if (warnOption == null) {
        validator.setAllWarnings();
    } else {
        String[] warnCategories = warnOption.split(",");
        for (String warnCategory : warnCategories) {
            switch(warnCategory) {
                case "deprecated":
                    validator.setWarnDeprecated(true);
                    break;
                case "plannedRemoval":
                    validator.setWarnPlannedRemoval(true);
                    break;
                case "uuid":
                    validator.setWarnIncorrectOids(true);
                    break;
                default:
                    System.err.println("Unknown warn option '" + warnCategory + "'");
                    break;
            }
        }
    }
}
Also used : ObjectValidator(com.evolveum.midpoint.schema.validator.ObjectValidator)

Aggregations

ObjectValidator (com.evolveum.midpoint.schema.validator.ObjectValidator)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ValidationItem (com.evolveum.midpoint.schema.validator.ValidationItem)1 ValidationResult (com.evolveum.midpoint.schema.validator.ValidationResult)1 MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)1 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 IOException (java.io.IOException)1 Test (org.testng.annotations.Test)1