You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:24:38 UTC

[sling-org-apache-sling-validation-test-services] 13/33: SLING-5026 - refactor validator interface to allow to set multiple failure messages

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.validation.test-services-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-validation-test-services.git

commit 0a324bc101a5b977696f6f88c14a51c14f888a75
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Fri Dec 18 14:50:39 2015 +0000

    SLING-5026 - refactor validator interface to allow to set multiple failure messages
    
    This closes #117
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/validation/test-services@1720802 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/validation/testservices/ValidationPostResponse.java | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponse.java b/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponse.java
index f535c15..4b71762 100644
--- a/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponse.java
+++ b/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponse.java
@@ -25,9 +25,11 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.sling.commons.json.JSONArray;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.JSONObject;
 import org.apache.sling.servlets.post.AbstractPostResponse;
+import org.apache.sling.validation.ValidationFailure;
 import org.apache.sling.validation.ValidationResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,9 +52,14 @@ public class ValidationPostResponse extends AbstractPostResponse {
         if (validationResult != null) {
             try {
                 jsonResponse.put("valid", validationResult.isValid());
-                for (Map.Entry<String, List<String>> entry : validationResult.getFailureMessages().entrySet()) {
-                    jsonResponse.put(entry.getKey(), entry.getValue());
+                JSONArray failures = new JSONArray();
+                for (ValidationFailure failure : validationResult.getFailures()) {
+                    JSONObject failureJson = new JSONObject();
+                    failureJson.put("message", failure.getMessage());
+                    failureJson.put("location", failure.getLocation());
+                    failures.put(failureJson);
                 }
+                jsonResponse.put("failures", failures);
             } catch (JSONException e) {
                 LOG.error("JSON error during response send operation.", e);
             }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.