Repository: firebase/firebase-admin-java
Pull request #295 (2019-08-01 17:40:40)

Add missing WebpushFcmOptions entity (as per documentation)
WebpushFcmOptions is described in [documentation](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushfcmoptions) but is not included in Java client.

Corresponding issue - #294


googlebot: 
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed (or fixed any issues), please reply here with `@googlebot I signed it!`) and we'll verify it.

----

#### What to do if you already signed the CLA

##### Individual signers

*   It's possible we don't have your GitHub username or you're using a different email address on your commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).

##### Corporate signers

*   Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to [go/cla#troubleshoot](http://go/cla#troubleshoot) ([Public version](https://opensource.google.com/docs/cla/#troubleshoot)).
*   The email used to register you as an authorized contributor must be the email used for the Git commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
*   The email used to register you as an authorized contributor must also be [attached to your GitHub account](https://github.com/settings/emails).
		

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Ffirebase%2Ffirebase-admin-java%2Fpull%2F295) for more info**.

<!-- need_sender_cla -->
kirmerzlikin: @googlebot I signed it!
googlebot: CLAs look good, thanks!

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Ffirebase%2Ffirebase-admin-java%2Fpull%2F295) for more info**.

<!-- ok -->
googlebot: We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors.  If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA ([login here](https://cla.developers.google.com/) to double check)?  If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment `@googlebot I fixed it.`. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Ffirebase%2Ffirebase-admin-java%2Fpull%2F295) for more info**.

<!-- need_author_cla -->
googlebot: CLAs look good, thanks!

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Ffirebase%2Ffirebase-admin-java%2Fpull%2F295) for more info**.

<!-- ok -->
kirmerzlikin: @hiranya911 done
hiranya911: @egilmorez can you review the javadoc-related changes in this PR?

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca37dfd..d95bd8e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
 # Unreleased
 
--
+- [added] Added `WebpushFcmOptions` to the `FirebaseMessaging` API, providing 
+  the `setLink()` method.
 
 # v6.9.0
 
diff --git a/src/main/java/com/google/firebase/messaging/AndroidNotification.java b/src/main/java/com/google/firebase/messaging/AndroidNotification.java
index 0a6cd06..064f493 100644
--- a/src/main/java/com/google/firebase/messaging/AndroidNotification.java
+++ b/src/main/java/com/google/firebase/messaging/AndroidNotification.java
@@ -138,7 +138,7 @@ public class AndroidNotification {
     }
 
     /**
-     * Sets the body of the Android notification. When provided, overrides the body sent
+     * Sets the body of the Android notification. When provided, overrides the body set
      * via {@link Notification}.
      *
      * @param body Body of the notification.
diff --git a/src/main/java/com/google/firebase/messaging/WebpushConfig.java b/src/main/java/com/google/firebase/messaging/WebpushConfig.java
index 7c99580..9cde9d0 100644
--- a/src/main/java/com/google/firebase/messaging/WebpushConfig.java
+++ b/src/main/java/com/google/firebase/messaging/WebpushConfig.java
@@ -19,6 +19,7 @@ package com.google.firebase.messaging;
 import com.google.api.client.util.Key;
 import com.google.common.collect.ImmutableMap;
 import com.google.firebase.internal.NonNull;
+
 import java.util.HashMap;
 import java.util.Map;
 
@@ -37,10 +38,14 @@ public class WebpushConfig {
   @Key("notification")
   private final Map<String, Object> notification;
 
+  @Key("fcm_options")
+  private final WebpushFcmOptions fcmOptions;
+
   private WebpushConfig(Builder builder) {
     this.headers = builder.headers.isEmpty() ? null : ImmutableMap.copyOf(builder.headers);
     this.data = builder.data.isEmpty() ? null : ImmutableMap.copyOf(builder.data);
     this.notification = builder.notification != null ? builder.notification.getFields() : null;
+    this.fcmOptions = builder.fcmOptions;
   }
 
   /**
@@ -57,6 +62,8 @@ public class WebpushConfig {
     private final Map<String, String> headers = new HashMap<>();
     private final Map<String, String> data = new HashMap<>();
     private WebpushNotification notification;
+    private WebpushFcmOptions fcmOptions;
+
 
     private Builder() {}
 
@@ -125,6 +132,17 @@ public class WebpushConfig {
       return this;
     }
 
+    /**
+     * Sets the Webpush FCM options to be included in the Webpush config.
+     *
+     * @param fcmOptions A {@link WebpushFcmOptions} instance.
+     * @return This builder.
+     */
+    public Builder setFcmOptions(WebpushFcmOptions fcmOptions) {
+      this.fcmOptions = fcmOptions;
+      return this;
+    }
+
     /**
      * Creates a new {@link WebpushConfig} instance from the parameters set on this builder.
      *
diff --git a/src/main/java/com/google/firebase/messaging/WebpushFcmOptions.java b/src/main/java/com/google/firebase/messaging/WebpushFcmOptions.java
new file mode 100644
index 0000000..bef49ec
--- /dev/null
+++ b/src/main/java/com/google/firebase/messaging/WebpushFcmOptions.java
@@ -0,0 +1,62 @@
+package com.google.firebase.messaging;
+
+import com.google.api.client.util.Key;
+
+/**
+ * Represents options for features provided by the FCM SDK for Web.
+ * Can be included in {@link WebpushConfig}. Instances of this class are thread-safe and immutable.
+ */
+public final class WebpushFcmOptions {
+
+  @Key("link")
+  private final String link;
+
+  private WebpushFcmOptions(Builder builder) {
+    this.link = builder.link;
+  }
+
+  /**
+   * Creates a new {@code WebpushFcmOptions} using given link.
+   *
+   * @param link The link to open when the user clicks on the notification.
+   *             For all URL values, HTTPS is required.
+   */
+  public static WebpushFcmOptions withLink(String link) {
+    return new Builder().setLink(link).build();
+  }
+
+  /**
+   * Creates a new {@link WebpushFcmOptions.Builder}.
+   *
+   * @return An {@link WebpushFcmOptions.Builder} instance.
+   */
+  public static Builder builder() {
+    return new WebpushFcmOptions.Builder();
+  }
+
+  public static class Builder {
+
+    private String link;
+
+    private Builder() {}
+
+    /**
+     * @param link The link to open when the user clicks on the notification.
+     *             For all URL values, HTTPS is required.
+     * @return This builder
+     */
+    public Builder setLink(String link) {
+      this.link = link;
+      return this;
+    }
+
+    /**
+     * Creates a new {@link WebpushFcmOptions} instance from the parameters set on this builder.
+     *
+     * @return A new {@link WebpushFcmOptions} instance.
+     */
+    public WebpushFcmOptions build() {
+      return new WebpushFcmOptions(this);
+    }
+  }
+}


Test patch:
diff --git a/src/test/java/com/google/firebase/messaging/FirebaseMessagingClientImplTest.java b/src/test/java/com/google/firebase/messaging/FirebaseMessagingClientImplTest.java
index 87e9499..ae1136b 100644
--- a/src/test/java/com/google/firebase/messaging/FirebaseMessagingClientImplTest.java
+++ b/src/test/java/com/google/firebase/messaging/FirebaseMessagingClientImplTest.java
@@ -781,6 +781,7 @@ public class FirebaseMessagingClientImplTest {
                     .putCustomData("k4", "v4")
                     .putAllCustomData(ImmutableMap.<String, Object>of("k5", "v5", "k6", "v6"))
                     .build())
+                .setFcmOptions(WebpushFcmOptions.withLink("https://firebase.google.com"))
                 .build())
             .setTopic("test-topic")
             .build(),
