From f1f0b7ea697031d83c883637f0184b0cf09cc002 Mon Sep 17 00:00:00 2001
From: Jonas Blatt <jonasblatt@uni-koblenz.de>
Date: Wed, 16 Oct 2019 14:46:42 +0200
Subject: [PATCH] Create api for selecting multiple verifier types for the
 verifications

---
 dmnverifierapi/docApi.md                      | 19 ++++++++-----
 .../de/unikoblenz/fgbks/api/Verification.java | 21 ++++++++-------
 .../verification/DmnVerificationService.java  | 11 ++++----
 .../resources/META-INF/resources/index.html   | 27 +++++++++----------
 4 files changed, 44 insertions(+), 34 deletions(-)

diff --git a/dmnverifierapi/docApi.md b/dmnverifierapi/docApi.md
index 9abf8718..8bcf59a4 100644
--- a/dmnverifierapi/docApi.md
+++ b/dmnverifierapi/docApi.md
@@ -3,6 +3,7 @@
 Root path: <code>/api</code>
 
 <h3>Verifications</h3>
+
 <h4>Get all verifications from all verifiers with the given dmn table</h4>
 <ul>
   <li>POST</li>
@@ -12,39 +13,45 @@ Root path: <code>/api</code>
 </ul>
 
 <h3>Verification classifications</h3>
+
 <h4>Get a list of all verification classifications</h4>
 <ul>
   <li>GET</li>
-  <li><code><a href="/api/dmn/verification/classification" target="_blank">/api/dmn/verification/classification</a></code>
+  <li><code><a href="/api/dmn/verification/classifications" target="_blank">/api/dmn/verification/classifications</a></code>
   </li>
   <li>Produces: application/json</li>
 </ul>
+
 <h4>Get all verifications for the given verification classification</h4>
 <ul>
   <li>POST</li>
-  <li><code>/api/dmn/verification/classification/{classificationName}</code></li>
+  <li><code>/api/dmn/verification/classifications/{classificationName}</code></li>
   <li>Consumes: text/xml - the dmn table as xml string</li>
   <li>Produces: application/json</li>
 </ul>
 
 <h3>Verification types</h3>
+
 <h4>Get a list of all verification types</h4>
 <ul>
   <li>GET</li>
   <li>
-    <code><a href="/api/dmn/verification/type"
-             target="_blank">/api/dmn/verification/type</a></code>
+    <code><a href="/api/dmn/verification/types"
+             target="_blank">/api/dmn/verification/types</a></code>
   </li>
   <li>Produces: application/json</li>
 </ul>
-<h4>Get all verifications for the given verification type</h4>
+
+<h4>Get all verifications for the given verification types a and b</h4>
 <ul>
   <li>POST</li>
-  <li><code>/api/dmn/verification/classification/{classificationName}</code></li>
+  <li><code>/api/dmn/verification/types?typeName={a}&typeName={b}</code></li>
   <li>Consumes: text/xml - the dmn table as xml string</li>
   <li>Produces: application/json</li>
 </ul>
+
 <h3>Metrics</h3>
+
 <h4>Get some statistics about execution times</h4>
 <ul>
   <li>GET</li>
diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/api/Verification.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/api/Verification.java
index 6fe1f756..afce52aa 100644
--- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/api/Verification.java
+++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/api/Verification.java
@@ -7,6 +7,7 @@ import de.unikoblenz.fgbks.core.dmn.verification.metrics.DmnVerificationMetricsS
 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 java.util.List;
 import javax.inject.Inject;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
@@ -14,6 +15,7 @@ import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
@@ -47,26 +49,27 @@ public class Verification {
    * @return a list of {@link VerificationType} as a JSON String.
    */
   @GET
-  @Path("/type")
+  @Path("/types")
   @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}.
+   * Method to generate all verifications for a dmn with the given names of {@link
+   * VerificationType}. The types are listed in the query param "typeName". Multiple typeNames can
+   * be requested.
    *
-   * @param typeName the name of a {@link VerificationType}
+   * @param typeNames the "typeName"(s) 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}")
+  @Path("/types")
   @Produces(MediaType.APPLICATION_JSON)
   @Consumes(MediaType.TEXT_XML)
