ae586892af10b5f4e521fc97abfff3dca9b57a74
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / NotificationQueryParams.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  * Copyright (c) 2021 PANTHEON.tech, s.r.o.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9 package org.opendaylight.restconf.nb.rfc8040;
10
11 import com.google.common.base.MoreObjects;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.restconf.api.query.ChangedLeafNodesOnlyParam;
15 import org.opendaylight.restconf.api.query.FilterParam;
16 import org.opendaylight.restconf.api.query.LeafNodesOnlyParam;
17 import org.opendaylight.restconf.api.query.SkipNotificationDataParam;
18 import org.opendaylight.restconf.api.query.StartTimeParam;
19 import org.opendaylight.restconf.api.query.StopTimeParam;
20 import org.opendaylight.yangtools.concepts.Immutable;
21
22 /**
23  * Parser and holder of query parameters from uriInfo for notifications.
24  */
25 public final class NotificationQueryParams implements Immutable {
26     private final SkipNotificationDataParam skipNotificationData;
27     private final LeafNodesOnlyParam leafNodesOnly;
28     private final StartTimeParam startTime;
29     private final StopTimeParam stopTime;
30     private final FilterParam filter;
31     private final ChangedLeafNodesOnlyParam changedLeafNodesOnly;
32
33     private NotificationQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime,
34             final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
35             final SkipNotificationDataParam skipNotificationData,
36             final ChangedLeafNodesOnlyParam changedLeafNodesOnly) {
37         this.startTime = startTime;
38         this.stopTime = stopTime;
39         this.filter = filter;
40         this.leafNodesOnly = leafNodesOnly;
41         this.skipNotificationData = skipNotificationData;
42         this.changedLeafNodesOnly = changedLeafNodesOnly;
43     }
44
45     public static @NonNull NotificationQueryParams of(final StartTimeParam startTime, final StopTimeParam stopTime,
46             final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
47             final SkipNotificationDataParam skipNotificationData,
48             final ChangedLeafNodesOnlyParam changedLeafNodesOnly) {
49         if (stopTime != null && startTime == null) {
50             throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
51                 + StartTimeParam.uriName + " parameter");
52         }
53         if (changedLeafNodesOnly != null && leafNodesOnly != null) {
54             throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
55                 + LeafNodesOnlyParam.uriName + " parameter");
56         }
57         return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
58                 changedLeafNodesOnly);
59     }
60
61     /**
62      * Get start-time query parameter.
63      *
64      * @return start-time
65      */
66     public @Nullable StartTimeParam startTime() {
67         return startTime;
68     }
69
70     /**
71      * Get stop-time query parameter.
72      *
73      * @return stop-time
74      */
75     public @Nullable StopTimeParam stopTime() {
76         return stopTime;
77     }
78
79     /**
80      * Get filter query parameter.
81      *
82      * @return filter
83      */
84     public @Nullable FilterParam filter() {
85         return filter;
86     }
87
88     /**
89      * Get odl-leaf-nodes-only query parameter.
90      *
91      * @return odl-leaf-nodes-only
92      */
93     public @Nullable LeafNodesOnlyParam leafNodesOnly() {
94         return leafNodesOnly;
95     }
96
97     /**
98      * Get odl-skip-notification-data query parameter.
99      *
100      * @return odl-skip-notification-data
101      */
102     public @Nullable SkipNotificationDataParam skipNotificationData() {
103         return skipNotificationData;
104     }
105
106     /**
107      * Get changed-leaf-nodes-only query parameter.
108      *
109      * @return changed-leaf-nodes-only
110      */
111     public @Nullable ChangedLeafNodesOnlyParam changedLeafNodesOnly() {
112         return changedLeafNodesOnly;
113     }
114
115     @Override
116     public String toString() {
117         final var helper = MoreObjects.toStringHelper(this);
118         if (startTime != null) {
119             helper.add("startTime", startTime.paramValue());
120         }
121         if (stopTime != null) {
122             helper.add("stopTime", stopTime.paramValue());
123         }
124         if (filter != null) {
125             helper.add("filter", filter.paramValue());
126         }
127         if (leafNodesOnly != null) {
128             helper.add("leafNodesOnly", leafNodesOnly.value());
129         }
130         if (skipNotificationData != null) {
131             helper.add("skipNotificationData", skipNotificationData.value());
132         }
133         if (changedLeafNodesOnly != null) {
134             helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
135         }
136         return helper.toString();
137     }
138 }