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());
}
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());
}
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;
}
Aggregations