@@ -811,7 +812,8 @@ public class FirebaseMessagingClientImplTest {
                     .put("k4", "v4")
                     .put("k5", "v5")
                     .put("k6", "v6")
-                    .build())
+                    .build(),
+                "fcm_options", ImmutableMap.of("link", "https://firebase.google.com"))
         ));
 
     return builder.build();
diff --git a/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java b/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java
index 9a2b3ff..751ba8b 100644
--- a/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java
+++ b/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java
@@ -59,6 +59,7 @@ public class FirebaseMessagingIT {
         .setWebpushConfig(WebpushConfig.builder()
             .putHeader("X-Custom-Val", "Foo")
             .setNotification(new WebpushNotification("Title", "Body"))
+            .setFcmOptions(WebpushFcmOptions.withLink("https://firebase.google.com"))
             .build())
         .setTopic("foo-bar")
         .build();
diff --git a/src/test/java/com/google/firebase/messaging/MessageTest.java b/src/test/java/com/google/firebase/messaging/MessageTest.java
index 5f555fe..6744a35 100644
--- a/src/test/java/com/google/firebase/messaging/MessageTest.java
+++ b/src/test/java/com/google/firebase/messaging/MessageTest.java
@@ -271,6 +271,26 @@ public class MessageTest {
     assertJsonEquals(ImmutableMap.of("topic", "test-topic", "webpush", data), message);
   }
 
+  @Test
+  public void testWebpushMessageWithWebpushOptions() throws IOException {
+    Message message = Message.builder()
+        .setWebpushConfig(WebpushConfig.builder()
+            .putHeader("k1", "v1")
+            .putAllHeaders(ImmutableMap.of("k2", "v2", "k3", "v3"))
+            .putData("k1", "v1")
+            .putAllData(ImmutableMap.of("k2", "v2", "k3", "v3"))
+            .setFcmOptions(WebpushFcmOptions.withLink("https://my-server/page"))
+            .build())
+        .setTopic("test-topic")
+        .build();
+    Map<String, Object> data = ImmutableMap.<String, Object>of(
+        "headers", ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"),
+        "data", ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"),
+        "fcm_options", ImmutableMap.of("link", "https://my-server/page")
+    );
+    assertJsonEquals(ImmutableMap.of("topic", "test-topic", "webpush", data), message);
+  }
+
   @Test
   public void testWebpushMessageWithNotification() throws IOException {
     Message message = Message.builder()
diff --git a/src/test/java/com/google/firebase/snippets/FirebaseMessagingSnippets.java b/src/test/java/com/google/firebase/snippets/FirebaseMessagingSnippets.java
index 7c46ad9..eb94021 100644
--- a/src/test/java/com/google/firebase/snippets/FirebaseMessagingSnippets.java
+++ b/src/test/java/com/google/firebase/snippets/FirebaseMessagingSnippets.java
@@ -30,6 +30,7 @@ import com.google.firebase.messaging.Notification;
 import com.google.firebase.messaging.SendResponse;
 import com.google.firebase.messaging.TopicManagementResponse;
 import com.google.firebase.messaging.WebpushConfig;
+import com.google.firebase.messaging.WebpushFcmOptions;
 import com.google.firebase.messaging.WebpushNotification;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -239,6 +240,7 @@ public class FirebaseMessagingSnippets {
                 "$GOOG up 1.43% on the day",
                 "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.",
                 "https://my-server/icon.png"))
+            .setFcmOptions(WebpushFcmOptions.withLink("https://my-server/page-to-open-on-click"))
             .build())
         .setTopic("industry-tech")
         .build();
@@ -310,4 +312,4 @@ public class FirebaseMessagingSnippets {
     // [END unsubscribe]
   }
 
-}
\ No newline at end of file
+}