1717
1818import static com .google .common .base .Preconditions .checkNotNull ;
1919
20+ import com .google .api .pathtemplate .PathTemplate ;
2021import com .google .api .services .storage .model .Notification ;
2122import com .google .common .base .Function ;
2223import com .google .common .base .MoreObjects ;
2324import com .google .common .collect .ImmutableList ;
2425import com .google .common .collect .ImmutableMap ;
25- import com .google .pubsub .v1 .ProjectTopicName ;
2626import java .io .Serializable ;
2727import java .util .List ;
2828import java .util .Map ;
3737public 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 ());
0 commit comments