Search in sources :

Example 1 with ValidationException

use of org.mycore.mets.validator.validators.ValidationException in project mycore by MyCoRe-Org.

the class MCRMetsCommands method validateSelectedMets.

@MCRCommand(syntax = "validate selected mets", help = "validates all mets.xml of selected derivates", order = 10)
public static void validateSelectedMets() {
    List<String> selectedObjectIDs = MCRObjectCommands.getSelectedObjectIDs();
    for (String objectID : selectedObjectIDs) {
        LOGGER.info("Validate mets.xml of {}", objectID);
        MCRPath metsFile = MCRPath.getPath(objectID, "/mets.xml");
        if (Files.exists(metsFile)) {
            try {
                MCRContent content = new MCRPathContent(metsFile);
                InputStream metsIS = content.getInputStream();
                METSValidator mv = new METSValidator(metsIS);
                List<ValidationException> validationExceptionList = mv.validate();
                if (validationExceptionList.size() > 0) {
                    invalidMetsQueue.add(objectID);
                }
                for (ValidationException validationException : validationExceptionList) {
                    LOGGER.error(validationException.getMessage());
                }
            } catch (IOException e) {
                LOGGER.error("Error while reading mets.xml of {}", objectID, e);
            } catch (JDOMException e) {
                LOGGER.error("Error while parsing mets.xml of {}", objectID, e);
            }
        }
    }
}
Also used : ValidationException(org.mycore.mets.validator.validators.ValidationException) InputStream(java.io.InputStream) MCRPathContent(org.mycore.common.content.MCRPathContent) METSValidator(org.mycore.mets.validator.METSValidator) IOException(java.io.IOException) MCRPath(org.mycore.datamodel.niofs.MCRPath) JDOMException(org.jdom2.JDOMException) MCRContent(org.mycore.common.content.MCRContent) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 2 with ValidationException

use of org.mycore.mets.validator.validators.ValidationException in project mycore by MyCoRe-Org.

the class MCRSwordMediaHandler method validate.

@Override
public MCRSwordUtil.MCRValidationResult validate(Path pathToFile) {
    // single added file name are remapped to mets.xml -> swordv2_*mets.xml
    if (pathToFile.getFileName().toString().endsWith("mets.xml")) {
        try (InputStream is = Files.newInputStream(pathToFile)) {
            METSValidator validator = new METSValidator(is);
            List<ValidationException> validateResult = validator.validate();
            if (validateResult.size() > 0) {
                String result = validateResult.stream().map(Throwable::getMessage).collect(Collectors.joining(System.lineSeparator()));
                return new MCRSwordUtil.MCRValidationResult(false, result);
            } else {
                return new MCRSwordUtil.MCRValidationResult(true, null);
            }
        } catch (IOException | JDOMException e) {
            return new MCRSwordUtil.MCRValidationResult(false, "Could not read mets.xml: " + e.getMessage());
        }
    } else {
        return new MCRSwordUtil.MCRValidationResult(true, null);
    }
}
Also used : MCRSwordUtil(org.mycore.sword.MCRSwordUtil) ValidationException(org.mycore.mets.validator.validators.ValidationException) InputStream(java.io.InputStream) METSValidator(org.mycore.mets.validator.METSValidator) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 JDOMException (org.jdom2.JDOMException)2 METSValidator (org.mycore.mets.validator.METSValidator)2 ValidationException (org.mycore.mets.validator.validators.ValidationException)2 MCRContent (org.mycore.common.content.MCRContent)1 MCRPathContent (org.mycore.common.content.MCRPathContent)1 MCRPath (org.mycore.datamodel.niofs.MCRPath)1 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)1 MCRSwordUtil (org.mycore.sword.MCRSwordUtil)1