Add representations of RFC8040 query parameters
[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.common.context.WriterParameters;
14 import org.opendaylight.restconf.nb.rfc8040.ContentParameter;
15 import org.opendaylight.restconf.nb.rfc8040.WithDefaultsParameter;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18
19 /**
20  * A RFC8040 overlay over {@link WriterParameters}. This holds various options acquired from a requests's query part.
21  * This class needs to be further split up to make sense of it, as parts of it pertain to how a
22  * {@link NormalizedNodePayload} should be created while others how it needs to be processed (for example filtered).
23  */
24 public final class QueryParameters extends WriterParameters {
25     public static final class Builder extends WriterParametersBuilder {
26         private List<YangInstanceIdentifier> fieldPaths;
27         private List<Set<QName>> fields;
28         private WithDefaultsParameter withDefault;
29         private boolean tagged;
30         private ContentParameter content;
31
32         Builder() {
33             // Hidden on purpose
34         }
35
36         public Builder setContent(final ContentParameter content) {
37             this.content = content;
38             return this;
39         }
40
41         public Builder setFields(final List<Set<QName>> fields) {
42             this.fields = fields;
43             return this;
44         }
45
46         public Builder setFieldPaths(final List<YangInstanceIdentifier> fieldPaths) {
47             this.fieldPaths = fieldPaths;
48             return this;
49         }
50
51         public Builder setTagged(final boolean tagged) {
52             this.tagged = tagged;
53             return this;
54         }
55
56         public Builder setWithDefault(final WithDefaultsParameter withDefault) {
57             this.withDefault = withDefault;
58             return this;
59         }
60
61         @Override
62         public @NonNull QueryParameters build() {
63             return new QueryParameters(this);
64         }
65     }
66
67     private static final @NonNull QueryParameters EMPTY = new Builder().build();
68
69     private final List<YangInstanceIdentifier> fieldPaths;
70     private final List<Set<QName>> fields;
71     private final WithDefaultsParameter withDefault;
72     private final ContentParameter content;
73     private final boolean tagged;
74
75     private QueryParameters(final Builder builder) {
76         super(builder);
77         content = builder.content;
78         fields = builder.fields;
79         fieldPaths = builder.fieldPaths;
80         tagged = builder.tagged;
81         withDefault = builder.withDefault;
82     }
83
84     public static @NonNull QueryParameters empty() {
85         return EMPTY;
86     }
87
88     public static @NonNull Builder builder() {
89         return new Builder();
90     }
91
92     public ContentParameter getContent() {
93         return content;
94     }
95
96     public List<Set<QName>> getFields() {
97         return fields;
98     }
99
100     public List<YangInstanceIdentifier> getFieldPaths() {
101         return fieldPaths;
102     }
103
104     public WithDefaultsParameter getWithDefault() {
105         return withDefault;
106     }
107
108     public boolean isTagged() {
109         return tagged;
110     }
111 }