You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2017/03/06 09:57:56 UTC

svn commit: r1785616 - in /sling/trunk/bundles/extensions/validation: api/src/main/java/org/apache/sling/validation/model/ api/src/main/java/org/apache/sling/validation/model/spi/ api/src/main/java/org/apache/sling/validation/spi/ core/src/main/java/or...

Author: kwin
Date: Mon Mar  6 09:57:56 2017
New Revision: 1785616

URL: http://svn.apache.org/viewvc?rev=1785616&view=rev
Log:
SLING-6610 use ValidationContext in DefaultValidationFailure and DefaultValidationResult

Apart from that clarified severity handling by allowing the severity of the Validator to be set via OSGi service property "validator.severity". In addition the fallback severity can be set via service pid "org.apache.sling.validation.impl.ValidationServiceImpl"

Added:
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java   (with props)
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/CompositeValidationResult.java
      - copied, changed from r1785256, sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/CompositeValidationResult.java
Removed:
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/CompositeValidationResult.java
Modified:
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ParameterizedValidator.java
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ResourceProperty.java
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationFailure.java
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationResult.java
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/ValidationContext.java
    sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/Validator.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationContextImpl.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationModelRetrieverImpl.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationResourceVisitor.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceConfiguration.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceImpl.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ParameterizedValidatorImpl.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ResourcePropertyBuilder.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java
    sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/validators/RegexValidator.java
    sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationModelRetrieverImplTest.java
    sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java
    sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImplTest.java

Modified: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ParameterizedValidator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ParameterizedValidator.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ParameterizedValidator.java (original)
+++ sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ParameterizedValidator.java Mon Mar  6 09:57:56 2017
@@ -53,7 +53,9 @@ public interface ParameterizedValidator
 
     /**
      *
-     * @return the severity of validation failures emitted by this validator. May be {@code null} in case it is not specified.
+     * @return the severity of validation failures emitted by this validator.
+     * Was either set on the model or on the {@link Validator} itself.
+     * May be {@code null} in case it was set on none of them.
      */
     @CheckForNull Integer getSeverity();
 

Modified: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ResourceProperty.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ResourceProperty.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ResourceProperty.java (original)
+++ sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ResourceProperty.java Mon Mar  6 09:57:56 2017
@@ -38,7 +38,7 @@ public interface ResourceProperty {
      *
      * @return the name
      */
-    String getName();
+    @Nonnull String getName();
     
     /**
      * Returns the name pattern for this property. In case this is not returning {@code null}, this pattern is used for finding the properties which should be validated.

Added: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java?rev=1785616&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java (added)
+++ sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java Mon Mar  6 09:57:56 2017
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.validation.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.sling.validation.spi.Validator;
+
+/**
+ * This encapsulates a {@link Validator} as well as its default severity.
+ *
+ * @param <T> the type param of the encapsulated {@link Validator}
+ */
+public final class ValidatorAndSeverity<T> {
+    private final Validator<T> validator;
+    private final Integer severity;
+
+    public ValidatorAndSeverity(@Nonnull Validator<T> validator, Integer severity) {
+        this.validator = validator;
+        this.severity = severity;
+    }
+    
+    public @CheckForNull Integer getSeverity() {
+        return severity;
+    }
+
+    public @Nonnull Validator<T> getValidator() {
+        return validator;
+    }
+
+    @Override
+    public String toString() {
+        return "ValidatorWithSeverity [validator=" + validator + ", severity=" + severity + "]";
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((severity == null) ? 0 : severity.hashCode());
+        result = prime * result + ((validator == null) ? 0 : validator.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ValidatorAndSeverity other = (ValidatorAndSeverity) obj;
+        if (severity == null) {
+            if (other.severity != null)
+                return false;
+        } else if (!severity.equals(other.severity))
+            return false;
+        if (validator == null) {
+            if (other.validator != null)
+                return false;
+        } else if (!validator.equals(other.validator))
+            return false;
+        return true;
+    }
+    
+}

Propchange: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java (original)
+++ sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java Mon Mar  6 09:57:56 2017
@@ -25,7 +25,7 @@ import javax.annotation.Nonnull;
 
 import org.apache.sling.validation.ValidationService;
 import org.apache.sling.validation.model.ValidationModel;
-import org.apache.sling.validation.spi.Validator;
+import org.apache.sling.validation.model.ValidatorAndSeverity;
 import org.osgi.annotation.versioning.ProviderType;
 
 
@@ -52,6 +52,6 @@ public interface ValidationModelProvider
      *             in case a validation model was found but it is invalid
      */
     @Nonnull List<ValidationModel> getModels(@Nonnull String relativeResourceType,
-            @Nonnull Map<String, Validator<?>> validatorsMap) throws IllegalStateException;
+            @Nonnull Map<String, ValidatorAndSeverity<?>> validatorsMap) throws IllegalStateException;
 
 }

Modified: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationFailure.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationFailure.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationFailure.java (original)
+++ sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationFailure.java Mon Mar  6 09:57:56 2017
@@ -43,7 +43,19 @@ public class DefaultValidationFailure im
     private final transient @Nonnull ResourceBundle defaultResourceBundle;
     private final int severity;
 
-    public final static int DEFAULT_SEVERITY = 0;
+    /**
+    * Constructor of a validation failure.
+    * @param validationContext the context from which to extract location, severity and default resource bundle
+    * @param messageKey the key to look up in the resource bundle
+    * @param messageArguments the arguments to be used with the looked up value from the resource bundle (given in {@link #getMessage(ResourceBundle)}
+    */
+   public DefaultValidationFailure(@Nonnull ValidationContext validationContext, @Nonnull String messageKey, Object... messageArguments) {
+       this.location = validationContext.getLocation();
+       this.severity = validationContext.getSeverity();
+       this.defaultResourceBundle = validationContext.getDefaultResourceBundle();
+       this.messageKey = messageKey;
+       this.messageArguments = messageArguments;
+   }
 
     /**
      * Constructor of a validation failure.
@@ -54,13 +66,9 @@ public class DefaultValidationFailure im
      * @param messageKey the key to look up in the resource bundle
      * @param messageArguments the arguments to be used with the looked up value from the resource bundle (given in {@link #getMessage(ResourceBundle)}
      */
