Skip to content

Commit 302d627

Browse files
committed
feat: fix review changes
1 parent 96caf7b commit 302d627

6 files changed

Lines changed: 46 additions & 43 deletions

File tree

google-cloud-storage/pom.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@
8080
<groupId>com.google.protobuf</groupId>
8181
<artifactId>protobuf-java-util</artifactId>
8282
</dependency>
83-
<dependency>
84-
<groupId>com.google.cloud</groupId>
85-
<artifactId>google-cloud-pubsub</artifactId>
86-
</dependency>
87-
<dependency>
88-
<groupId>com.google.api.grpc</groupId>
89-
<artifactId>proto-google-cloud-pubsub-v1</artifactId>
90-
</dependency>
9183
<dependency>
9284
<groupId>org.threeten</groupId>
9385
<artifactId>threetenbp</artifactId>
@@ -159,6 +151,11 @@
159151
<artifactId>truth</artifactId>
160152
<scope>test</scope>
161153
</dependency>
154+
<dependency>
155+
<groupId>com.google.cloud</groupId>
156+
<artifactId>google-cloud-pubsub</artifactId>
157+
<scope>test</scope>
158+
</dependency>
162159
<dependency>
163160
<groupId>org.easymock</groupId>
164161
<artifactId>easymock</artifactId>

google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
import static com.google.common.base.Preconditions.checkNotNull;
1919

20+
import com.google.api.pathtemplate.PathTemplate;
2021
import com.google.api.services.storage.model.Notification;
2122
import com.google.common.base.Function;
2223
import com.google.common.base.MoreObjects;
2324
import com.google.common.collect.ImmutableList;
2425
import com.google.common.collect.ImmutableMap;
25-
import com.google.pubsub.v1.ProjectTopicName;
2626
import java.io.Serializable;
2727
import java.util.List;
2828
import java.util.Map;
@@ -37,6 +37,8 @@
3737
public class NotificationInfo implements Serializable {
3838

3939
private static final long serialVersionUID = 5725883368559753810L;
40+
private static final PathTemplate PATH_TEMPLATE =
41+
PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}");
4042

