2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
10 import java.util.ArrayList;
11 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
15 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 * Util class for common methods of transactions.
21 public final class TransactionUtil {
22 private TransactionUtil() {
27 * Merged parents of data.
29 * @param path path of data
30 * @param schemaContext {@link SchemaContext}
31 * @param transaction A handle to a set of DS operations
33 // FIXME: this method should only be invoked in MdsalRestconfStrategy, and even then only if we are crossing
35 public static void ensureParentsByMerge(final YangInstanceIdentifier path,
36 final EffectiveModelContext schemaContext,
37 final RestconfTransaction transaction) {
38 final var normalizedPathWithoutChildArgs = new ArrayList<PathArgument>();
39 YangInstanceIdentifier rootNormalizedPath = null;
41 final var it = path.getPathArguments().iterator();
43 while (it.hasNext()) {
44 final var pathArgument = it.next();
45 if (rootNormalizedPath == null) {
46 rootNormalizedPath = YangInstanceIdentifier.of(pathArgument);
50 normalizedPathWithoutChildArgs.add(pathArgument);
54 if (normalizedPathWithoutChildArgs.isEmpty()) {
58 transaction.merge(rootNormalizedPath,
59 ImmutableNodes.fromInstanceId(schemaContext, YangInstanceIdentifier.of(normalizedPathWithoutChildArgs)));