-    public DefaultValidationFailure(@Nonnull String location, Integer severity, @Nonnull ResourceBundle defaultResourceBundle, @Nonnull String messageKey, Object... messageArguments) {
+    public DefaultValidationFailure(@Nonnull String location, int severity, @Nonnull ResourceBundle defaultResourceBundle, @Nonnull String messageKey, Object... messageArguments) {
         this.location = location;
-        if (severity != null) {
-            this.severity = severity;
-        } else {
-            this.severity = DEFAULT_SEVERITY;
-        }
+        this.severity = severity;
         this.messageKey = messageKey;
         this.messageArguments = messageArguments;
         this.defaultResourceBundle = defaultResourceBundle;
@@ -115,17 +123,11 @@ public class DefaultValidationFailure im
         if (getClass() != obj.getClass())
             return false;
         DefaultValidationFailure other = (DefaultValidationFailure) obj;
-        if (location == null) {
-            if (other.location != null)
-                return false;
-        } else if (!location.equals(other.location))
+        if (!location.equals(other.location))
             return false;
         if (!Arrays.equals(messageArguments, other.messageArguments))
             return false;
-        if (messageKey == null) {
-            if (other.messageKey != null)
-                return false;
-        } else if (!messageKey.equals(other.messageKey))
+        if (!messageKey.equals(other.messageKey))
             return false;
         if (severity != other.severity)
             return false;

Modified: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationResult.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationResult.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationResult.java (original)
+++ sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/DefaultValidationResult.java Mon Mar  6 09:57:56 2017
@@ -51,13 +51,25 @@ public class DefaultValidationResult imp
     /** 
      * Constructs a result with one failure message. The message is constructed by looking up the given messageKey from a resourceBundle.
      * and formatting it using the given messageArguments via {@link MessageFormat#format(String, Object...)}.
+     * @param validationContext the context from which to take the location, severity and default resource bundle
+     * @param messageKey the message key used for looking up a value in the resource bundle given in {@link ValidationFailure#getMessage(java.util.ResourceBundle)}.
+     * @param messageArguments optional number of arguments being used in {@link MessageFormat#format(String, Object...)}
+     */
+    public DefaultValidationResult(@Nonnull ValidationContext validationContext, @Nonnull String messageKey, Object... messageArguments) {
+        this.isValid = false;
+        this.failures = Collections.<ValidationFailure>singletonList(new DefaultValidationFailure(validationContext, messageKey, messageArguments));
+    }
+
+    /** 
+     * Constructs a result with one failure message. The message is constructed by looking up the given messageKey from a resourceBundle.
+     * and formatting it using the given messageArguments via {@link MessageFormat#format(String, Object...)}.
      * @param location the location.
      * @param severity the severity of the embedded failure (may be {@code null}), which leads to setting it to the {@link #DEFAULT_SEVERITY}.
      * @param defaultResourceBundle the default resourceBundle which is used to resolve the {@link messageKey} if no other bundle is provided.
      * @param messageKey the message key used for looking up a value in the resource bundle given in {@link ValidationFailure#getMessage(java.util.ResourceBundle)}.
      * @param messageArguments optional number of arguments being used in {@link MessageFormat#format(String, Object...)}
      */
-    public DefaultValidationResult(@Nonnull String location, Integer severity, @Nonnull ResourceBundle defaultResourceBundle, @Nonnull String messageKey, Object... messageArguments) {
+    public DefaultValidationResult(@Nonnull String location, int severity, @Nonnull ResourceBundle defaultResourceBundle, @Nonnull String messageKey, Object... messageArguments) {
         this.isValid = false;
         this.failures = Collections.<ValidationFailure>singletonList(new DefaultValidationFailure(location, severity, defaultResourceBundle, messageKey, messageArguments));
     }
@@ -79,7 +91,7 @@ public class DefaultValidationResult imp
     }
 
     /**
-     * Used to indicated a valid result. Use this instead of instantiating your own {@link DefaultValidationResult}.
+     * Used to indicated a valid result.
      */
     public static final @Nonnull DefaultValidationResult VALID = new DefaultValidationResult(true);
 }

Modified: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/ValidationContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/ValidationContext.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/ValidationContext.java (original)
+++ sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/ValidationContext.java Mon Mar  6 09:57:56 2017
@@ -53,9 +53,9 @@ public interface ValidationContext {
 
     /**
      * Returns the severity to be issued for validation failures in this context.
-     * @return the severity of the validation failure. May be {@code null} when no explicit severity has been set in the model.
+     * @return the severity of the validation failure.
      */
-    @CheckForNull Integer getSeverity();
+    int getSeverity();
     
     /**
      * The default resource bundle which should be able to give out the error message of the validator in English. 

Modified: sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/Validator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/Validator.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/Validator.java (original)
+++ sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/Validator.java Mon Mar  6 09:57:56 2017
@@ -22,6 +22,7 @@ import javax.annotation.Nonnull;
 
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.validation.SlingValidationException;
+import org.apache.sling.validation.ValidationFailure;
 import org.apache.sling.validation.ValidationResult;
 import org.osgi.annotation.versioning.ConsumerType;
 
@@ -80,4 +81,11 @@ public interface Validator <T> {
      * It is recommended to prefix the value of the validator with the providing bundle symbolic name to prevent any name clashes.
      */
     String PROPERTY_VALIDATOR_ID = "validator.id";
+    
+    /***
+     * Each {@link Validator} may have a service property with name {@code validator.severity} of type {@link String}. This is taken as the severity of all 
+     * {@link ValidationFailure}s constructed by this {@link Validator} in case the model has not overwritten the severity. 
+     * If this property is not set the default severity is being used.
+     */
+    String PROPERTY_VALIDATOR_SEVERITY = "validator.severity";
 }

Copied: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/CompositeValidationResult.java (from r1785256, sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/CompositeValidationResult.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/CompositeValidationResult.java?p2=sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/CompositeValidationResult.java&p1=sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/CompositeValidationResult.java&r1=1785256&r2=1785616&rev=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/api/src/main/java/org/apache/sling/validation/spi/CompositeValidationResult.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/CompositeValidationResult.java Mon Mar  6 09:57:56 2017
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.validation.spi;
+package org.apache.sling.validation.impl;
 
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -28,9 +28,11 @@ import javax.annotation.Nonnull;
 
 import org.apache.sling.validation.ValidationFailure;
 import org.apache.sling.validation.ValidationResult;
+import org.apache.sling.validation.spi.DefaultValidationResult;
+import org.apache.sling.validation.spi.Validator;
 
 /**
- * Aggregates multiple {@link ValidationResult}s.
+ * Aggregates multiple {@link ValidationResult}s. Should not be from {@link Validator}s.
  */
 public class CompositeValidationResult implements ValidationResult, Serializable {
 
@@ -48,7 +50,7 @@ public class CompositeValidationResult i
         results.add(result);
     }
 
-    public void addFailure(@Nonnull String location, Integer severity, @Nonnull ResourceBundle defaultResourceBundle, @Nonnull String message, Object... messageArguments) {
+    public void addFailure(@Nonnull String location, int severity, @Nonnull ResourceBundle defaultResourceBundle, @Nonnull String message, Object... messageArguments) {
         results.add(new DefaultValidationResult(location, severity, defaultResourceBundle, message, messageArguments));
     }
 

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationContextImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationContextImpl.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationContextImpl.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationContextImpl.java Mon Mar  6 09:57:56 2017
@@ -30,12 +30,12 @@ import org.apache.sling.validation.spi.V
 public class ValidationContextImpl implements ValidationContext {
 
     private final @Nonnull String location;
-    private final Integer severity;
+    private final int severity;
     private final @Nonnull ValueMap valueMap;
     private final Resource resource;
     private final @Nonnull ResourceBundle defaultResourceBundle;
 
-    public ValidationContextImpl(@Nonnull String location, Integer severity,  @Nonnull ValueMap valueMap, Resource resource, @Nonnull ResourceBundle defaultResourceBundle) {
+    public ValidationContextImpl(@Nonnull String location, int severity, @Nonnull ValueMap valueMap, Resource resource, @Nonnull ResourceBundle defaultResourceBundle) {
         super();
         this.location = location;
         this.severity = severity;
@@ -63,8 +63,7 @@ public class ValidationContextImpl imple
     }
 
     @Override
-    @CheckForNull
-    public Integer getSeverity() {
+    public int getSeverity() {
         return severity;
     }
 

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationModelRetrieverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationModelRetrieverImpl.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationModelRetrieverImpl.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationModelRetrieverImpl.java Mon Mar  6 09:57:56 2017
@@ -35,6 +35,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.validation.impl.model.MergedValidationModel;
 import org.apache.sling.validation.model.ValidationModel;
+import org.apache.sling.validation.model.ValidatorAndSeverity;
 import org.apache.sling.validation.model.spi.ValidationModelProvider;
 import org.apache.sling.validation.spi.Validator;
 import org.osgi.framework.ServiceReference;
@@ -62,9 +63,9 @@ public class ValidationModelRetrieverImp
     @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE, policyOption = ReferencePolicyOption.GREEDY, fieldOption = FieldOption.REPLACE)
     protected volatile List<ValidationModelProvider> modelProviders;
 
-    /** List of all known validators (key=classname of validator) */
+    /** List of all known validators (key=id of validator) */
     @Nonnull
-    Map<String, Validator<?>> validators = new ConcurrentHashMap<>();
+    Map<String, ValidatorAndSeverity<?>> validators = new ConcurrentHashMap<>();
 
     @Nonnull
     Map<String, ServiceReference<Validator<?>>> validatorServiceReferences = new ConcurrentHashMap<>();
@@ -160,6 +161,7 @@ public class ValidationModelRetrieverImp
     @Reference(cardinality = ReferenceCardinality.MULTIPLE, policyOption = ReferencePolicyOption.GREEDY)
     protected void addValidator(Validator<?> validator, Map<String, Object> properties, ServiceReference<Validator<?>> serviceReference) {
         String validatorId = getValidatorIdFromServiceProperties(properties, validator, serviceReference);
+        Integer severity = getValidatorSeverityFromServiceProperties(properties, validator, serviceReference);
         if (validators.containsKey(validatorId)) {
             ServiceReference<Validator<?>> existingServiceReference = validatorServiceReferences.get(validatorId);
             if (existingServiceReference == null) {
@@ -170,7 +172,7 @@ public class ValidationModelRetrieverImp
                         + " because it has the same id '{}' and a higher service ranking",
                         validators.get(validatorId), existingServiceReference.getBundle().getBundleId(), validator,
                         serviceReference.getBundle().getBundleId(), validatorId);
-                validators.put(validatorId, validator);
+                validators.put(validatorId, new ValidatorAndSeverity<>(validator, severity));
                 validatorServiceReferences.put(validatorId, serviceReference);
             } else {
                 LOG.info(
@@ -178,7 +180,7 @@ public class ValidationModelRetrieverImp
                         validatorId, validators.get(validatorId), existingServiceReference.getBundle().getBundleId());
             }
         } else {
-            validators.put(validatorId, validator);
+            validators.put(validatorId, new ValidatorAndSeverity<>(validator, severity));
             validatorServiceReferences.put(validatorId, serviceReference);
         }
     }
@@ -191,19 +193,35 @@ public class ValidationModelRetrieverImp
 
     private String getValidatorIdFromServiceProperties(Map<String, Object> properties, Validator<?> validator,
             ServiceReference<Validator<?>> serviceReference) {
-        Object object = properties.get(Validator.PROPERTY_VALIDATOR_ID);
-        if (object == null) {
+        Object id = properties.get(Validator.PROPERTY_VALIDATOR_ID);
+        if (id == null) {
             throw new IllegalArgumentException("Validator '" + validator.getClass().getName() + "' provided from bundle "
                     + serviceReference.getBundle().getBundleId() +
                     " is lacking the mandatory service property " + Validator.PROPERTY_VALIDATOR_ID);
         }
-        if (!(object instanceof String)) {
+        if (!(id instanceof String)) {
             throw new IllegalArgumentException("Validator '" + validator.getClass().getName() + "' provided from bundle "
                     + serviceReference.getBundle().getBundleId() +
                     " is providing the mandatory service property " + Validator.PROPERTY_VALIDATOR_ID + " with the wrong type "
-                    + object.getClass() + " (must be of type String)");
+                    + id.getClass() + " (must be of type String)");
         }
-        return (String) object;
+        return (String) id;
+    }
+    
+    private Integer getValidatorSeverityFromServiceProperties(Map<String, Object> properties, Validator<?> validator,
+            ServiceReference<Validator<?>> serviceReference) {
+        Object severity = properties.get(Validator.PROPERTY_VALIDATOR_SEVERITY);
+        if (severity == null) {
+            LOG.debug("Validator '{}' is not setting an explicit severity via the OSGi service property {}", validator.getClass().getName(), Validator.PROPERTY_VALIDATOR_SEVERITY);
+            return null;
+        }
+        if (!(severity instanceof Integer)) {
+            throw new IllegalArgumentException("Validator '" + validator.getClass().getName() + "' provided from bundle "
+                    + serviceReference.getBundle().getBundleId() +
+                    " is providing the optional service property " + Validator.PROPERTY_VALIDATOR_SEVERITY + " with the wrong type "
+                    + severity.getClass() + " (must be of type Integer)");
+        }
+        return (Integer) severity;
     }
 
 }

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationResourceVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationResourceVisitor.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationResourceVisitor.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationResourceVisitor.java Mon Mar  6 09:57:56 2017
@@ -27,7 +27,6 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.validation.ValidationResult;
 import org.apache.sling.validation.model.ValidationModel;
-import org.apache.sling.validation.spi.CompositeValidationResult;
 
 public class ValidationResourceVisitor extends AbstractResourceVisitor {
 

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceConfiguration.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceConfiguration.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceConfiguration.java Mon Mar  6 09:57:56 2017
@@ -25,4 +25,6 @@ import org.osgi.service.metatype.annotat
 public @interface ValidationServiceConfiguration {
     @AttributeDefinition(name = "Cache Validation Results on Resources", description = "If enabled will cache the validation result from calls to ValidationService.validate(Resource,ValidationModel) and expose it via Resource.adaptTo('ValidationResult.class').")
     boolean cacheValidationResultsOnResources() default false;
+    @AttributeDefinition(name = "Default Severity of Validation Failures", description = "The default severity set for all validation failures where no explicit severity has been set in the model or on the according Validator.")
+    int defaultSeverity() default 0;
 }

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceImpl.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceImpl.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/ValidationServiceImpl.java Mon Mar  6 09:57:56 2017
@@ -47,7 +47,6 @@ import org.apache.sling.validation.model
 import org.apache.sling.validation.model.ParameterizedValidator;
 import org.apache.sling.validation.model.ResourceProperty;
 import org.apache.sling.validation.model.ValidationModel;
-import org.apache.sling.validation.spi.CompositeValidationResult;
 import org.apache.sling.validation.spi.ValidationContext;
 import org.apache.sling.validation.spi.Validator;
 import org.osgi.framework.ServiceReference;
@@ -57,10 +56,12 @@ import org.osgi.service.component.annota
 import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.osgi.service.component.annotations.ReferencePolicy;
 import org.osgi.service.component.annotations.ReferencePolicyOption;
+import org.osgi.service.metatype.annotations.Designate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Component
+@Designate(ocd=ValidationServiceConfiguration.class)
 public class ValidationServiceImpl implements ValidationService{
 
     /** Keys whose values are defined in the JCR resource bundle contained in the content-repository section of this bundle */
@@ -172,6 +173,15 @@ public class ValidationServiceImpl imple
         throw new IllegalStateException("There is no resource provider in the system, providing a resource bundle for locale");
     }
 
+    private int getSeverityForValidator(ParameterizedValidator validator) {
+        Integer validatorSeverity = validator.getSeverity();
+        if (validatorSeverity == null) {
+            return configuration.defaultSeverity();
+        } else {
+            return validatorSeverity;
+        }
+    }
+
     protected @Nonnull ValidationResult validate(@Nonnull Resource resource, @Nonnull ValidationModel model, @Nonnull String relativePath) {
         if (resource == null || model == null || relativePath == null) {
             throw new IllegalArgumentException("ValidationService.validate - cannot accept null parameters");
@@ -221,14 +231,14 @@ public class ValidationServiceImpl imple
                     }
                 }
                 if (!foundMatch && childResource.isRequired()) {
-                    result.addFailure(relativePath, null, defaultResourceBundle, I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN, pattern.toString());
+                    result.addFailure(relativePath, configuration.defaultSeverity(), defaultResourceBundle, I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN, pattern.toString());
                 }
             } else {
                 Resource expectedResource = resource.getChild(childResource.getName());
                 if (expectedResource != null) {
                     validateChildResource(expectedResource, relativePath, childResource, result, defaultResourceBundle);
                 } else if (childResource.isRequired()) {
-                    result.addFailure(relativePath, null, defaultResourceBundle, I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME, childResource.getName());
+                    result.addFailure(relativePath, configuration.defaultSeverity(), defaultResourceBundle, I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME, childResource.getName());
                 }
             } 
         }
@@ -280,7 +290,7 @@ public class ValidationServiceImpl imple
                     }
                 }
                 if (!foundMatch && resourceProperty.isRequired()) {
-                    result.addFailure(relativePath, null, defaultResourceBundle, I18N_KEY_MISSING_REQUIRED_PROPERTY_MATCHING_PATTERN, pattern.toString());
+                    result.addFailure(relativePath, configuration.defaultSeverity(), defaultResourceBundle, I18N_KEY_MISSING_REQUIRED_PROPERTY_MATCHING_PATTERN, pattern.toString());
                 }
             } else {
                 validatePropertyValue(resourceProperty.getName(), valueMap, resource, relativePath, resourceProperty, result, defaultResourceBundle);
@@ -288,23 +298,24 @@ public class ValidationServiceImpl imple
         }
     }
 