-  public Response verifyType(@PathParam("typeName") String typeName, String payload) {
-    return checkResult(dmnVerificationService.generateFromType(typeName, payload));
+  public Response verifyTypes(@QueryParam("typeName") List<String> typeNames, String payload) {
+    return checkResult(dmnVerificationService.generateFromTypes(typeNames, payload));
   }
 
   /**
@@ -75,7 +78,7 @@ public class Verification {
    * @return a list of {@link ClassificationType} as a JSON String.
    */
   @GET
-  @Path("/classification")
+  @Path("/classifications")
   @Produces(MediaType.APPLICATION_JSON)
   public Response verifyClassification() {
     return Response.accepted(dmnVerificationService.getVerificationClassificationTypes()).build();
@@ -90,7 +93,7 @@ public class Verification {
    * @return a JSON String, which represents a {@link VerifierResultSet}
    */
   @POST
-  @Path("/classification/{classificationName}")
+  @Path("/classifications/{classificationName}")
   @Produces(MediaType.APPLICATION_JSON)
   @Consumes(MediaType.TEXT_XML)
   public Response verifyClassification(
diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/core/dmn/verification/DmnVerificationService.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/core/dmn/verification/DmnVerificationService.java
index 31518e15..5526d35b 100644
--- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/core/dmn/verification/DmnVerificationService.java
+++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/core/dmn/verification/DmnVerificationService.java
@@ -84,12 +84,12 @@ public class DmnVerificationService {
    * Create a {@link VerifierResultSet} by executing the verifiers, which is registered in the
    * current deployment and has the name of the {@code type} parameter.
    *
-   * @param type the type as String. Should be the name of a {@link VerificationType}.
+   * @param types the type as string list. Should be the name of a {@link VerificationType}.
    * @param dmnXml the XML of the DMN as String
    * @return a {@link VerifierResultSet} containing all verifications of the selected verifier.
    */
-  public VerifierResultSet generateFromType(String type, String dmnXml) {
-    return generateWithFilter(dmnXml, type, null);
+  public VerifierResultSet generateFromTypes(List<String> types, String dmnXml) {
+    return generateWithFilter(dmnXml, types, null);
   }
 
   /**
@@ -188,7 +188,7 @@ public class DmnVerificationService {
   }
 
   private VerifierResultSet generateWithFilter(
-      String dmnXml, String typeName, String classificationName) {
+      String dmnXml, List<String> typeNames, String classificationName) {
     long verificationProcessId = UniqueIdGenerator.getNextId();
     LOGGER.info("Start verification process. Id: " + verificationProcessId);
     LOGGER.info("Parsing dmn. Id: " + verificationProcessId);
@@ -214,7 +214,8 @@ public class DmnVerificationService {
         LOGGER.error(e.getMessage());
       }
       if (av != null
-          && (typeName == null || av.getVerificationType().getName().getValue().equals(typeName))
+          && (typeNames == null
+          || typeNames.contains(av.getVerificationType().getName().getValue()))
           && (classificationName == null
               || av.getVerificationType()
                   .getClassification()
diff --git a/dmnverifierapi/src/main/resources/META-INF/resources/index.html b/dmnverifierapi/src/main/resources/META-INF/resources/index.html
index 1a852a96..639c062c 100644
--- a/dmnverifierapi/src/main/resources/META-INF/resources/index.html
+++ b/dmnverifierapi/src/main/resources/META-INF/resources/index.html
@@ -121,6 +121,7 @@
     Root path: <code>/api</code>
 
     <h3>Verifications</h3>
+
     <h4>Get all verifications from all verifiers with the given dmn table</h4>
     <ul>
       <li>POST</li>
@@ -130,39 +131,45 @@
     </ul>
 
     <h3>Verification classifications</h3>
+
     <h4>Get a list of all verification classifications</h4>
     <ul>
       <li>GET</li>
-      <li><code><a href="/api/dmn/verification/classification" target="_blank">/api/dmn/verification/classification</a></code>
+      <li><code><a href="/api/dmn/verification/classifications" target="_blank">/api/dmn/verification/classifications</a></code>
       </li>
       <li>Produces: application/json</li>
     </ul>
+
     <h4>Get all verifications for the given verification classification</h4>
     <ul>
       <li>POST</li>
-      <li><code>/api/dmn/verification/classification/{classificationName}</code></li>
+      <li><code>/api/dmn/verification/classifications/{classificationName}</code></li>
       <li>Consumes: text/xml - the dmn table as xml string</li>
       <li>Produces: application/json</li>
     </ul>
 
     <h3>Verification types</h3>
+
     <h4>Get a list of all verification types</h4>
     <ul>
       <li>GET</li>
       <li>
-        <code><a href="/api/dmn/verification/type"
-                 target="_blank">/api/dmn/verification/type</a></code>
+        <code><a href="/api/dmn/verification/types"
+                 target="_blank">/api/dmn/verification/types</a></code>
       </li>
       <li>Produces: application/json</li>
     </ul>
-    <h4>Get all verifications for the given verification type</h4>
+
+    <h4>Get all verifications for the given verification types a and b</h4>
     <ul>
       <li>POST</li>
-      <li><code>/api/dmn/verification/classification/{classificationName}</code></li>
+      <li><code>/api/dmn/verification/types?typeName={a}&typeName={b}</code></li>
       <li>Consumes: text/xml - the dmn table as xml string</li>
       <li>Produces: application/json</li>
     </ul>
+
     <h3>Metrics</h3>
+
     <h4>Get some statistics about execution times</h4>
     <ul>
       <li>GET</li>
@@ -188,16 +195,8 @@
         </li>
       </ul>
     </div>
-    <div class="right-section">
-      <h3>Contribute</h3>
-      <ul>
-        <li><a href="https://gitlab.uni-koblenz.de/jonasblatt/ma-jonasblatt-thesis" target="_blank">
-          GitLab Project </a></li>
-      </ul>
-    </div>
   </div>
 </div>
 
-
 </body>
 </html>
-- 
GitLab