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