4143
public enum PayloadFormat {
4244
JSON_API_V1,
@@ -58,7 +60,7 @@ public Notification apply(NotificationInfo NotificationInfo) {
5860
}
5961
};
6062
private final String generatedId;
61-
private final ProjectTopicName topic;
63+
private final String topic;
6264
private final List<String> eventTypes;
6365
private final Map<String, String> customAttributes;
6466
private final PayloadFormat payloadFormat;
@@ -69,15 +71,15 @@ public Notification apply(NotificationInfo NotificationInfo) {
6971
public static final class Builder {
7072

7173
private String generatedId;
72-
private ProjectTopicName topic;
74+
private String topic;
7375
private List<String> eventTypes;
7476
private Map<String, String> customAttributes;
7577
private PayloadFormat payloadFormat;
7678
private String objectNamePrefix;
7779
private String etag;
7880
private String selfLink;
7981

80-
Builder(ProjectTopicName topic) {
82+
Builder(String topic) {
8183
this.topic = topic;
8284
}
8385

@@ -102,7 +104,8 @@ Builder setSelfLink(String selfLink) {
102104
return this;
103105
}
104106

105-
public Builder setTopic(ProjectTopicName topic) {
107+
/** The name of the topic. It must have the format "projects/{project}/topics/{topic}". */
108+
public Builder setTopic(String topic) {
106109
this.topic = topic;
107110
return this;
108111
}
@@ -155,8 +158,8 @@ public String getGeneratedId() {
155158
return generatedId;
156159
}
157160

158-
/** Returns the Cloud PubSub topic to which this subscription publishes. */
159-
public ProjectTopicName getTopic() {
161+
/** Returns the topic to which this subscription publishes. */
162+
public String getTopic() {
160163
return topic;
161164
}
162165

@@ -248,25 +251,35 @@ Notification toPb() {
248251
notificationPb.setPayloadFormat(PayloadFormat.NONE.toString());
249252
}
250253
notificationPb.setSelfLink(selfLink);
251-
notificationPb.setTopic(topic.toString());
254+
notificationPb.setTopic(topic);
252255

253256
return notificationPb;
254257
}
255258

256-
/** Creates a {@code NotificationInfo} object for the provided topic name. */
257-
public static NotificationInfo of(ProjectTopicName topic) {
259+
/**
260+
* Creates a {@code NotificationInfo} object for the provided topic name.
261+
*
262+
* @param topic The name of the topic. It must have the format
263+
* "projects/{project}/topics/{topic}".
264+
*/
265+
public static NotificationInfo of(String topic) {
266+
PATH_TEMPLATE.validatedMatch(topic, "topic name must be in valid format");
258267
return newBuilder(topic).build();
259268
}
260269

261270
/**
262271
* Returns a {@code NotificationInfo} builder where the topic's name is set to the provided name.
272+
*
273+
* @param topic The name of the topic. It must have the format
274+
* "projects/{project}/topics/{topic}".
263275
*/
264-
public static Builder newBuilder(ProjectTopicName topic) {
276+
public static Builder newBuilder(String topic) {
277+
PATH_TEMPLATE.validatedMatch(topic, "topic name must be in valid format");
265278
return new Builder(topic);
266279
}
267280

268281
static NotificationInfo fromPb(Notification notificationPb) {
269-
Builder builder = newBuilder(ProjectTopicName.parse(notificationPb.getTopic()));
282+
Builder builder = newBuilder(notificationPb.getTopic());
270283
if (notificationPb.getId() != null) {
271284
builder.setGeneratedId(notificationPb.getId());
272285
}
@@ -283,7 +296,7 @@ static NotificationInfo fromPb(Notification notificationPb) {
283296
builder.setObjectNamePrefix(notificationPb.getObjectNamePrefix());
284297
}
285298
if (notificationPb.getTopic() != null) {
286-
builder.setTopic(ProjectTopicName.parse(notificationPb.getTopic()));
299+
builder.setTopic(notificationPb.getTopic());
287300
}
288301
if (notificationPb.getEventTypes() != null) {
289302
builder.setEventTypes(notificationPb.getEventTypes());

google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.cloud.storage.NotificationInfo.PayloadFormat;
2222
import com.google.common.collect.ImmutableList;
2323
import com.google.common.collect.ImmutableMap;
24-
import com.google.pubsub.v1.ProjectTopicName;
2524
import java.util.List;
2625
import java.util.Map;
2726
import org.junit.Test;
@@ -35,7 +34,7 @@ public class NotificationInfoTest {
3534
ImmutableList.of("OBJECT_FINALIZE", "OBJECT_METADATA_UPDATE");
3635
private static final String OBJECT_NAME_PREFIX = "index.html";
3736
private static final PayloadFormat PAYLOAD_FORMAT = PayloadFormat.JSON_API_V1.JSON_API_V1;
38-
private static final ProjectTopicName TOPIC = ProjectTopicName.of("myProject", "topic1");
37+
private static final String TOPIC = "projects/myProject/topics/topic1";
3938
private static final Map<String, String> CUSTOM_ATTRIBUTES = ImmutableMap.of("label1", "value1");
4039
private static final NotificationInfo NOTIFICATION_INFO =
4140
NotificationInfo.newBuilder(TOPIC)

google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import com.google.common.collect.ImmutableMap;
5959
import com.google.common.collect.Iterables;
6060
import com.google.common.io.BaseEncoding;
61-
import com.google.pubsub.v1.ProjectTopicName;
6261
import java.io.ByteArrayInputStream;
6362
import java.io.IOException;
6463
import java.io.UnsupportedEncodingException;
@@ -385,7 +384,7 @@ public long millisTime() {
385384
private static final String OBJECT_NAME_PREFIX = "index.html";
386385
private static final NotificationInfo.PayloadFormat PAYLOAD_FORMAT =
387386
NotificationInfo.PayloadFormat.JSON_API_V1.JSON_API_V1;
388-
private static final ProjectTopicName TOPIC = ProjectTopicName.of("myProject", "topic1");
387+
private static final String TOPIC = "projects/myProject/topics/topic1";
389388
private static final Map<String, String> CUSTOM_ATTRIBUTES = ImmutableMap.of("label1", "value1");
390389
private static final NotificationInfo NOTIFICATION_INFO_01 =
391390
NotificationInfo.newBuilder(TOPIC)

google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
import com.google.iam.v1.Binding;
9494
import com.google.iam.v1.IAMPolicyGrpc;
9595
import com.google.iam.v1.SetIamPolicyRequest;
96-
import com.google.pubsub.v1.ProjectTopicName;
9796
import io.grpc.ManagedChannel;
9897
import io.grpc.ManagedChannelBuilder;
9998
import io.grpc.Metadata;
@@ -183,8 +182,9 @@ public class ITStorageTest {
183182
private static final String ID = UUID.randomUUID().toString().substring(0, 8);
184183
private static final NotificationInfo.PayloadFormat PAYLOAD_FORMAT =
185184
NotificationInfo.PayloadFormat.JSON_API_V1.JSON_API_V1;
186-
private static final ProjectTopicName TOPIC =
187-
ProjectTopicName.of(PROJECT, String.format("test_topic_foo_%s", ID));
185+
186+
private static final String TOPIC =
187+
String.format("projects/%s/topics/test_topic_foo_%s", PROJECT, ID);
188188
private static final Map<String, String> CUSTOM_ATTRIBUTES = ImmutableMap.of("label1", "value1");
189189

190190
@BeforeClass
@@ -208,11 +208,10 @@ public static void beforeClass() throws IOException {
208208
// Create pubsub topic for notification.
209209
topicAdminClient = TopicAdminClient.create();
210210
topicAdminClient.createTopic(TOPIC);
211-
com.google.iam.v1.Policy policy = topicAdminClient.getIamPolicy(TOPIC.toString());
211+
com.google.iam.v1.Policy policy = topicAdminClient.getIamPolicy(TOPIC);
212212
Binding binding =
213213
Binding.newBuilder().setRole("roles/owner").addMembers("allAuthenticatedUsers").build();
214-
topicAdminClient.setIamPolicy(
215-
TOPIC.toString(), policy.toBuilder().addBindings(binding).build());
214+
topicAdminClient.setIamPolicy(TOPIC, policy.toBuilder().addBindings(binding).build());
216215

217216
// Create a notification on a bucket.
218217
NotificationInfo notificationInfo =
@@ -3254,7 +3253,7 @@ public void testGetNotification() {
32543253
Notification actualNotification = storage.getNotification(BUCKET, notification.getId());
32553254
assertEquals(CUSTOM_ATTRIBUTES, actualNotification.getCustomAttributes());
32563255
assertEquals(PAYLOAD_FORMAT.name(), actualNotification.getPayloadFormat());
3257-
assertTrue(actualNotification.getTopic().contains(TOPIC.toString()));
3256+
assertTrue(actualNotification.getTopic().contains(TOPIC));
32583257
}
32593258

32603259
@Test
@@ -3264,7 +3263,7 @@ public void testListNotification() {
32643263
if (actualNotification.getId().equals(notification.getId())) {
32653264
assertEquals(CUSTOM_ATTRIBUTES, actualNotification.getCustomAttributes());
32663265
assertEquals(PAYLOAD_FORMAT.name(), actualNotification.getPayloadFormat());
3267-
assertTrue(actualNotification.getTopic().contains(TOPIC.toString()));
3266+
assertTrue(actualNotification.getTopic().contains(TOPIC));
32683267
}
32693268
}
32703269
}

pom.xml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,6 @@
151151
<artifactId>proto-google-common-protos</artifactId>
152152
<version>1.17.0</version>
153153
</dependency>
154-
<dependency>
155-
<groupId>com.google.cloud</groupId>
156-
<artifactId>google-cloud-pubsub</artifactId>
157-
<version>1.102.1</version>
158-
</dependency>
159-
<dependency>
160-
<groupId>com.google.api.grpc</groupId>
161-
<artifactId>proto-google-cloud-pubsub-v1</artifactId>
162-
<version>1.84.1</version>
163-
</dependency>
164154
<dependency>
165155
<groupId>org.threeten</groupId>
166156
<artifactId>threetenbp</artifactId>
@@ -194,6 +184,12 @@
194184
<version>1.0.1</version>
195185
<scope>test</scope>
196186
</dependency>
187+
<dependency>
188+
<groupId>com.google.cloud</groupId>
189+
<artifactId>google-cloud-pubsub</artifactId>
190+
<version>1.102.1</version>
191+
<scope>test</scope>
192+
</dependency>
197193
<dependency>
198194
<groupId>org.easymock</groupId>
199195
<artifactId>easymock</artifactId>

0 commit comments

Comments
 (0)