Add RestconfQueryParam
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / legacy / QueryParameters.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.nb.rfc8040.legacy;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import java.util.List;
14 import java.util.Set;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.restconf.nb.rfc8040.DepthParam;
18 import org.opendaylight.restconf.nb.rfc8040.ReadDataParams;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21
22 /**
23  * This holds various options acquired from a requests's query part. This class needs to be further split up to make
24  * sense of it, as parts of it pertain to how a {@link NormalizedNodePayload} should be created while others how it
25  * needs to be processed (for example filtered).
26  */
27 @Beta
28 // FIXME: this probably needs to be renamed back to WriterParams, or somesuch
29 public final class QueryParameters {
30     private static final @NonNull QueryParameters EMPTY = of(ReadDataParams.empty());
31
32     private final @NonNull ReadDataParams params;
33     private final List<YangInstanceIdentifier> fieldPaths;
34     private final List<Set<QName>> fields;
35
36     private QueryParameters(final ReadDataParams params, final List<Set<QName>> fields,
37             final List<YangInstanceIdentifier> fieldPaths) {
38         this.params = requireNonNull(params);
39         this.fields = fields;
40         this.fieldPaths = fieldPaths;
41     }
42
43     public static @NonNull QueryParameters empty() {
44         return EMPTY;
45     }
46
47     public static @NonNull QueryParameters of(final ReadDataParams params) {
48         return new QueryParameters(params, null, null);
49     }
50
51     public static @NonNull QueryParameters ofFields(final ReadDataParams params, final List<Set<QName>> fields) {
52         return new QueryParameters(params, fields, null);
53     }
54
55     public static @NonNull QueryParameters ofFieldPaths(final ReadDataParams params,
56             final List<YangInstanceIdentifier> fieldPaths) {
57         return new QueryParameters(params, null, fieldPaths);
58     }
59
60     public @NonNull ReadDataParams params() {
61         return params;
62     }
63
64     public @Nullable DepthParam depth() {
65         return params.depth();
66     }
67
68
69     public @Nullable List<Set<QName>> fields() {
70         return fields;
71     }
72
73     public @Nullable List<YangInstanceIdentifier> fieldPaths() {
74         return fieldPaths;
75     }
76
77     public boolean prettyPrint() {
78         return params.prettyPrint();
79     }
80 }