-    private void validatePropertyValue(String property, ValueMap valueMap, Resource resource, @Nonnull String relativePath, @Nonnull ResourceProperty resourceProperty, @Nonnull CompositeValidationResult result, @Nonnull ResourceBundle defaultResourceBundle) {
+    private void validatePropertyValue(@Nonnull String property, ValueMap valueMap, Resource resource, @Nonnull String relativePath, @Nonnull ResourceProperty resourceProperty, @Nonnull CompositeValidationResult result, @Nonnull ResourceBundle defaultResourceBundle) {
         Object fieldValues = valueMap.get(property);
         if (fieldValues == null) {
             if (resourceProperty.isRequired()) {
-                result.addFailure(relativePath, null, defaultResourceBundle, I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, property);
+                result.addFailure(relativePath, configuration.defaultSeverity(), defaultResourceBundle, I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, property);
             }
             return;
         }
         List<ParameterizedValidator> validators = resourceProperty.getValidators();
         if (resourceProperty.isMultiple()) {
             if (!fieldValues.getClass().isArray()) {
-                result.addFailure(relativePath + property, null, defaultResourceBundle, I18N_KEY_EXPECTED_MULTIVALUE_PROPERTY);
+                result.addFailure(relativePath + property, configuration.defaultSeverity(), defaultResourceBundle, I18N_KEY_EXPECTED_MULTIVALUE_PROPERTY);
                 return;
             }
         }
         
         for (ParameterizedValidator validator : validators) {
+            int severity = getSeverityForValidator(validator);
             // convert the type always to an array
             Class<?> type = validator.getType();
             if (!type.isArray()) {
@@ -320,23 +331,23 @@ public class ValidationServiceImpl imple
             // see https://issues.apache.org/jira/browse/SLING-4178 for why the second check is necessary
             if (typedValue == null || (typedValue.length > 0 && typedValue[0] == null)) {
                 // here the missing required property case was already treated in validateValueMap
-                result.addFailure(relativePath + property, validator.getSeverity(), defaultResourceBundle, I18N_KEY_WRONG_PROPERTY_TYPE, validator.getType());
+                result.addFailure(relativePath + property, severity, defaultResourceBundle, I18N_KEY_WRONG_PROPERTY_TYPE, validator.getType());
                 return;
             }
             
             // see https://issues.apache.org/jira/browse/SLING-662 for a description on how multivalue properties are treated with ValueMap
             if (validator.getType().isArray()) {
                 // ValueMap already returns an array in both cases (property is single value or multivalue)
-                validateValue(result, typedValue, property, relativePath, valueMap, resource, validator, defaultResourceBundle);
+                validateValue(result, typedValue, property, relativePath, valueMap, resource, validator, defaultResourceBundle, severity);
             } else {
                 // call validate for each entry in the array (supports both singlevalue and multivalue)
                 @Nonnull Object[] array = (Object[])typedValue;
                 if (array.length == 1) {
-                   validateValue(result, array[0], property, relativePath, valueMap, resource, validator, defaultResourceBundle);
+                   validateValue(result, array[0], property, relativePath, valueMap, resource, validator, defaultResourceBundle, severity);
                 } else {
                     int n = 0;
                     for (Object item : array) {
-                        validateValue(result, item, property + "[" + n++ + "]", relativePath, valueMap, resource, validator, defaultResourceBundle);
+                        validateValue(result, item, property + "[" + n++ + "]", relativePath, valueMap, resource, validator, defaultResourceBundle, severity);
                     }
                 }
             }
@@ -344,9 +355,9 @@ public class ValidationServiceImpl imple
     }
     
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    private void validateValue(CompositeValidationResult result, @Nonnull Object value, String property, String relativePath, @Nonnull ValueMap valueMap, Resource resource, ParameterizedValidator validator, @Nonnull ResourceBundle defaultResourceBundle) {
+    private void validateValue(CompositeValidationResult result, @Nonnull Object value, String property, String relativePath, @Nonnull ValueMap valueMap, Resource resource, ParameterizedValidator validator, @Nonnull ResourceBundle defaultResourceBundle, int severity) {
         try {
-            ValidationContext validationContext = new ValidationContextImpl(relativePath + property, validator.getSeverity(), valueMap, resource, defaultResourceBundle);
+            ValidationContext validationContext = new ValidationContextImpl(relativePath + property, severity, valueMap, resource, defaultResourceBundle);
             ValidationResult validatorResult = ((Validator)validator.getValidator()).validate(value, validationContext, validator.getParameters());
             result.addValidationResult(validatorResult);
         } catch (SlingValidationException e) {

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ParameterizedValidatorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ParameterizedValidatorImpl.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ParameterizedValidatorImpl.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ParameterizedValidatorImpl.java Mon Mar  6 09:57:56 2017
@@ -27,6 +27,7 @@ import org.apache.sling.api.resource.Val
 import org.apache.sling.api.wrappers.ValueMapDecorator;
 import org.apache.sling.validation.impl.util.ValidatorTypeUtil;
 import org.apache.sling.validation.model.ParameterizedValidator;
+import org.apache.sling.validation.model.ValidatorAndSeverity;
 import org.apache.sling.validation.spi.Validator;
 
 public class ParameterizedValidatorImpl implements ParameterizedValidator {
@@ -42,13 +43,17 @@ public class ParameterizedValidatorImpl
      * @param parameters
      * @param severity
      */
-    public ParameterizedValidatorImpl(@Nonnull Validator<?> validator, @Nonnull Map<String, Object> parameters, Integer severity) {
+    public ParameterizedValidatorImpl(@Nonnull ValidatorAndSeverity<?> validator, @Nonnull Map<String, Object> parameters, Integer severity) {
         super();
-        this.validator = validator;
+        this.validator = validator.getValidator();
         this.parameters = parameters;
         // cache type information as this is using reflection
-        this.type = ValidatorTypeUtil.getValidatorType(validator);
-        this.severity = severity;
+        this.type = ValidatorTypeUtil.getValidatorType(this.validator);
+        if (severity == null) {
+            this.severity = validator.getSeverity();
+        } else {
+            this.severity = severity;
+        }
     }
 
     /* (non-Javadoc)

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ResourcePropertyBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ResourcePropertyBuilder.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ResourcePropertyBuilder.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/model/ResourcePropertyBuilder.java Mon Mar  6 09:57:56 2017
@@ -27,6 +27,7 @@ import javax.annotation.Nonnull;
 
 import org.apache.sling.validation.model.ParameterizedValidator;
 import org.apache.sling.validation.model.ResourceProperty;
+import org.apache.sling.validation.model.ValidatorAndSeverity;
 import org.apache.sling.validation.spi.Validator;
 
 public class ResourcePropertyBuilder {
@@ -51,7 +52,7 @@ public class ResourcePropertyBuilder {
     /** 
      * should only be used from test classes 
      */
-    public @Nonnull ResourcePropertyBuilder validator(@Nonnull Validator<?> validator) {
+    public @Nonnull ResourcePropertyBuilder validator(@Nonnull ValidatorAndSeverity<?> validator) {
         validators.add(new ParameterizedValidatorImpl(validator, new HashMap<String, Object>(), null));
         return this;
     }
@@ -59,7 +60,7 @@ public class ResourcePropertyBuilder {
     /** 
      * should only be used from test classes 
      */
-    public @Nonnull ResourcePropertyBuilder validator(@Nonnull Validator<?> validator, Integer severity, String... parametersNamesAndValues) {
+    public @Nonnull ResourcePropertyBuilder validator(@Nonnull ValidatorAndSeverity<?> validator, Integer severity, String... parametersNamesAndValues) {
         if (parametersNamesAndValues.length % 2 != 0) {
             throw new IllegalArgumentException("array parametersNamesAndValues must be even! (first specify name then value, separated by comma)");
         }
@@ -71,7 +72,7 @@ public class ResourcePropertyBuilder {
         return validator(validator, severity, parameterMap);
     }
     
-    public @Nonnull ResourcePropertyBuilder validator(@Nonnull Validator<?> validator, Integer severity, @Nonnull Map<String, Object> parameters) {
+    public @Nonnull ResourcePropertyBuilder validator(@Nonnull ValidatorAndSeverity<?> validator, Integer severity, @Nonnull Map<String, Object> parameters) {
         validators.add(new ParameterizedValidatorImpl(validator, parameters, severity));
         return this;
     }

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java Mon Mar  6 09:57:56 2017
@@ -46,6 +46,7 @@ import org.apache.sling.validation.impl.
 import org.apache.sling.validation.model.ChildResource;
 import org.apache.sling.validation.model.ResourceProperty;
 import org.apache.sling.validation.model.ValidationModel;
+import org.apache.sling.validation.model.ValidatorAndSeverity;
 import org.apache.sling.validation.model.spi.ValidationModelProvider;
 import org.apache.sling.validation.spi.Validator;
 import org.osgi.framework.ServiceRegistration;
@@ -92,7 +93,7 @@ public class ResourceValidationModelProv
     @Reference
     private ServiceUserMapped serviceUserMapped;
 
-    /** key = resource type of validation models value = a list of all validation models for the resource type given in the key */
+    /** key = resource type, value = a list of all validation models for the resource type given in the key */
     final Map<String, List<ValidationModel>> validationModelCacheByResourceType = new ConcurrentHashMap<>();
 
     @Activate
@@ -218,7 +219,7 @@ public class ResourceValidationModelProv
      */
     @Override
     public @Nonnull List<ValidationModel> getModels(@Nonnull String relativeResourceType,
-            @Nonnull Map<String, Validator<?>> validatorsMap) {
+            @Nonnull Map<String, ValidatorAndSeverity<?>> validatorsMap) {
         List<ValidationModel> cacheEntry = validationModelCacheByResourceType.get(relativeResourceType);
         if (cacheEntry == null) {
             cacheEntry = doGetModels(relativeResourceType, validatorsMap);
@@ -238,7 +239,7 @@ public class ResourceValidationModelProv
      *         type could be found. Returns the models below "/apps" before the models below "/libs".
      * @throws IllegalStateException in case a validation model is found but it is invalid */
     @Nonnull
-    private List<ValidationModel> doGetModels(@Nonnull String relativeResourceType, @Nonnull Map<String, Validator<?>> validatorsMap) {
+    private List<ValidationModel> doGetModels(@Nonnull String relativeResourceType, @Nonnull Map<String, ValidatorAndSeverity<?>> validatorsMap) {
         List<ValidationModel> validationModels = new ArrayList<ValidationModel>();
         ResourceResolver resourceResolver = null;
         try {
@@ -289,7 +290,7 @@ public class ResourceValidationModelProv
      * @param propertiesResource the resource identifying the properties node from a validation model's structure (might be {@code null})
      * @return a set of properties or an empty set if no properties are defined
      * @see ResourceProperty */
-    private @Nonnull List<ResourceProperty> buildProperties(@Nonnull Map<String, Validator<?>> validatorsMap, Resource propertiesResource) {
+    private @Nonnull List<ResourceProperty> buildProperties(@Nonnull Map<String, ValidatorAndSeverity<?>> validatorsMap, Resource propertiesResource) {
         List<ResourceProperty> properties = new ArrayList<ResourceProperty>();
         if (propertiesResource != null) {
             for (Resource propertyResource : propertiesResource.getChildren()) {
@@ -317,7 +318,7 @@ public class ResourceValidationModelProv
                                     "Could not adapt resource at '" + validatorResource.getPath() + "' to ValueMap");
                         }
                         String validatorId = validatorResource.getName();
-                        Validator<?> validator = validatorsMap.get(validatorId);
+                        ValidatorAndSeverity<?> validator = validatorsMap.get(validatorId);
                         if (validator == null) {
                             throw new IllegalArgumentException("Could not find validator with id '" + validatorId + "'");
                         }
@@ -374,7 +375,7 @@ public class ResourceValidationModelProv
      * @param validatorsMap a map containing {@link Validator}s as values and their class names as values
      * @return a list of all the children resources; the list will be empty if there are no children resources */
     private @Nonnull List<ChildResource> buildChildren(@Nonnull Resource modelResource, @Nonnull Resource rootResource,
-            @Nonnull Map<String, Validator<?>> validatorsMap) {
+            @Nonnull Map<String, ValidatorAndSeverity<?>> validatorsMap) {
         List<ChildResource> children = new ArrayList<ChildResource>();
         Resource childrenResource = rootResource.getChild(ResourceValidationModelProviderImpl.CHILDREN);
         if (childrenResource != null) {

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java Mon Mar  6 09:57:56 2017
@@ -30,12 +30,9 @@ import org.apache.commons.lang3.reflect.
 import org.apache.sling.validation.spi.Validator;
 
 public class ValidatorTypeUtil {
-    
-    /**
-     * 
-     * @param validator
-     * @return the type parametrization value on the {@link Validator} interface
-     */
+
+    /** @param validator
+     * @return the type parametrization value on the {@link Validator} interface */
     public static @Nonnull Class<?> getValidatorType(Validator<?> validator) {
         // get all type arguments from the current validator class up to the Validator interface
         Map<TypeVariable<?>, java.lang.reflect.Type> typeMap = TypeUtils.getTypeArguments(validator.getClass(), Validator.class);
@@ -44,24 +41,25 @@ public class ValidatorTypeUtil {
             type = entry.getValue();
             // check if this is really the type argument defined on the interface {@link Validator}
             if (entry.getKey().getGenericDeclaration() instanceof Class<?>) {
-                Class<?> clazz = (Class<?>)entry.getKey().getGenericDeclaration();
+                Class<?> clazz = (Class<?>) entry.getKey().getGenericDeclaration();
                 if (clazz.equals(Validator.class)) {
-                	// Java6 doesn't return the class for array types due to this bug: http://bugs.java.com/view_bug.do?bug_id=5041784
-                	if (type instanceof GenericArrayType) {
-                		// as a workaround make a new array class out of the generic component type encapsulated in the generic array type
-                    	type = Array.newInstance((Class<?>) ((GenericArrayType)type).getGenericComponentType(), 0).getClass();
+                    // Java6 doesn't return the class for array types due to this bug: http://bugs.java.com/view_bug.do?bug_id=5041784
+                    if (type instanceof GenericArrayType) {
+                        // as a workaround make a new array class out of the generic component type encapsulated in the generic array type
+                        type = Array.newInstance((Class<?>) ((GenericArrayType) type).getGenericComponentType(), 0).getClass();
                     }
                     if (type instanceof Class<?>) {
-                        return (Class<?>)type;
+                        return (Class<?>) type;
                     }
                     // type may also be a parameterized type (e.g. for Collection<String>), this is not allowed!
                     else {
-                        throw new IllegalArgumentException("Validators may not use parameterized types as type parameter. Only simple class types and arrays of class types are allowed.");
+                        throw new IllegalArgumentException(
+                                "Validators may not use parameterized types as type parameter. Only simple class types and arrays of class types are allowed.");
                     }
                 }
             }
-           
+
         }
-        throw new IllegalArgumentException("Validator '" + validator +"' has not valid type parameter!");
-}
+        throw new IllegalArgumentException("Validator '" + validator + "' has not valid type parameter!");
+    }
 }

Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/validators/RegexValidator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/validators/RegexValidator.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/validators/RegexValidator.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/validators/RegexValidator.java Mon Mar  6 09:57:56 2017
@@ -39,8 +39,8 @@ import org.osgi.service.component.annota
 @Component(property=Validator.PROPERTY_VALIDATOR_ID+"=org.apache.sling.validation.core.RegexValidator")
 public class RegexValidator implements Validator<String> {
 
-    public static final String I18N_KEY_PATTERN_DOES_NOT_MATCH = "sling.validator.regex.pattern-does-not-match";
-    public static final String REGEX_PARAM = "regex";
+    public static final @Nonnull String I18N_KEY_PATTERN_DOES_NOT_MATCH = "sling.validator.regex.pattern-does-not-match";
+    public static final @Nonnull String REGEX_PARAM = "regex";
 
     @Override
     public @Nonnull ValidationResult validate(@Nonnull String data, @Nonnull ValidationContext context, @Nonnull ValueMap arguments)
@@ -54,7 +54,7 @@ public class RegexValidator implements V
             if (pattern.matcher((String)data).matches()) {
                 return DefaultValidationResult.VALID;
             }
-            return new DefaultValidationResult(context.getLocation(), context.getSeverity(), context.getDefaultResourceBundle(), I18N_KEY_PATTERN_DOES_NOT_MATCH, regex);
+            return new DefaultValidationResult(context, I18N_KEY_PATTERN_DOES_NOT_MATCH, regex);
         } catch (PatternSyntaxException e) {
             throw new SlingValidationException("Given pattern in argument '" + REGEX_PARAM + "' is invalid", e);
         }

Modified: sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationModelRetrieverImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationModelRetrieverImplTest.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationModelRetrieverImplTest.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationModelRetrieverImplTest.java Mon Mar  6 09:57:56 2017
@@ -21,6 +21,7 @@ package org.apache.sling.validation.impl
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +40,7 @@ import org.apache.sling.validation.impl.
 import org.apache.sling.validation.impl.util.examplevalidators.StringValidator;
 import org.apache.sling.validation.model.ResourceProperty;
 import org.apache.sling.validation.model.ValidationModel;
+import org.apache.sling.validation.model.ValidatorAndSeverity;
 import org.apache.sling.validation.model.spi.ValidationModelProvider;
 import org.apache.sling.validation.spi.Validator;
 import org.hamcrest.Matchers;
@@ -57,7 +59,7 @@ import org.osgi.framework.ServiceReferen
 public class ValidationModelRetrieverImplTest {
 
     private ValidationModelRetrieverImpl validationModelRetriever;
-    private Validator<?> dateValidator;
+    private Validator<Date> dateValidator;
     private MultiValuedMap<String, String> applicablePathPerResourceType;
     private TestModelProvider modelProvider;
     
@@ -87,10 +89,10 @@ public class ValidationModelRetrieverImp
         
         @Override
         public @Nonnull List<ValidationModel> getModels(@Nonnull String relativeResourceType,
-                @Nonnull Map<String, Validator<?>> validatorsMap) {
+                @Nonnull Map<String, ValidatorAndSeverity<?>> validatorsMap) {
             // make sure the date validator is passed along
             Assert.assertThat(validatorsMap,
-                    Matchers.<String, Validator<?>> hasEntry(DATE_VALIDATOR_ID, dateValidator));
+                    Matchers.<String, ValidatorAndSeverity<?>> hasEntry(DATE_VALIDATOR_ID, new ValidatorAndSeverity<Date>(dateValidator, 1)));
 
             List<ValidationModel> models = new ArrayList<ValidationModel>();
             Collection<String> applicablePaths = applicablePathPerResourceType.get(relativeResourceType);
@@ -110,7 +112,7 @@ public class ValidationModelRetrieverImp
 
     @Before
     public void setup() throws LoginException {
-        dateValidator = new DateValidator();
+        dateValidator =  new DateValidator();
         applicablePathPerResourceType = new ArrayListValuedHashMap<>();
         validationModelRetriever = new ValidationModelRetrieverImpl();
         modelProvider = new TestModelProvider("source1");
@@ -121,6 +123,7 @@ public class ValidationModelRetrieverImp
         Mockito.doReturn(providingBundle).when(newValidatorServiceReference).getBundle();
         Map<String, Object> validatorProperties = new HashMap<>();
         validatorProperties.put(Validator.PROPERTY_VALIDATOR_ID, DATE_VALIDATOR_ID);
+        validatorProperties.put(Validator.PROPERTY_VALIDATOR_SEVERITY, 1);
         validationModelRetriever.addValidator(dateValidator, validatorProperties, validatorServiceReference);
         validationModelRetriever.resourceResolverFactory = resourceResolverFactory;
         Mockito.when(resourceResolverFactory.getServiceResourceResolver(Mockito.anyObject())).thenReturn(resourceResolver);
@@ -143,10 +146,11 @@ public class ValidationModelRetrieverImp
     public void testAddOverloadingValidatorWithSameValidatorIdAndHigherRanking() {
         Map<String, Object> validatorProperties = new HashMap<>();
         validatorProperties.put(Validator.PROPERTY_VALIDATOR_ID, DATE_VALIDATOR_ID);
+        validatorProperties.put(Validator.PROPERTY_VALIDATOR_SEVERITY, 2);
         Mockito.doReturn(1).when(newValidatorServiceReference).compareTo(Mockito.anyObject());
         Validator<String> stringValidator = new StringValidator();
         validationModelRetriever.addValidator(stringValidator, validatorProperties, newValidatorServiceReference);
-        Assert.assertEquals(stringValidator, validationModelRetriever.validators.get(DATE_VALIDATOR_ID));
+        Assert.assertEquals(new ValidatorAndSeverity<>(stringValidator, 2), validationModelRetriever.validators.get(DATE_VALIDATOR_ID));
         Assert.assertEquals(newValidatorServiceReference, validationModelRetriever.validatorServiceReferences.get(DATE_VALIDATOR_ID));
     }
     
@@ -154,10 +158,11 @@ public class ValidationModelRetrieverImp
     public void testAddOverloadingValidatorWithSameValidatorIdAndLowerRanking() {
         Map<String, Object> validatorProperties = new HashMap<>();
         validatorProperties.put(Validator.PROPERTY_VALIDATOR_ID, DATE_VALIDATOR_ID);
+        validatorProperties.put(Validator.PROPERTY_VALIDATOR_SEVERITY, 2);
         Mockito.doReturn(-1).when(newValidatorServiceReference).compareTo(Mockito.anyObject());
         Validator<String> stringValidator = new StringValidator();
         validationModelRetriever.addValidator(stringValidator, validatorProperties, newValidatorServiceReference);
-        Assert.assertEquals(dateValidator, validationModelRetriever.validators.get(DATE_VALIDATOR_ID));
+        Assert.assertEquals(new ValidatorAndSeverity<>(dateValidator, 1), validationModelRetriever.validators.get(DATE_VALIDATOR_ID));
         Assert.assertEquals(validatorServiceReference, validationModelRetriever.validatorServiceReferences.get(DATE_VALIDATOR_ID));
     }
 

Modified: sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java Mon Mar  6 09:57:56 2017
@@ -55,6 +55,7 @@ import org.apache.sling.validation.impl.
 import org.apache.sling.validation.model.ChildResource;
 import org.apache.sling.validation.model.ResourceProperty;
 import org.apache.sling.validation.model.ValidationModel;
+import org.apache.sling.validation.model.ValidatorAndSeverity;
 import org.apache.sling.validation.spi.DefaultValidationFailure;
 import org.apache.sling.validation.spi.DefaultValidationResult;
 import org.apache.sling.validation.spi.ValidationContext;
@@ -98,6 +99,7 @@ public class ValidationServiceImplTest {
         validationService = new ValidationServiceImpl();
         validationService.searchPaths = Arrays.asList(context.resourceResolver().getSearchPath());
         validationService.configuration = configuration;
+        Mockito.doReturn(20).when(configuration).defaultSeverity();
         validationService.resourceBundleProviders = Collections.singletonList(resourceBundleProvider);
         Mockito.doReturn(defaultResourceBundle).when(resourceBundleProvider).getResourceBundle(Mockito.anyObject());
         modelBuilder = new ValidationModelBuilder();
@@ -111,14 +113,14 @@ public class ValidationServiceImplTest {
 
     @Test()
     public void testValueMapWithWrongDataType() throws Exception {
-        propertyBuilder.validator(new DateValidator());
+        propertyBuilder.validator(new ValidatorAndSeverity<Date>(new DateValidator(), 10));
         modelBuilder.resourceProperty(propertyBuilder.build("field1"));
         ValidationModel vm = modelBuilder.build("sling/validation/test", "some source");
 
         HashMap<String, Object> hashMap = new HashMap<String, Object>();
         hashMap.put("field1", "1");
         ValidationResult vr = validationService.validate(new ValueMapDecorator(hashMap), vm);
-        Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("field1", null, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_WRONG_PROPERTY_TYPE, Date.class)));
+        Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("field1", 10, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_WRONG_PROPERTY_TYPE, Date.class)));
     }
 
     @Test
@@ -135,7 +137,7 @@ public class ValidationServiceImplTest {
                 return DefaultValidationResult.VALID;
             }
         };
-        propertyBuilder.validator(myValidator);
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(myValidator, 10));
         modelBuilder.resourceProperty(propertyBuilder.build("field1"));
         ValidationModel vm = modelBuilder.build("sling/validation/test", "some source");
 
@@ -161,7 +163,7 @@ public class ValidationServiceImplTest {
         hashMap.put("field3", "");
 
         ValidationResult vr = validationService.validate(new ValueMapDecorator(hashMap), vm);
-        Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("", null, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field4")));
+        Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field4")));
     }
 
     @Test()
@@ -179,7 +181,7 @@ public class ValidationServiceImplTest {
     @Test()
     public void testValueMapWithEmptyOptionalValue() throws Exception {
         propertyBuilder.optional();
-        propertyBuilder.validator(new RegexValidator(), 2, RegexValidator.REGEX_PARAM, "abc");
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), null, RegexValidator.REGEX_PARAM, "abc");
         modelBuilder.resourceProperty(propertyBuilder.build("field1"));
         ValidationModel vm = modelBuilder.build("sling/validation/test", "some source");
 
@@ -193,11 +195,11 @@ public class ValidationServiceImplTest {
 
     @Test
     public void testValueMapWithCorrectDataType() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "abc");
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, "abc");
         modelBuilder.resourceProperty(propertyBuilder.build("field1"));
         propertyBuilder = new ResourcePropertyBuilder();
         final String TEST_REGEX = "^test$";
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, TEST_REGEX);
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, TEST_REGEX);
         modelBuilder.resourceProperty(propertyBuilder.build("field2"));
         ValidationModel vm = modelBuilder.build("sling/validation/test", "some source");
 
@@ -214,7 +216,7 @@ public class ValidationServiceImplTest {
     // see https://issues.apache.org/jira/browse/SLING-5674
     @Test
     public void testNonExistingResource() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
         ResourceProperty property = propertyBuilder.build("field1");
         modelBuilder.resourceProperty(property);
         
@@ -230,15 +232,15 @@ public class ValidationServiceImplTest {
         ValidationResult vr = validationService.validate(nonExistingResource, vm);
         Assert.assertFalse("resource should have been considered invalid", vr.isValid());
         Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>containsInAnyOrder(
-                new DefaultValidationFailure("", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"),
-                new DefaultValidationFailure("", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME, "child")
+                new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"),
+                new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME, "child")
                 ));
     }
 
     // see https://issues.apache.org/jira/browse/SLING-5749
     @Test
     public void testSyntheticResource() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
         ResourceProperty property = propertyBuilder.build("field1");
         modelBuilder.resourceProperty(property);
         
@@ -254,14 +256,14 @@ public class ValidationServiceImplTest {
         ValidationResult vr = validationService.validate(nonExistingResource, vm);
         Assert.assertFalse("resource should have been considered invalid", vr.isValid());
         Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>containsInAnyOrder(
-                new DefaultValidationFailure("", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"),
-                new DefaultValidationFailure("", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME, "child")
+                new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"),
+                new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME, "child")
                 ));
     }
 
     @Test
     public void testResourceWithMissingGrandChildProperty() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
         ResourceProperty property = propertyBuilder.build("field1");
         modelBuilder.resourceProperty(property);
 
@@ -288,12 +290,12 @@ public class ValidationServiceImplTest {
 
         ValidationResult vr = validationService.validate(testResource, vm);
         Assert.assertFalse("resource should have been considered invalid", vr.isValid());
-        Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("child/grandchild", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1")));
+        Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("child/grandchild", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1")));
     }
 
     @Test
     public void testResourceWithMissingOptionalChildResource() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
         ResourceProperty property = propertyBuilder.build("field1");
 
         ChildResource child = new ChildResourceImpl("child", null, false, Collections.singletonList(property),
@@ -313,7 +315,7 @@ public class ValidationServiceImplTest {
 
     @Test
     public void testResourceWithNestedChildren() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
         ResourceProperty property = propertyBuilder.build("field1");
 
         ChildResource modelGrandChild = new ChildResourceImpl("grandchild", null, true,
@@ -339,7 +341,7 @@ public class ValidationServiceImplTest {
 
     @Test
     public void testResourceWithValidatorLeveragingTheResource() throws Exception {
-        Validator<String> extendedValidator = new Validator<String>() {
+        ValidatorAndSeverity<String> extendedValidator = new ValidatorAndSeverity<String>(new Validator<String>() {
             @Override
             @Nonnull
             public ValidationResult validate(@Nonnull String data, @Nonnull ValidationContext context, @Nonnull ValueMap arguments)
@@ -353,7 +355,7 @@ public class ValidationServiceImplTest {
                 return DefaultValidationResult.VALID;
             }
             
-        };
+        }, 0);
         propertyBuilder.validator(extendedValidator); // accept any digits
         modelBuilder.resourceProperty(propertyBuilder.build("field1"));
         ValidationModel vm = modelBuilder.build("sometype", "some source");
@@ -370,7 +372,7 @@ public class ValidationServiceImplTest {
 
     @Test
     public void testResourceWithNestedChildrenAndPatternMatching() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
         ResourceProperty property = propertyBuilder.build("field1");
 
         ChildResource modelGrandChild = new ChildResourceImpl("grandchild", "grandchild.*", true,
@@ -401,15 +403,15 @@ public class ValidationServiceImplTest {
         Assert.assertFalse("resource should have been considered invalid", vr.isValid());
         
         Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>containsInAnyOrder(
-                new DefaultValidationFailure("child2", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN, "grandchild.*"),
-                new DefaultValidationFailure("child3", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN, "grandchild.*"),
-                new DefaultValidationFailure("child3", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"),
-                new DefaultValidationFailure("", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN, "siblingchild.*")));
+                new DefaultValidationFailure("child2", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN, "grandchild.*"),
+                new DefaultValidationFailure("child3", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN, "grandchild.*"),
+                new DefaultValidationFailure("child3", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"),
+                new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN, "siblingchild.*")));
     }
 
     @Test
     public void testResourceWithPropertyPatternMatching() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 1, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
         propertyBuilder.nameRegex("field.*");
         modelBuilder.resourceProperty(propertyBuilder.build("field"));
         propertyBuilder.nameRegex("otherfield.*");
@@ -432,13 +434,13 @@ public class ValidationServiceImplTest {
         Assert.assertFalse("resource should have been considered invalid", vr.isValid());
         
         Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(
-                new DefaultValidationFailure("field3", 0, defaultResourceBundle, RegexValidator.I18N_KEY_PATTERN_DOES_NOT_MATCH, "\\d"),
-                new DefaultValidationFailure("", 0, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_MATCHING_PATTERN, "otherfield.*")));
+                new DefaultValidationFailure("field3", 1, defaultResourceBundle, RegexValidator.I18N_KEY_PATTERN_DOES_NOT_MATCH, "\\d"),
+                new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_MATCHING_PATTERN, "otherfield.*")));
     }
 
     @Test
     public void testResourceWithMultivalueProperties() throws Exception {
-        propertyBuilder.validator(new RegexValidator(), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 0, RegexValidator.REGEX_PARAM, "\\d"); // accept any digits
         propertyBuilder.multiple();
         modelBuilder.resourceProperty(propertyBuilder.build("field"));
         ValidationModel vm = modelBuilder.build("type", "some source");
@@ -508,8 +510,8 @@ public class ValidationServiceImplTest {
         ValidationResult vr = validationService.validateResourceRecursively(testResource, true, ignoreResourceType3Filter, false);
         Assert.assertFalse("resource should have been considered invalid", vr.isValid());
         Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(
-                new DefaultValidationFailure("", null, defaultResourceBundle,  ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"),
-                new DefaultValidationFailure("child2", null, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field2")));
+                new DefaultValidationFailure("", 20, defaultResourceBundle,  ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"),
+                new DefaultValidationFailure("child2", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field2")));
     }
 
     // see https://issues.apache.org/jira/browse/SLING-5674

Modified: sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImplTest.java?rev=1785616&r1=1785615&r2=1785616&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImplTest.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImplTest.java Mon Mar  6 09:57:56 2017
@@ -57,6 +57,7 @@ import org.apache.sling.validation.model
 import org.apache.sling.validation.model.ParameterizedValidator;
 import org.apache.sling.validation.model.ResourceProperty;
 import org.apache.sling.validation.model.ValidationModel;
+import org.apache.sling.validation.model.ValidatorAndSeverity;
 import org.apache.sling.validation.spi.Validator;
 import org.hamcrest.Matchers;
 import org.junit.After;
@@ -132,7 +133,7 @@ public class ResourceValidationModelProv
     private ResourceResolverFactory resourceResolverFactory;
     private MockQueryResultHandler prefixBasedResultHandler;
     private Map<PrefixAndResourceType, List<Node>> validatorModelNodesPerPrefixAndResourceType;
-    private Map<String, Validator<?>> validatorMap;
+    private Map<String, ValidatorAndSeverity<?>> validatorMap;
     private Map<String, Object> regexValdidatorParametrization;
     private ValidationModelBuilder modelBuilder;
 
@@ -149,14 +150,14 @@ public class ResourceValidationModelProv
         primaryTypeUnstructuredMap.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
         
         modelProvider = new ResourceValidationModelProviderImpl();
-        validatorMap = new HashMap<String, Validator<?>>();
-        validatorMap.put("org.apache.sling.validation.impl.validators.RegexValidator", new RegexValidator());
+        validatorMap = new HashMap<>();
+        validatorMap.put("org.apache.sling.validation.impl.validators.RegexValidator", new ValidatorAndSeverity<String>(new RegexValidator(), 2));
 
         // one default model
         modelBuilder = new ValidationModelBuilder();
         modelBuilder.setApplicablePath("/content/site1");
         ResourcePropertyBuilder propertyBuilder = new ResourcePropertyBuilder();
-        propertyBuilder.validator(new RegexValidator(), 10, RegexValidator.REGEX_PARAM, "prefix.*");
+        propertyBuilder.validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 10, RegexValidator.REGEX_PARAM, "prefix.*");
         ResourceProperty property = propertyBuilder.build("field1");
         modelBuilder.resourceProperty(property);
 
@@ -358,7 +359,7 @@ public class ResourceValidationModelProv
         validatorArguments.put("key2", "value1");
         validatorArguments.put("key3", "value1=value2");
         modelBuilder = new ValidationModelBuilder();
-        modelBuilder.resourceProperty(new ResourcePropertyBuilder().validator(new RegexValidator(), 10, validatorArguments).build("field1"));
+        modelBuilder.resourceProperty(new ResourcePropertyBuilder().validator(new ValidatorAndSeverity<String>(new RegexValidator(), 2), 10, validatorArguments).build("field1"));
         modelBuilder.addApplicablePath("content/site1");
         ValidationModel model1 = modelBuilder.build("sling/validation/test", libsValidatorsRoot.getPath() + "/testValidationModel1");
         createValidationModelResource(rr, libsValidatorsRoot.getPath(), "testValidationModel1", model1);