import java.util.List;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
import org.opendaylight.yangtools.yang.data.api.schema.AnyxmlNode;
import org.opendaylight.yangtools.yang.data.tree.impl.node.Version;
import org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
if (!belongsToTree(treeConfig.getTreeType(), schemaNode)) {
throw new ExcludedDataSchemaNodeException(schemaNode + " does not belong to configuration tree");
}
- if (schemaNode instanceof ContainerSchemaNode) {
- return ContainerModificationStrategy.of((ContainerSchemaNode) schemaNode, treeConfig);
- } else if (schemaNode instanceof ListSchemaNode) {
- return fromListSchemaNode((ListSchemaNode) schemaNode, treeConfig);
- } else if (schemaNode instanceof ChoiceSchemaNode) {
- return new ChoiceModificationStrategy((ChoiceSchemaNode) schemaNode, treeConfig);
- } else if (schemaNode instanceof LeafListSchemaNode) {
- return MinMaxElementsValidation.from(new LeafSetModificationStrategy((LeafListSchemaNode) schemaNode,
- treeConfig));
- } else if (schemaNode instanceof LeafSchemaNode) {
- return new ValueNodeModificationStrategy<>(LeafNode.class, (LeafSchemaNode) schemaNode);
- } else if (schemaNode instanceof AnydataSchemaNode) {
- return new ValueNodeModificationStrategy<>(AnydataNode.class, (AnydataSchemaNode) schemaNode);
- } else if (schemaNode instanceof AnyxmlSchemaNode) {
- return new ValueNodeModificationStrategy<>(AnyxmlNode.class, (AnyxmlSchemaNode) schemaNode);
- } else if (schemaNode instanceof SchemaContext) {
- return new StructuralContainerModificationStrategy((SchemaContext) schemaNode, treeConfig);
+ if (schemaNode instanceof ContainerSchemaNode container) {
+ return ContainerModificationStrategy.of(container, treeConfig);
+ } else if (schemaNode instanceof ListSchemaNode list) {
+ return fromListSchemaNode(list, treeConfig);
+ } else if (schemaNode instanceof ChoiceSchemaNode choice) {
+ return new ChoiceModificationStrategy(choice, treeConfig);
+ } else if (schemaNode instanceof LeafListSchemaNode leafList) {
+ return MinMaxElementsValidation.from(new LeafSetModificationStrategy(leafList, treeConfig));
+ } else if (schemaNode instanceof LeafSchemaNode leaf) {
+ return new ValueNodeModificationStrategy<>(LeafNode.class, leaf);
+ } else if (schemaNode instanceof AnydataSchemaNode anydata) {
+ return new ValueNodeModificationStrategy<>(AnydataNode.class, anydata);
+ } else if (schemaNode instanceof AnyxmlSchemaNode anyxml) {
+ return new ValueNodeModificationStrategy<>(AnyxmlNode.class, anyxml);
+ } else if (schemaNode instanceof SchemaContext context) {
+ return new StructuralContainerModificationStrategy(context, treeConfig);
} else {
throw new IllegalStateException("Unsupported schema " + schemaNode);
}
}
- static @Nullable AugmentationModificationStrategy from(final DataNodeContainer resolvedTree,
- final AugmentationTarget augSchemas, final AugmentationIdentifier identifier,
- final DataTreeConfiguration treeConfig) {
- for (final AugmentationSchemaNode potential : augSchemas.getAvailableAugmentations()) {
- for (final DataSchemaNode child : potential.getChildNodes()) {
- if (identifier.getPossibleChildNames().contains(child.getQName())) {
- return new AugmentationModificationStrategy(potential, resolvedTree, treeConfig);
- }
- }
- }
-
- return null;
- }
-
static void checkConflicting(final ModificationPath path, final boolean condition, final String message)
throws ConflictingModificationAppliedException {
if (!condition) {
final void checkApplicable(final ModificationPath path, final NodeModification modification,
final Optional<? extends TreeNode> current, final Version version) throws DataValidationFailedException {
switch (modification.getOperation()) {
- case DELETE:
- checkDeleteApplicable(modification, current);
- break;
- case TOUCH:
- checkTouchApplicable(path, modification, current, version);
- break;
- case WRITE:
- checkWriteApplicable(path, modification, current, version);
- break;
- case MERGE:
- checkMergeApplicable(path, modification, current, version);
- break;
- case NONE:
- break;
- default:
- throw new UnsupportedOperationException(
- "Suplied modification type " + modification.getOperation() + " is not supported.");
+ case DELETE -> checkDeleteApplicable(modification, current);
+ case TOUCH -> checkTouchApplicable(path, modification, current, version);
+ case WRITE -> checkWriteApplicable(path, modification, current, version);
+ case MERGE -> checkMergeApplicable(path, modification, current, version);
+ case NONE -> {
+ // No-op
+ }
+ default -> throw new UnsupportedOperationException(
+ "Suplied modification type " + modification.getOperation() + " is not supported.");
}
}
* it should not cause transaction to fail, since result of this merge
* leads to same data.
*/
- final TreeNode orig = original.get();
- final TreeNode cur = current.get();
+ final TreeNode orig = original.orElseThrow();
+ final TreeNode cur = current.orElseThrow();
if (!orig.getData().equals(cur.getData())) {
checkNotConflicting(path, orig, cur);
}
final Optional<? extends TreeNode> current, final Version version) throws DataValidationFailedException {
final Optional<? extends TreeNode> original = modification.getOriginal();
if (original.isPresent() && current.isPresent()) {
- checkNotConflicting(path, original.get(), current.get());
+ checkNotConflicting(path, original.orElseThrow(), current.orElseThrow());
} else {
checkConflicting(path, !original.isPresent(), "Node was deleted by other transaction.");
checkConflicting(path, !current.isPresent(), "Node was created by other transaction.");
@Override
Optional<? extends TreeNode> apply(final ModifiedNode modification, final Optional<? extends TreeNode> currentMeta,
final Version version) {
- switch (modification.getOperation()) {
- case DELETE:
+ return switch (modification.getOperation()) {
+ case DELETE -> {
// Deletion of a non-existing node is a no-op, report it as such
modification.resolveModificationType(currentMeta.isPresent() ? ModificationType.DELETE
: ModificationType.UNMODIFIED);
- return modification.setSnapshot(Optional.empty());
- case TOUCH:
+ yield modification.setSnapshot(Optional.empty());
+ }
+ case TOUCH -> {
checkArgument(currentMeta.isPresent(), "Metadata not available for modification %s", modification);
- return modification.setSnapshot(Optional.of(applyTouch(modification, currentMeta.get(),
+ yield modification.setSnapshot(Optional.of(applyTouch(modification, currentMeta.orElseThrow(),
version)));
- case MERGE:
+ }
+ case MERGE -> {
final TreeNode result;
if (!currentMeta.isPresent()) {
result = applyWrite(modification, modification.getWrittenValue(), currentMeta, version);
fullVerifyStructure(result.getData());
} else {
- result = applyMerge(modification, currentMeta.get(), version);
+ result = applyMerge(modification, currentMeta.orElseThrow(), version);
}
- return modification.setSnapshot(Optional.of(result));
- case WRITE:
+ yield modification.setSnapshot(Optional.of(result));
+ }
+ case WRITE -> {
modification.resolveModificationType(ModificationType.WRITE);
- return modification.setSnapshot(Optional.of(applyWrite(modification,
+ yield modification.setSnapshot(Optional.of(applyWrite(modification,
verifyNotNull(modification.getWrittenValue()), currentMeta, version)));
- case NONE:
+ }
+ case NONE -> {
modification.resolveModificationType(ModificationType.UNMODIFIED);
- return currentMeta;
- default:
- throw new IllegalArgumentException("Provided modification type is not supported.");
- }
+ yield currentMeta;
+ }
+ };
}
/**