5
5
package com .backblaze .b2 .client .structures ;
6
6
7
7
import com .backblaze .b2 .json .B2Json ;
8
- import com .backblaze .b2 .util .B2Preconditions ;
9
- import com .backblaze .b2 .util .B2StringUtil ;
10
8
11
9
import java .util .Comparator ;
12
10
import java .util .Objects ;
15
13
/**
16
14
* One rule about under what condition(s) to send notifications for events in a bucket.
17
15
*/
18
- public class B2EventNotificationRuleForResponse implements Comparable <B2EventNotificationRuleForResponse > {
19
- private static final Comparator <B2EventNotificationRuleForResponse > COMPARATOR = Comparator .comparing (B2EventNotificationRuleForResponse ::getName )
16
+ public class B2EventNotificationRule implements Comparable <B2EventNotificationRule > {
17
+ private static final Comparator <B2EventNotificationRule > COMPARATOR = Comparator .comparing (B2EventNotificationRule ::getName )
20
18
.thenComparing (rule -> String .join ("," , rule .getEventTypes ()))
21
- .thenComparing (B2EventNotificationRuleForResponse ::getObjectNamePrefix )
19
+ .thenComparing (B2EventNotificationRule ::getObjectNamePrefix )
22
20
.thenComparing (rule -> rule .getTargetConfiguration ().toString ())
23
- .thenComparing (B2EventNotificationRuleForResponse ::isEnabled )
24
- .thenComparing (B2EventNotificationRuleForResponse ::isSuspended )
25
- .thenComparing (B2EventNotificationRuleForResponse ::getSuspensionReason );
21
+ .thenComparing (B2EventNotificationRule ::isEnabled )
22
+ .thenComparing (B2EventNotificationRule ::isSuspended )
23
+ .thenComparing (B2EventNotificationRule ::getSuspensionReason );
26
24
27
25
/**
28
26
* A name for identifying the rule. Names must be unique within a bucket.
@@ -52,7 +50,7 @@ public class B2EventNotificationRuleForResponse implements Comparable<B2EventNot
52
50
* The target configuration for the event notification.
53
51
*/
54
52
@ B2Json .required
55
- private final B2EventNotificationTargetConfigurationForResponse targetConfiguration ;
53
+ private final B2EventNotificationTargetConfiguration targetConfiguration ;
56
54
57
55
/**
58
56
* Indicates if the rule is enabled.
@@ -63,8 +61,8 @@ public class B2EventNotificationRuleForResponse implements Comparable<B2EventNot
63
61
/**
64
62
* Indicates if the rule is suspended.
65
63
*/
66
- @ B2Json .required
67
- private final boolean isSuspended ;
64
+ @ B2Json .optional
65
+ private final Boolean isSuspended ;
68
66
69
67
/**
70
68
* If isSuspended is true, specifies the reason the rule was
@@ -74,18 +72,13 @@ public class B2EventNotificationRuleForResponse implements Comparable<B2EventNot
74
72
private final String suspensionReason ;
75
73
76
74
@ B2Json .constructor
77
- public B2EventNotificationRuleForResponse (String name ,
78
- TreeSet <String > eventTypes ,
79
- String objectNamePrefix ,
80
- B2EventNotificationTargetConfigurationForResponse targetConfiguration ,
81
- boolean isEnabled ,
82
- boolean isSuspended ,
83
- String suspensionReason ) {
84
-
85
- B2Preconditions .checkArgument (
86
- !isSuspended || !B2StringUtil .isEmpty (suspensionReason ),
87
- "A suspension reason is required if isSuspended is true"
88
- );
75
+ public B2EventNotificationRule (String name ,
76
+ TreeSet <String > eventTypes ,
77
+ String objectNamePrefix ,
78
+ B2EventNotificationTargetConfiguration targetConfiguration ,
79
+ boolean isEnabled ,
80
+ Boolean isSuspended ,
81
+ String suspensionReason ) {
89
82
90
83
this .name = name ;
91
84
this .eventTypes = new TreeSet <>(eventTypes );
@@ -96,12 +89,12 @@ public B2EventNotificationRuleForResponse(String name,
96
89
this .suspensionReason = suspensionReason ;
97
90
}
98
91
99
- public B2EventNotificationRuleForResponse (String name ,
100
- TreeSet <String > eventTypes ,
101
- String objectNamePrefix ,
102
- B2EventNotificationTargetConfigurationForResponse targetConfiguration ,
103
- boolean isEnabled ) {
104
- this (name , eventTypes , objectNamePrefix , targetConfiguration , isEnabled , false , null );
92
+ public B2EventNotificationRule (String name ,
93
+ TreeSet <String > eventTypes ,
94
+ String objectNamePrefix ,
95
+ B2EventNotificationTargetConfiguration targetConfiguration ,
96
+ boolean isEnabled ) {
97
+ this (name , eventTypes , objectNamePrefix , targetConfiguration , isEnabled , null , null );
105
98
}
106
99
107
100
public String getName () {
@@ -116,7 +109,7 @@ public String getObjectNamePrefix() {
116
109
return objectNamePrefix ;
117
110
}
118
111
119
- public B2EventNotificationTargetConfigurationForResponse getTargetConfiguration () {
112
+ public B2EventNotificationTargetConfiguration getTargetConfiguration () {
120
113
return targetConfiguration ;
121
114
}
122
115
@@ -136,13 +129,13 @@ public String getSuspensionReason() {
136
129
public boolean equals (Object o ) {
137
130
if (this == o ) return true ;
138
131
if (o == null || getClass () != o .getClass ()) return false ;
139
- final B2EventNotificationRuleForResponse that = (B2EventNotificationRuleForResponse ) o ;
132
+ final B2EventNotificationRule that = (B2EventNotificationRule ) o ;
140
133
return isEnabled == that .isEnabled &&
141
- isSuspended == that .isSuspended &&
142
134
name .equals (that .name ) &&
143
135
eventTypes .equals (that .eventTypes ) &&
144
136
objectNamePrefix .equals (that .objectNamePrefix ) &&
145
137
targetConfiguration .equals (that .targetConfiguration ) &&
138
+ Objects .equals (isSuspended , that .isSuspended ) &&
146
139
Objects .equals (suspensionReason , that .suspensionReason );
147
140
}
148
141
@@ -161,7 +154,7 @@ public int hashCode() {
161
154
162
155
@ Override
163
156
public String toString () {
164
- return "B2EventNotificationRuleForResponse {" +
157
+ return "B2EventNotificationRule {" +
165
158
"name='" + name + '\'' +
166
159
", eventTypes=" + eventTypes +
167
160
", objectNamePrefix='" + objectNamePrefix + '\'' +
@@ -176,7 +169,7 @@ public String toString() {
176
169
* Rules are sorted by name first, and then additional attributes if necessary.
177
170
*/
178
171
@ Override
179
- public int compareTo (B2EventNotificationRuleForResponse r ) {
172
+ public int compareTo (B2EventNotificationRule r ) {
180
173
return COMPARATOR .compare (this , r );
181
174
}
182
175
}
0 commit comments