Update sal-remote-augment model to rev 2023-11-03
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / ReceiveEventsParams.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.opendaylight.restconf.api.query.ChangedLeafNodesOnlyParam;
13 import org.opendaylight.restconf.api.query.ChildNodesOnlyParam;
14 import org.opendaylight.restconf.api.query.FilterParam;
15 import org.opendaylight.restconf.api.query.LeafNodesOnlyParam;
16 import org.opendaylight.restconf.api.query.SkipNotificationDataParam;
17 import org.opendaylight.restconf.api.query.StartTimeParam;
18 import org.opendaylight.restconf.api.query.StopTimeParam;
19
20 /**
21  * Query parameters valid in the scope of a GET request on an event stream resource, as outline in
22  * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-6.3">RFC8040 section 6.3</a>.
23  */
24 public record ReceiveEventsParams(
25         StartTimeParam startTime,
26         StopTimeParam stopTime,
27         FilterParam filter,
28         LeafNodesOnlyParam leafNodesOnly,
29         SkipNotificationDataParam skipNotificationData,
30         ChangedLeafNodesOnlyParam changedLeafNodesOnly,
31         ChildNodesOnlyParam childNodesOnly) {
32     public ReceiveEventsParams {
33         if (stopTime != null && startTime == null) {
34             throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
35                 + StartTimeParam.uriName + " parameter");
36         }
37         if (changedLeafNodesOnly != null) {
38             if (leafNodesOnly != null) {
39                 throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
40                     + LeafNodesOnlyParam.uriName + " parameter");
41             }
42             if (childNodesOnly != null) {
43                 throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
44                     + ChildNodesOnlyParam.uriName + " parameter");
45             }
46         }
47     }
48
49     @Override
50     public String toString() {
51         final var helper = MoreObjects.toStringHelper(this);
52         if (startTime != null) {
53             helper.add("startTime", startTime.paramValue());
54         }
55         if (stopTime != null) {
56             helper.add("stopTime", stopTime.paramValue());
57         }
58         if (filter != null) {
59             helper.add("filter", filter.paramValue());
60         }
61         if (leafNodesOnly != null) {
62             helper.add("leafNodesOnly", leafNodesOnly.value());
63         }
64         if (skipNotificationData != null) {
65             helper.add("skipNotificationData", skipNotificationData.value());
66         }
67         if (changedLeafNodesOnly != null) {
68             helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
69         }
70         if (childNodesOnly != null) {
71             helper.add("childNodesOnly", childNodesOnly.value());
72         }
73         return helper.toString();
74     }
75 }