use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration in project yangtools by opendaylight.
the class UniqueValidation method validatorsOf.
static ImmutableList<UniqueValidator<?>> validatorsOf(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
final Collection<? extends @NonNull UniqueEffectiveStatement> uniques = schema.getUniqueConstraints();
if (!treeConfig.isUniqueIndexEnabled() || uniques.isEmpty()) {
return ImmutableList.of();
}
final Stopwatch sw = Stopwatch.createStarted();
final Map<Descendant, List<NodeIdentifier>> paths = new HashMap<>();
final ImmutableList<UniqueValidator<?>> validators = uniques.stream().map(unique -> UniqueValidator.of(unique.argument().stream().map(descendant -> paths.computeIfAbsent(descendant, key -> toDescendantPath(schema, key))).collect(ImmutableList.toImmutableList()))).collect(ImmutableList.toImmutableList());
LOG.debug("Constructed {} validators in {}", validators.size(), sw);
return validators;
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration in project yangtools by opendaylight.
the class MapEntryRootTest method testMapEntryRoot.
@Test
public void testMapEntryRoot() {
final DataTreeConfiguration treeConfig = DataTreeConfiguration.builder(TreeType.OPERATIONAL).setRootPath(TestModel.TEST_PATH.node(TestModel.OUTER_LIST_QNAME).node(NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, (short) 12))).build();
final DataTree dataTree = new InMemoryDataTreeFactory().create(treeConfig, SCHEMA_CONTEXT);
assertTrue(dataTree instanceof InMemoryDataTree);
final InMemoryDataTree imdt = (InMemoryDataTree) dataTree;
final InMemoryDataTreeModification mod = imdt.takeSnapshot().newModification();
final ModificationApplyOperation strategy = mod.getStrategy();
assertThat(strategy, instanceOf(MapEntryModificationStrategy.class));
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration in project yangtools by opendaylight.
the class DataTreeConfigurationTest method testDataTreeConfiguration.
@Test
public void testDataTreeConfiguration() {
DataTreeConfiguration.Builder builder = new DataTreeConfiguration.Builder(TreeType.CONFIGURATION);
builder.setUniqueIndexes(true);
builder.setMandatoryNodesValidation(true);
DataTreeConfiguration dataTreeConfiguration = builder.build();
assertEquals(TreeType.CONFIGURATION, dataTreeConfiguration.getTreeType());
assertTrue(dataTreeConfiguration.isUniqueIndexEnabled());
assertTrue(dataTreeConfiguration.isMandatoryNodesValidationEnabled());
builder = new DataTreeConfiguration.Builder(TreeType.OPERATIONAL);
builder.setUniqueIndexes(false);
builder.setMandatoryNodesValidation(false);
dataTreeConfiguration = builder.build();
assertEquals(TreeType.OPERATIONAL, dataTreeConfiguration.getTreeType());
assertFalse(dataTreeConfiguration.isUniqueIndexEnabled());
assertFalse(dataTreeConfiguration.isMandatoryNodesValidationEnabled());
dataTreeConfiguration = DataTreeConfiguration.getDefault(TreeType.CONFIGURATION);
assertEquals(TreeType.CONFIGURATION, dataTreeConfiguration.getTreeType());
assertFalse(dataTreeConfiguration.isUniqueIndexEnabled());
assertTrue(dataTreeConfiguration.isMandatoryNodesValidationEnabled());
dataTreeConfiguration = DataTreeConfiguration.getDefault(TreeType.OPERATIONAL);
assertEquals(TreeType.OPERATIONAL, dataTreeConfiguration.getTreeType());
assertFalse(dataTreeConfiguration.isUniqueIndexEnabled());
assertTrue(dataTreeConfiguration.isMandatoryNodesValidationEnabled());
}
Aggregations