Search in sources :

Example 1 with DataTreeConfiguration

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;
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NormalizedNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer) Stopwatch(com.google.common.base.Stopwatch) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Nullable(org.eclipse.jdt.annotation.Nullable) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) DataContainerNode(org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) UniqueEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.UniqueEffectiveStatement) Collection(java.util.Collection) Descendant(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant) QName(org.opendaylight.yangtools.yang.common.QName) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) UniqueConstraintException(org.opendaylight.yangtools.yang.data.tree.api.UniqueConstraintException) NonNull(org.eclipse.jdt.annotation.NonNull) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DataTreeConfiguration(org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration) Descendant(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant) HashMap(java.util.HashMap) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull) Stopwatch(com.google.common.base.Stopwatch) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 2 with DataTreeConfiguration

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));
}
Also used : DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) DataTreeConfiguration(org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Test(org.junit.Test)

Example 3 with DataTreeConfiguration

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());
}
Also used : DataTreeConfiguration(org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration) Test(org.junit.Test)

Aggregations

DataTreeConfiguration (org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration)3 Test (org.junit.Test)2 ToStringHelper (com.google.common.base.MoreObjects.ToStringHelper)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Stopwatch (com.google.common.base.Stopwatch)1 Verify.verify (com.google.common.base.Verify.verify)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 QName (org.opendaylight.yangtools.yang.common.QName)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 DataContainerNode (org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode)1