Link Search Menu Expand Document
Consortium of European Social Science Data Archives

API

The CMV API is available in two forms, a HTTP REST API and a Java API.

Documentation for the REST API is available at https://api.tech.cessda.eu/. In the top right-hand corner select CESSDA Metadata Validator from the list of API definitions.

To use the Java API, include the dependency and repository definition in your Maven project.

<dependency>
  <groupId>eu.cessda.cmv</groupId>
  <artifactId>cmv-core</artifactId>
  <version>2.0.0</version>
</dependency>
<repositories>
  <repository>
    <id>cessda-nexus</id>
    <name>CESSDA Nexus Repository</name>
    <url>https://nexus.cessda.eu/repository/maven-releases</url>
  </repository>
</repositories>

An example usage of the API is shown below.

boolean validateFiles() throws IOException, NotDocumentException
{
  // Create the validator factory and the validation service
  CessdaMetadataValidatorFactory factory = new CessdaMetadataValidatorFactory();
  ValidationService validationService = factory.newValidationService();

  // Load the validation profile; this can be a file, URI or a InputStream
  Resource profile = Resource.newResource(new File("path/to/cmv-profile.xml"));

  // Load the document to validate
  Resource documentToValidate = Resource.newResource(new File("path/to/ddi-document-to-validate.xml"));

  // Run the validation.
  ValidationReport validationReport = validationService.validate(documentToValidate, profile, ValidationGateName.BASIC);

  // The validation report can now be inspected. A document is valid if no constraint violations are present.
  List<ConstraintViolation> constraintViolations = validationReport.getConstraintViolations();
  boolean isValid = constraintViolations.isEmpty();

  // Constraint violations can be detailed if present.
  for (ConstraintViolation violation : constraintViolations) {
    System.out.println(violation.getMessage());
  }

  // Return the validation status
  return isValid;
}

Consult the JavaDoc for more details.


Table of contents