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