Split out restconf-api
[netconf.git] / protocol / restconf-api / src / main / java / org / opendaylight / restconf / api / query / WithDefaultsParam.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.api.query;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.net.URI;
13 import org.eclipse.jdt.annotation.NonNull;
14
15 /**
16  * Enumeration of possible {@code with-defaults} parameter values as defined by
17  * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.9">RFC8040, section 4.8.9</a>.
18  */
19 public enum WithDefaultsParam implements RestconfQueryParam<WithDefaultsParam> {
20     /**
21      * Data nodes set to the YANG default by the client are reported.
22      */
23     EXPLICIT("explicit"),
24     /**
25      * All data nodes are reported.
26      */
27     REPORT_ALL("report-all"),
28     /**
29      * All data nodes are reported, and defaults are tagged.
30      */
31     REPORT_ALL_TAGGED("report-all-tagged"),
32     /**
33      * Data nodes set to the YANG default are not reported.
34      */
35     TRIM("trim");
36
37     // API consistency: must not be confused with enum constants
38     @SuppressWarnings("checkstyle:ConstantName")
39     public static final @NonNull String uriName = "with-defaults";
40
41     private static final @NonNull URI CAPABILITY = URI.create("urn:ietf:params:restconf:capability:with-defaults:1.0");
42
43     private final @NonNull String uriValue;
44
45     WithDefaultsParam(final String uriValue) {
46         this.uriValue = requireNonNull(uriValue);
47     }
48
49     @Override
50     public Class<WithDefaultsParam> javaClass() {
51         return WithDefaultsParam.class;
52     }
53
54     @Override
55     public String paramName() {
56         return uriName;
57     }
58
59     @Override
60     public String paramValue() {
61         return uriValue;
62     }
63
64     public static @NonNull WithDefaultsParam forUriValue(final String uriValue) {
65         return switch (uriValue) {
66             case "explicit" -> EXPLICIT;
67             case "report-all" -> REPORT_ALL;
68             case "report-all-tagged" -> REPORT_ALL_TAGGED;
69             case "trim" -> TRIM;
70             default -> throw new IllegalArgumentException(
71                 "Value can be 'explicit', 'report-all', 'report-all-tagged' or 'trim', not '" + uriValue + "'");
72         };
73     }
74
75     public static @NonNull URI capabilityUri() {
76         return CAPABILITY;
77     }
78 }