Skip to content

Commit 0bd17b1

Browse files
athakorsydney-munrogcf-owl-bot[bot]
authored
feat: expose the methods of Notifications (#399)
* feat: expose bucket notifications apis See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Sydney Munro <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent e45ae07 commit 0bd17b1

16 files changed

+1167
-7
lines changed

google-cloud-storage/clirr-ignored-differences.xml

+25
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,29 @@
1111
<method>BucketInfo$LifecycleRule$LifecycleAction()</method>
1212
<differenceType>7004</differenceType>
1313
</difference>
14+
<difference>
15+
<className>com/google/cloud/storage/Storage</className>
16+
<method>*.Notification createNotification(*.String, *.NotificationInfo)</method>
17+
<differenceType>7012</differenceType>
18+
</difference>
19+
<difference>
20+
<className>com/google/cloud/storage/Storage</className>
21+
<method>*.Notification getNotification(*.String, *.String)</method>
22+
<differenceType>7012</differenceType>
23+
</difference>
24+
<difference>
25+
<className>com/google/cloud/storage/Storage</className>
26+
<method>java.util.List listNotifications(*.String)</method>
27+
<differenceType>7012</differenceType>
28+
</difference>
29+
<difference>
30+
<className>com/google/cloud/storage/Storage</className>
31+
<method>boolean deleteNotification(*.String, *.String)</method>
32+
<differenceType>7012</differenceType>
33+
</difference>
34+
<difference>
35+
<className>com/google/cloud/storage/spi/v1/StorageRpc</className>
36+
<method>*.model.Notification getNotification(*.String, *.String)</method>
37+
<differenceType>7012</differenceType>
38+
</difference>
1439
</differences>

google-cloud-storage/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@
147147
<artifactId>truth</artifactId>
148148
<scope>test</scope>
149149
</dependency>
150+
<dependency>
151+
<groupId>com.google.cloud</groupId>
152+
<artifactId>google-cloud-pubsub</artifactId>
153+
<scope>test</scope>
154+
</dependency>
150155
<dependency>
151156
<groupId>org.easymock</groupId>
152157
<artifactId>easymock</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.storage;
17+
18+
import static com.google.common.base.Preconditions.checkNotNull;
19+
20+
import java.util.Map;
21+
import java.util.Objects;
22+
23+
/**
24+
* The class representing Pub/Sub notifications for the Storage. See <a
25+
* href="https://cloud.google.com/storage/docs/pubsub-notifications">pubsub-notifications</a> for
26+
* details.
27+
*/
28+
public class Notification extends NotificationInfo {
29+
30+
private final StorageOptions options;
31+
private transient Storage storage;
32+
33+
/** Builder for {@code Notification}. */
34+
public static class Builder extends NotificationInfo.Builder {
35+
private final Storage storage;
36+
private final NotificationInfo.BuilderImpl infoBuilder;
37+
38+
Builder(Notification notification) {
39+
this.storage = notification.storage;
40+
this.infoBuilder = new NotificationInfo.BuilderImpl(notification);
41+
}
42+
43+
@Override
44+
Builder setNotificationId(String notificationId) {
45+
infoBuilder.setNotificationId(notificationId);
46+
return this;
47+
}
48+
49+
@Override
50+
public Builder setSelfLink(String selfLink) {
51+
infoBuilder.setSelfLink(selfLink);
52+
return this;
53+
}
54+
55+
@Override
56+
public Builder setTopic(String topic) {
57+
infoBuilder.setTopic(topic);
58+
return this;
59+
}
60+
61+
@Override
62+
public Builder setPayloadFormat(PayloadFormat payloadFormat) {
63+
infoBuilder.setPayloadFormat(payloadFormat);
64+
return this;
65+
}
66+
67+
@Override
68+
public Builder setObjectNamePrefix(String objectNamePrefix) {
69+
infoBuilder.setObjectNamePrefix(objectNamePrefix);
70+
return this;
71+
}
72+
73+
@Override
74+
public Builder setEventTypes(EventType... eventTypes) {
75+
infoBuilder.setEventTypes(eventTypes);
76+
return this;
77+
}
78+
79+
@Override
80+
public Builder setEtag(String etag) {
81+
infoBuilder.setEtag(etag);
82+
return this;
83+
}
84+
85+
@Override
86+
public Builder setCustomAttributes(Map<String, String> customAttributes) {
87+
infoBuilder.setCustomAttributes(customAttributes);
88+
return this;
89+
}
90+
91+
@Override
92+
public Notification build() {
93+
return new Notification(storage, infoBuilder);
94+
}
95+
}
96+
97+
Notification(Storage storage, NotificationInfo.BuilderImpl infoBuilder) {
98+
super(infoBuilder);
99+
this.storage = checkNotNull(storage);
100+
this.options = storage.getOptions();
101+
}
102+
103+
/** Returns the notification's {@code Storage} object used to issue requests. */
104+
public Storage getStorage() {
105+
return storage;
106+
}
107+
108+
@Override
109+
public Builder toBuilder() {
110+
return new Notification.Builder(this);
111+
}
112+
113+
@Override
114+
public boolean equals(Object o) {
115+
if (this == o) {
116+
return true;
117+
}
118+
if (o == null || getClass() != o.getClass()) {
119+
return false;
120+
}
121+
if (!super.equals(o)) {
122+
return false;
123+
}
124+
Notification notification = (Notification) o;
125+
return Objects.equals(toPb(), notification.toPb())
126+
&& Objects.equals(options, notification.options);
127+
}
128+
129+
@Override
130+
public int hashCode() {
131+
return Objects.hash(super.hashCode(), options, storage);
132+
}
133+
134+
static Notification fromPb(
135+
Storage storage, com.google.api.services.storage.model.Notification notificationPb) {
136+
return new Notification(
137+
storage, new NotificationInfo.BuilderImpl(NotificationInfo.fromPb(notificationPb)));
138+
}
139+
}

0 commit comments

Comments
 (0)