sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-validation-test-services] 13/33: SLING-5026 - refactor validator interface to allow to set multiple failure messages
Date Tue, 07 Nov 2017 10:24:38 GMT
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 <kwin@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" <commits@sling.apache.org>.

Mime
View raw message