use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.
the class LeafRefValidation method validateNode.
private void validateNode(final DataTreeCandidateNode node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final YangInstanceIdentifier current) {
if (node.getModificationType() == ModificationType.WRITE && node.getDataAfter().isPresent()) {
validateNodeData(node.getDataAfter().get(), referencedByCtx, referencingCtx, node.getModificationType(), current);
return;
}
if (node.getModificationType() == ModificationType.DELETE && referencedByCtx != null) {
validateNodeData(node.getDataBefore().get(), referencedByCtx, null, node.getModificationType(), current);
return;
}
for (final DataTreeCandidateNode childNode : node.getChildNodes()) {
if (childNode.getModificationType() != ModificationType.UNMODIFIED) {
final LeafRefContext childReferencedByCtx = getReferencedByCtxChild(referencedByCtx, childNode);
final LeafRefContext childReferencingCtx = getReferencingCtxChild(referencingCtx, childNode);
if (childReferencedByCtx != null || childReferencingCtx != null) {
validateNode(childNode, childReferencedByCtx, childReferencingCtx, current.node(childNode.getIdentifier()));
}
}
}
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.
the class DataTreeCandidatesTest method testEmptyMergesOnExisting.
@Test
public void testEmptyMergesOnExisting() throws DataValidationFailedException {
// Make sure 'non-presence' is present
DataTreeModification modification = dataTree.takeSnapshot().newModification();
modification.write(TestModel.NAME_PATH, ImmutableNodes.leafNode(TestModel.NAME_QNAME, "foo"));
modification.ready();
dataTree.validate(modification);
dataTree.commit(dataTree.prepare(modification));
// Issue an empty merge on it and a child choice
modification = dataTree.takeSnapshot().newModification();
modification.merge(TestModel.NON_PRESENCE_PATH, ImmutableNodes.containerNode(TestModel.NON_PRESENCE_QNAME));
modification.merge(TestModel.DEEP_CHOICE_PATH, ImmutableNodes.choiceNode(TestModel.DEEP_CHOICE_QNAME));
modification.ready();
dataTree.validate(modification);
// The entire transaction needs to fizzle to a no-op
final DataTreeCandidate candidate = dataTree.prepare(modification);
assertEquals(YangInstanceIdentifier.empty(), candidate.getRootPath());
final DataTreeCandidateNode node = candidate.getRootNode();
assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
// 'non-presence' and 'test'
assertUnmodified(2, node.getChildNodes());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.
the class DataTreeCandidatesTest method testEmptyWriteOnContainer.
@Test
public void testEmptyWriteOnContainer() throws DataValidationFailedException {
DataTreeModification modification = dataTree.takeSnapshot().newModification();
modification.write(TestModel.NON_PRESENCE_PATH, ImmutableNodes.containerNode(TestModel.NON_PRESENCE_QNAME));
modification.ready();
dataTree.validate(modification);
// The entire transaction needs to fizzle to a no-op
DataTreeCandidate candidate = dataTree.prepare(modification);
DataTreeCandidateNode node = candidate.getRootNode();
assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
// 'test'
assertUnmodified(1, node.getChildNodes());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.
the class DataTreeCandidatesTest method testEmptyMergesOnDeleted.
@Test
public void testEmptyMergesOnDeleted() throws DataValidationFailedException {
DataTreeModification modification = dataTree.takeSnapshot().newModification();
modification.delete(TestModel.NON_PRESENCE_PATH);
modification.merge(TestModel.DEEP_CHOICE_PATH, ImmutableNodes.choiceNode(TestModel.DEEP_CHOICE_QNAME));
modification.ready();
dataTree.validate(modification);
final DataTreeCandidate candidate = dataTree.prepare(modification);
assertEquals(YangInstanceIdentifier.empty(), candidate.getRootPath());
final DataTreeCandidateNode node = candidate.getRootNode();
assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
// 'test'
assertUnmodified(1, node.getChildNodes());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.
the class DataTreeCandidates method cleanUpTree.
// Compare data before and after in order to find modified nodes without actual changes
private static DataTreeCandidateNode cleanUpTree(final TerminalDataTreeCandidateNode finalNode, final TerminalDataTreeCandidateNode node) {
PathArgument identifier = node.getIdentifier();
ModificationType nodeModification = node.getModificationType();
Collection<DataTreeCandidateNode> childNodes = node.getChildNodes();
for (DataTreeCandidateNode childNode : childNodes) {
cleanUpTree(finalNode, (TerminalDataTreeCandidateNode) childNode);
}
Optional<NormalizedNode> dataBefore = finalNode.getDataBefore(identifier);
switch(nodeModification) {
case UNMODIFIED:
finalNode.deleteNode(identifier);
return finalNode;
case WRITE:
return finalNode;
case DELETE:
if (dataBefore.isEmpty()) {
finalNode.deleteNode(identifier);
}
return finalNode;
case APPEARED:
if (dataBefore.isPresent()) {
illegalModification(ModificationType.APPEARED, ModificationType.WRITE);
}
if (childNodes.isEmpty()) {
finalNode.deleteNode(identifier);
}
return finalNode;
case DISAPPEARED:
if (dataBefore.isEmpty() || childNodes.isEmpty()) {
finalNode.deleteNode(identifier);
}
return finalNode;
case SUBTREE_MODIFIED:
if (dataBefore.isEmpty()) {
illegalModification(ModificationType.SUBTREE_MODIFIED, ModificationType.DELETE);
}
if (childNodes.isEmpty()) {
finalNode.deleteNode(identifier);
}
return finalNode;
default:
throw new IllegalStateException("Unsupported modification type " + nodeModification);
}
}
Aggregations