2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.legacy;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableMap;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
19 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
22 * A RFC8040 overlay from our marriage to NormalizedNodeContext. This represents a NormalizedNode along with further
23 * messy details needed to deal with the payload.
25 public final class NormalizedNodePayload {
26 private final @NonNull ImmutableMap<String, Object> headers;
27 private final @NonNull QueryParameters writerParameters;
28 private final @NonNull Inference inference;
29 private final NormalizedNode data;
31 private NormalizedNodePayload(final Inference inference, final NormalizedNode data,
32 final QueryParameters writerParameters, final ImmutableMap<String, Object> headers) {
33 this.inference = requireNonNull(inference);
35 this.writerParameters = requireNonNull(writerParameters);
36 this.headers = requireNonNull(headers);
39 public static @NonNull NormalizedNodePayload empty(final Inference inference) {
40 return new NormalizedNodePayload(inference, null, QueryParameters.empty(), ImmutableMap.of());
43 public static @NonNull NormalizedNodePayload of(final Inference inference, final NormalizedNode data) {
44 return new NormalizedNodePayload(inference, requireNonNull(data), QueryParameters.empty(), ImmutableMap.of());
47 public static @NonNull NormalizedNodePayload ofNullable(final Inference inference, final NormalizedNode data) {
48 return data == null ? empty(inference) : of(inference, data);
51 // FIXME: can we get rid of this, please? Whoever is using this should be setting a Response instead
53 public static @NonNull NormalizedNodePayload ofLocation(final Inference inference, final NodeIdentifier leafId,
55 return new NormalizedNodePayload(inference, ImmutableNodes.leafNode(leafId, location.toString()),
56 QueryParameters.empty(), ImmutableMap.of("Location", location));
59 public static Object ofReadData(final Inference inference, final NormalizedNode data,
60 final QueryParameters parameters) {
61 return new NormalizedNodePayload(inference, requireNonNull(data), parameters, ImmutableMap.of());
64 public @NonNull Inference inference() {
68 public @Nullable NormalizedNode getData() {
73 * Return headers response headers.
75 * @return map of headers
77 // FIXME: this is only used for redirect on subscribe
78 public @NonNull ImmutableMap<String, Object> getNewHeaders() {
82 public @NonNull QueryParameters getWriterParameters() {
83 return writerParameters;