4fa5a521da8bee65ecf6a62d904b4cdd734a6ba7
[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 java.util.List;
13 import java.util.Set;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.restconf.nb.rfc8040.ContentParameter;
17 import org.opendaylight.restconf.nb.rfc8040.DepthParameter;
18 import org.opendaylight.restconf.nb.rfc8040.WithDefaultsParameter;
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 public final class QueryParameters {
28     public static final class Builder {
29         private @NonNull ContentParameter content = ContentParameter.ALL;
30         private List<YangInstanceIdentifier> fieldPaths;
31         private List<Set<QName>> fields;
32         private WithDefaultsParameter withDefault;
33         private DepthParameter depth;
34         private boolean prettyPrint;
35         private boolean tagged;
36
37         Builder() {
38             // Hidden on purpose
39         }
40
41         public Builder setContent(final ContentParameter content) {
42             this.content = requireNonNull(content);
43             return this;
44         }
45
46         public Builder setDepth(final DepthParameter depth) {
47             this.depth = depth;
48             return this;
49         }
50
51         public Builder setFields(final List<Set<QName>> fields) {
52             this.fields = fields;
53             return this;
54         }
55
56         public Builder setFieldPaths(final List<YangInstanceIdentifier> fieldPaths) {
57             this.fieldPaths = fieldPaths;
58             return this;
59         }
60
61         // FIXME: this is not called from anywhere. Create a PrettyPrintParameter or similar to hold it
62         public Builder setPrettyPrint(final boolean prettyPrint) {
63             this.prettyPrint = prettyPrint;
64             return this;
65         }
66
67         public Builder setTagged(final boolean tagged) {
68             this.tagged = tagged;
69             return this;
70         }
71
72         public Builder setWithDefault(final WithDefaultsParameter withDefault) {
73             this.withDefault = withDefault;
74             return this;
75         }
76
77         public @NonNull QueryParameters build() {
78             return new QueryParameters(this);
79         }
80     }
81
82     private static final @NonNull QueryParameters EMPTY = new Builder().build();
83
84     private final List<YangInstanceIdentifier> fieldPaths;
85     private final List<Set<QName>> fields;
86     private final WithDefaultsParameter withDefault;
87     private final @NonNull ContentParameter content;
88     private final DepthParameter depth;
89     private final boolean prettyPrint;
90     private final boolean tagged;
91
92     private QueryParameters(final Builder builder) {
93         content = builder.content;
94         depth = builder.depth;
95         fields = builder.fields;
96         fieldPaths = builder.fieldPaths;
97         tagged = builder.tagged;
98         prettyPrint = builder.prettyPrint;
99         withDefault = builder.withDefault;
100     }
101
102     public static @NonNull QueryParameters empty() {
103         return EMPTY;
104     }
105
106     public static @NonNull Builder builder() {
107         return new Builder();
108     }
109
110     public @NonNull ContentParameter getContent() {
111         return content;
112     }
113
114     public @Nullable DepthParameter getDepth() {
115         return depth;
116     }
117
118     public List<Set<QName>> getFields() {
119         return fields;
120     }
121
122     public List<YangInstanceIdentifier> getFieldPaths() {
123         return fieldPaths;
124     }
125
126     public WithDefaultsParameter getWithDefault() {
127         return withDefault;
128     }
129
130     public boolean isPrettyPrint() {
131         return prettyPrint;
132     }
133
134     public boolean isTagged() {
135         return tagged;
136     }
137 }