Use DepthParameter in QueryParameters
[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 java.util.List;
11 import java.util.Set;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.restconf.nb.rfc8040.ContentParameter;
15 import org.opendaylight.restconf.nb.rfc8040.DepthParameter;
16 import org.opendaylight.restconf.nb.rfc8040.WithDefaultsParameter;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19
20 /**
21  * This holds various options acquired from a requests's query part. This class needs to be further split up to make
22  * sense of it, as parts of it pertain to how a {@link NormalizedNodePayload} should be created while others how it
23  * needs to be processed (for example filtered).
24  */
25 public final class QueryParameters {
26     public static final class Builder {
27         private List<YangInstanceIdentifier> fieldPaths;
28         private List<Set<QName>> fields;
29         private ContentParameter content;
30         private WithDefaultsParameter withDefault;
31         private DepthParameter depth;
32         private boolean prettyPrint;
33         private boolean tagged;
34
35         Builder() {
36             // Hidden on purpose
37         }
38
39         public Builder setContent(final ContentParameter content) {
40             this.content = content;
41             return this;
42         }
43
44         public Builder setDepth(final DepthParameter depth) {
45             this.depth = depth;
46             return this;
47         }
48
49         public Builder setFields(final List<Set<QName>> fields) {
50             this.fields = fields;
51             return this;
52         }
53
54         public Builder setFieldPaths(final List<YangInstanceIdentifier> fieldPaths) {
55             this.fieldPaths = fieldPaths;
56             return this;
57         }
58
59         // FIXME: this is not called from anywhere. Create a PrettyPrintParameter or similar to hold it
60         public Builder setPrettyPrint(final boolean prettyPrint) {
61             this.prettyPrint = prettyPrint;
62             return this;
63         }
64
65         public Builder setTagged(final boolean tagged) {
66             this.tagged = tagged;
67             return this;
68         }
69
70         public Builder setWithDefault(final WithDefaultsParameter withDefault) {
71             this.withDefault = withDefault;
72             return this;
73         }
74
75         public @NonNull QueryParameters build() {
76             return new QueryParameters(this);
77         }
78     }
79
80     private static final @NonNull QueryParameters EMPTY = new Builder().build();
81
82     private final List<YangInstanceIdentifier> fieldPaths;
83     private final List<Set<QName>> fields;
84     private final WithDefaultsParameter withDefault;
85     private final ContentParameter content;
86     private final DepthParameter depth;
87     private final boolean prettyPrint;
88     private final boolean tagged;
89
90     private QueryParameters(final Builder builder) {
91         content = builder.content;
92         depth = builder.depth;
93         fields = builder.fields;
94         fieldPaths = builder.fieldPaths;
95         tagged = builder.tagged;
96         prettyPrint = builder.prettyPrint;
97         withDefault = builder.withDefault;
98     }
99
100     public static @NonNull QueryParameters empty() {
101         return EMPTY;
102     }
103
104     public static @NonNull Builder builder() {
105         return new Builder();
106     }
107
108     public ContentParameter getContent() {
109         return content;
110     }
111
112     public @Nullable DepthParameter getDepth() {
113         return depth;
114     }
115
116     public List<Set<QName>> getFields() {
117         return fields;
118     }
119
120     public List<YangInstanceIdentifier> getFieldPaths() {
121         return fieldPaths;
122     }
123
124     public WithDefaultsParameter getWithDefault() {
125         return withDefault;
126     }
127
128     public boolean isPrettyPrint() {
129         return prettyPrint;
130     }
131
132     public boolean isTagged() {
133         return tagged;
134     }
135 }