Remove "/" sign in AbstractRestconfStreamRegistry
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / DataGetParams.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.server.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.restconf.api.QueryParameters;
15 import org.opendaylight.restconf.api.query.ContentParam;
16 import org.opendaylight.restconf.api.query.DepthParam;
17 import org.opendaylight.restconf.api.query.FieldsParam;
18 import org.opendaylight.restconf.api.query.WithDefaultsParam;
19
20 /**
21  * Supported query parameters of {@code /data} {@code GET} HTTP operation, as defined in
22  * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.3">RFC8040 section 4.3</a>.
23  */
24 public record DataGetParams(
25         @NonNull ContentParam content,
26         @Nullable DepthParam depth,
27         @Nullable FieldsParam fields,
28         @Nullable WithDefaultsParam withDefaults) {
29     public static final @NonNull DataGetParams EMPTY = new DataGetParams(ContentParam.ALL, null, null, null);
30
31     public DataGetParams {
32         requireNonNull(content);
33     }
34
35     /**
36      * Return {@link DataGetParams} for specified query parameters.
37      *
38      * @param params Parameters and their values
39      * @return A {@link DataGetParams}
40      * @throws NullPointerException if {@code queryParameters} is {@code null}
41      * @throws IllegalArgumentException if the parameters are invalid
42      */
43     public static @NonNull DataGetParams of(final QueryParameters params) {
44         ContentParam content = ContentParam.ALL;
45         DepthParam depth = null;
46         FieldsParam fields = null;
47         WithDefaultsParam withDefaults = null;
48
49         for (var entry : params.asCollection()) {
50             final var name = entry.getKey();
51             final var value = entry.getValue();
52
53             switch (name) {
54                 case ContentParam.uriName:
55                     content = ContentParam.forUriValue(value);
56                     break;
57                 case DepthParam.uriName:
58                     depth = DepthParam.forUriValue(value);
59                     break;
60                 case FieldsParam.uriName:
61                     fields = FieldsParam.forUriValue(value);
62                     break;
63                 case WithDefaultsParam.uriName:
64                     withDefaults = WithDefaultsParam.forUriValue(value);
65                     break;
66                 default:
67                     throw new IllegalArgumentException("Unknown parameter in /data GET: " + name);
68             }
69         }
70
71         return new DataGetParams(content, depth, fields, withDefaults);
72     }
73 }