Search in sources :

Example 1 with ValidationModelProvider

use of org.apache.sling.validation.model.spi.ValidationModelProvider in project sling by apache.

the class ValidationModelRetrieverImplTest method testGetModelWithMultipleProvidersHigherRanking.

@Test
public void testGetModelWithMultipleProvidersHigherRanking() {
    ValidationModelProvider modelProvider2 = new TestModelProvider("source2");
    validationModelRetriever.modelProviders.clear();
    validationModelRetriever.modelProviders.add(modelProvider);
    validationModelRetriever.modelProviders.add(modelProvider2);
    // each provider must return the same applicable path but different
    applicablePathPerResourceType.put("test/type", "/content/site1");
    ValidationModel model = validationModelRetriever.getValidationModel("test/type", "/content/site1/somepage", false);
    Assert.assertNotNull(model);
    Assert.assertEquals("source2", model.getSource());
}
Also used : ValidationModel(org.apache.sling.validation.model.ValidationModel) ValidationModelProvider(org.apache.sling.validation.model.spi.ValidationModelProvider) Test(org.junit.Test)

Example 2 with ValidationModelProvider

use of org.apache.sling.validation.model.spi.ValidationModelProvider in project sling by apache.

the class ValidationModelRetrieverImplTest method testGetModelWithMultipleProvidersLowerRanking.

@Test
public void testGetModelWithMultipleProvidersLowerRanking() {
    ValidationModelProvider modelProvider2 = new TestModelProvider("source2");
    validationModelRetriever.modelProviders.clear();
    validationModelRetriever.modelProviders.add(modelProvider2);
    validationModelRetriever.modelProviders.add(modelProvider);
    // each provider must return the same applicable path but different
    applicablePathPerResourceType.put("test/type", "/content/site1");
    ValidationModel model = validationModelRetriever.getValidationModel("test/type", "/content/site1/somepage", false);
    Assert.assertNotNull(model);
    Assert.assertEquals("source1", model.getSource());
}
Also used : ValidationModel(org.apache.sling.validation.model.ValidationModel) ValidationModelProvider(org.apache.sling.validation.model.spi.ValidationModelProvider) Test(org.junit.Test)

Example 3 with ValidationModelProvider

use of org.apache.sling.validation.model.spi.ValidationModelProvider in project sling by apache.

the class ValidationModelRetrieverImpl method fillTrieForResourceType.

@Nonnull
private PatriciaTrie<ValidationModel> fillTrieForResourceType(@Nonnull String resourceType) {
    // create a new (empty) trie
    PatriciaTrie<ValidationModel> modelsForResourceType = new PatriciaTrie<ValidationModel>();
    // lowest ranked model provider inserts first (i.e. higher ranked should overwrite)
    for (ValidationModelProvider modelProvider : modelProviders) {
        LOG.debug("Retrieving validation models with resource type {} from provider {}...", resourceType, modelProvider.getClass().getName());
        List<ValidationModel> models = modelProvider.getValidationModels(resourceType);
        for (ValidationModel model : models) {
            for (String applicablePath : model.getApplicablePaths()) {
                LOG.debug("Found validation model for resource type {} for applicable path {}", resourceType, applicablePath);
                modelsForResourceType.put(applicablePath, model);
            }
        }
        if (models.isEmpty()) {
            LOG.debug("Found no validation model with resource type {} from provider {}", resourceType, modelProvider.getClass().getName());
        }
    }
    return modelsForResourceType;
}
Also used : MergedValidationModel(org.apache.sling.validation.impl.model.MergedValidationModel) ValidationModel(org.apache.sling.validation.model.ValidationModel) PatriciaTrie(org.apache.commons.collections4.trie.PatriciaTrie) ValidationModelProvider(org.apache.sling.validation.model.spi.ValidationModelProvider) Nonnull(javax.annotation.Nonnull)

Aggregations

ValidationModel (org.apache.sling.validation.model.ValidationModel)3 ValidationModelProvider (org.apache.sling.validation.model.spi.ValidationModelProvider)3 Test (org.junit.Test)2 Nonnull (javax.annotation.Nonnull)1 PatriciaTrie (org.apache.commons.collections4.trie.PatriciaTrie)1 MergedValidationModel (org.apache.sling.validation.impl.model.MergedValidationModel)1