Skip to content
Snippets Groups Projects
Verification.java 3.21 KiB
Newer Older
package de.unikoblenz.fgbks.api;

import de.unikoblenz.fgbks.core.dmn.verification.DmnVerificationService;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerifierResultSet;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.classification.ClassificationType;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.VerificationType;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * API for the dmn verification service. Provides methods for generating verifications for dmn
 * tables.
 */
Jonas Blatt's avatar
Jonas Blatt committed
@Path("/api/dmn/verification")
public class Verification {

  @Inject protected DmnVerificationService dmnVerificationService;

  /**
   * Method to generate all verifications for a dmn with all registered verifiers.
   *
   * @param payload the dmn as XML format as
   * @return a JSON String, which represents a {@link VerifierResultSet}
   */
  @POST
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.TEXT_XML)
  public Response verifyAll(String payload) {
    return Response.accepted(dmnVerificationService.generate(payload)).build();
  }

  /**
   * Method to get all registered verification types.
   *
   * @return a list of {@link VerificationType} as a JSON String.
   */
  @Path("/type")
  @Produces(MediaType.APPLICATION_JSON)
  public Response verifyType() {
    return Response.accepted(dmnVerificationService.getVerificationTypes()).build();
  }

  /**
   * Method to generate all verifications for a dmn with the given name of a {@link
   * VerificationType}.
   *
   * @param typeName the name of a {@link VerificationType}
   * @param payload the dmn as XML format as
   * @return a JSON String, which represents a {@link VerifierResultSet}
   */
  @POST
  @Path("/type/{typeName}")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.TEXT_XML)
  public Response verifyType(@PathParam("typeName") String typeName, String payload) {
    return Response.accepted(dmnVerificationService.generateFromType(typeName, payload)).build();
  }

  /**
   * Method to get all registered classification types.
   *
   * @return a list of {@link ClassificationType} as a JSON String.
   */
  @Path("/classification")
  @Produces(MediaType.APPLICATION_JSON)
  public Response verifyClassification() {
    return Response.accepted(dmnVerificationService.getVerificationClassificationTypes()).build();
  }

  /**
   * Method to generate all verifications for a dmn with the given name of a {@link
   * ClassificationType}.
   *
   * @param classificationName the name of a {@link ClassificationType}
   * @param payload the dmn as XML format as
   * @return a JSON String, which represents a {@link VerifierResultSet}
   */
  @POST
  @Path("/classification/{classificationName}")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.TEXT_XML)
  public Response verifyClassification(
      @PathParam("classificationName") String classificationName, String payload) {
    return Response.accepted(
        dmnVerificationService.generateFromClassification(classificationName, payload))
        .build();
  }
}