chibenwa commented on a change in pull request #711:
URL: https://github.com/apache/james-project/pull/711#discussion_r735584155



##########
File path: 
server/data/data-jmap/src/main/scala/org/apache/james/jmap/api/push_subscription/PushRequest.scala
##########
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.push_subscription
+
+import eu.timepit.refined.types.numeric.NonNegInt
+import org.apache.james.jmap.api.push_subscription
+import 
org.apache.james.jmap.api.push_subscription.PushUrgencyOption.PushUrgencyOption
+
+object PushUrgencyOption extends Enumeration {
+  type PushUrgencyOption = Value
+  val LOW, VERY_LOW, NORMAL, HIGH = Value
+
+  val default: push_subscription.PushUrgencyOption.Value = NORMAL
+}
+
+case class Topic(value: String)

Review comment:
       extend AnyVal
   
   Also we may want to check some stuff with refined: 
https://datatracker.ietf.org/doc/html/rfc8030#section-5.4
   
   ```
   For use with this protocol, the Topic header field MUST be restricted
      to no more than 32 characters from the URL and a filename-safe Base
      64 alphabet [RFC4648].
   ```

##########
File path: 
server/data/data-jmap/src/main/scala/org/apache/james/jmap/api/push_subscription/WebPushClient.scala
##########
@@ -0,0 +1,99 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.push_subscription
+
+import eu.timepit.refined
+import eu.timepit.refined.api.Refined
+import eu.timepit.refined.string.Url
+import io.netty.buffer.Unpooled
+import 
org.apache.james.jmap.api.push_subscription.DefaultWebPushClient.buildHttpClient
+import org.apache.james.jmap.api.push_subscription.PushServerURL.PushServerURL
+import 
org.apache.james.jmap.api.push_subscription.WebPushClientHeader.{DEFAULT_TIMEOUT,
 MESSAGE_URGENCY, TIME_TO_LIVE, TOPIC}
+import org.reactivestreams.Publisher
+import reactor.core.scala.publisher.SMono
+import reactor.netty.http.client.HttpClient
+import reactor.netty.resources.ConnectionProvider
+
+import java.time.Duration
+import java.time.temporal.ChronoUnit
+
+trait WebPushClient {
+  def push(pushServerUrl: PushServerURL, request: PushRequest): Publisher[Void]
+}
+
+case class PushClientConfiguration(maxTimeoutSeconds: Option[Int],
+                                   maxConnections: Option[Int],
+                                   maxRetryTimes: Option[Int],
+                                   requestPerSeconds: Option[Int],
+                                   scheduler: reactor.core.scheduler.Scheduler)
+
+object WebPushClientHeader {
+  val TIME_TO_LIVE: String = "TTL"
+  val MESSAGE_URGENCY: String = "Urgency"
+  val TOPIC: String = "Topic"
+  val DEFAULT_TIMEOUT: Duration = Duration.of(30, ChronoUnit.SECONDS)
+}
+
+object PushServerURL {
+  type PushServerURL = String Refined Url
+
+  def validate(string: String): Either[IllegalArgumentException, 
PushServerURL] =
+    refined.refineV[Url](string)
+      .left
+      .map(new IllegalArgumentException(_))
+}
+
+object DefaultWebPushClient {
+
+  def buildHttpClient(configuration: PushClientConfiguration): HttpClient = {

Review comment:
       private?

##########
File path: 
server/data/data-jmap/src/main/scala/org/apache/james/jmap/api/push_subscription/PushRequest.scala
##########
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.push_subscription
+
+import eu.timepit.refined.types.numeric.NonNegInt
+import org.apache.james.jmap.api.push_subscription
+import 
org.apache.james.jmap.api.push_subscription.PushUrgencyOption.PushUrgencyOption
+
+object PushUrgencyOption extends Enumeration {
+  type PushUrgencyOption = Value
+  val LOW, VERY_LOW, NORMAL, HIGH = Value
+
+  val default: push_subscription.PushUrgencyOption.Value = NORMAL
+}
+
+case class Topic(value: String)
+
+case class TTL(value: NonNegInt)

Review comment:
       https://datatracker.ietf.org/doc/html/rfc8030#section-5.2 
   
   We should be between 0 and 2^31. Can we refined check that too?

##########
File path: 
server/data/data-jmap/src/main/scala/org/apache/james/jmap/api/push_subscription/WebPushClient.scala
##########
@@ -0,0 +1,99 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.push_subscription
+
+import eu.timepit.refined
+import eu.timepit.refined.api.Refined
+import eu.timepit.refined.string.Url
+import io.netty.buffer.Unpooled
+import 
org.apache.james.jmap.api.push_subscription.DefaultWebPushClient.buildHttpClient
+import org.apache.james.jmap.api.push_subscription.PushServerURL.PushServerURL
+import 
org.apache.james.jmap.api.push_subscription.WebPushClientHeader.{DEFAULT_TIMEOUT,
 MESSAGE_URGENCY, TIME_TO_LIVE, TOPIC}
+import org.reactivestreams.Publisher
+import reactor.core.scala.publisher.SMono
+import reactor.netty.http.client.HttpClient
+import reactor.netty.resources.ConnectionProvider
+
+import java.time.Duration
+import java.time.temporal.ChronoUnit
+
+trait WebPushClient {
+  def push(pushServerUrl: PushServerURL, request: PushRequest): Publisher[Void]
+}
+
+case class PushClientConfiguration(maxTimeoutSeconds: Option[Int],
+                                   maxConnections: Option[Int],
+                                   maxRetryTimes: Option[Int],
+                                   requestPerSeconds: Option[Int],
+                                   scheduler: reactor.core.scheduler.Scheduler)
+
+object WebPushClientHeader {
+  val TIME_TO_LIVE: String = "TTL"
+  val MESSAGE_URGENCY: String = "Urgency"
+  val TOPIC: String = "Topic"
+  val DEFAULT_TIMEOUT: Duration = Duration.of(30, ChronoUnit.SECONDS)
+}
+
+object PushServerURL {
+  type PushServerURL = String Refined Url
+
+  def validate(string: String): Either[IllegalArgumentException, 
PushServerURL] =
+    refined.refineV[Url](string)
+      .left
+      .map(new IllegalArgumentException(_))
+}
+
+object DefaultWebPushClient {
+
+  def buildHttpClient(configuration: PushClientConfiguration): HttpClient = {
+    val connectionProviderBuilder: ConnectionProvider.Builder = 
ConnectionProvider.builder(DefaultWebPushClient.getClass.getName)
+    configuration.maxConnections.foreach(configValue => 
connectionProviderBuilder.maxConnections(configValue))
+    configuration.maxTimeoutSeconds.foreach(configValue => 
connectionProviderBuilder.pendingAcquireMaxCount(configValue))
+
+    val responseTimeout: Duration = configuration.maxTimeoutSeconds
+      .map(configValue => Duration.of(configValue, ChronoUnit.SECONDS))
+      .getOrElse(DEFAULT_TIMEOUT)
+
+    HttpClient.create(connectionProviderBuilder.build())
+      .responseTimeout(responseTimeout)
+      .headers(builder => {
+        builder.add("Content-Type", "text/plain;charset=utf8")

Review comment:
       https://jmap.io/spec-core.html#pushsubscription
   
   ```
   The POST request MUST have a content type of application/json and contain 
the UTF-8 JSON-encoded object as the body.
   ```

##########
File path: 
server/data/data-jmap/src/main/scala/org/apache/james/jmap/api/push_subscription/PushRequest.scala
##########
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.push_subscription
+
+import eu.timepit.refined.types.numeric.NonNegInt
+import org.apache.james.jmap.api.push_subscription
+import 
org.apache.james.jmap.api.push_subscription.PushUrgencyOption.PushUrgencyOption
+
+object PushUrgencyOption extends Enumeration {

Review comment:
       Use sealed trait + case object to be idiomatic:
   
   ```
   sealed trait Urgency {
      def value: String
   }
   
   case object Low extends Urgency {
      val value = "LOW"
   }
   Etc...
   ```

##########
File path: 
server/data/data-jmap/src/main/scala/org/apache/james/jmap/api/push_subscription/WebPushClient.scala
##########
@@ -0,0 +1,99 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.push_subscription
+
+import eu.timepit.refined
+import eu.timepit.refined.api.Refined
+import eu.timepit.refined.string.Url
+import io.netty.buffer.Unpooled
+import 
org.apache.james.jmap.api.push_subscription.DefaultWebPushClient.buildHttpClient
+import org.apache.james.jmap.api.push_subscription.PushServerURL.PushServerURL
+import 
org.apache.james.jmap.api.push_subscription.WebPushClientHeader.{DEFAULT_TIMEOUT,
 MESSAGE_URGENCY, TIME_TO_LIVE, TOPIC}
+import org.reactivestreams.Publisher
+import reactor.core.scala.publisher.SMono
+import reactor.netty.http.client.HttpClient
+import reactor.netty.resources.ConnectionProvider
+
+import java.time.Duration
+import java.time.temporal.ChronoUnit
+
+trait WebPushClient {
+  def push(pushServerUrl: PushServerURL, request: PushRequest): Publisher[Void]
+}
+
+case class PushClientConfiguration(maxTimeoutSeconds: Option[Int],
+                                   maxConnections: Option[Int],
+                                   maxRetryTimes: Option[Int],
+                                   requestPerSeconds: Option[Int],
+                                   scheduler: reactor.core.scheduler.Scheduler)
+
+object WebPushClientHeader {
+  val TIME_TO_LIVE: String = "TTL"
+  val MESSAGE_URGENCY: String = "Urgency"
+  val TOPIC: String = "Topic"
+  val DEFAULT_TIMEOUT: Duration = Duration.of(30, ChronoUnit.SECONDS)
+}
+
+object PushServerURL {
+  type PushServerURL = String Refined Url
+
+  def validate(string: String): Either[IllegalArgumentException, 
PushServerURL] =
+    refined.refineV[Url](string)
+      .left
+      .map(new IllegalArgumentException(_))
+}
+
+object DefaultWebPushClient {
+
+  def buildHttpClient(configuration: PushClientConfiguration): HttpClient = {
+    val connectionProviderBuilder: ConnectionProvider.Builder = 
ConnectionProvider.builder(DefaultWebPushClient.getClass.getName)
+    configuration.maxConnections.foreach(configValue => 
connectionProviderBuilder.maxConnections(configValue))
+    configuration.maxTimeoutSeconds.foreach(configValue => 
connectionProviderBuilder.pendingAcquireMaxCount(configValue))
+
+    val responseTimeout: Duration = configuration.maxTimeoutSeconds
+      .map(configValue => Duration.of(configValue, ChronoUnit.SECONDS))
+      .getOrElse(DEFAULT_TIMEOUT)
+
+    HttpClient.create(connectionProviderBuilder.build())
+      .responseTimeout(responseTimeout)
+      .headers(builder => {
+        builder.add("Content-Type", "text/plain;charset=utf8")
+      })
+  }
+}
+
+class DefaultWebPushClient(configuration: PushClientConfiguration) extends 
WebPushClient {
+
+  val httpClient: HttpClient = buildHttpClient(configuration)
+
+  override def push(pushServerUrl: PushServerURL, request: PushRequest): 
Publisher[Void] = {
+    this.httpClient.baseUrl(pushServerUrl.toString)

Review comment:
       ```suggestion
       httpClient.baseUrl(pushServerUrl.toString)
   ```
   
   Uneeded this qualifier?

##########
File path: 
server/data/data-jmap/src/main/scala/org/apache/james/jmap/api/push_subscription/WebPushClient.scala
##########
@@ -0,0 +1,99 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.push_subscription
+
+import eu.timepit.refined
+import eu.timepit.refined.api.Refined
+import eu.timepit.refined.string.Url
+import io.netty.buffer.Unpooled
+import 
org.apache.james.jmap.api.push_subscription.DefaultWebPushClient.buildHttpClient
+import org.apache.james.jmap.api.push_subscription.PushServerURL.PushServerURL
+import 
org.apache.james.jmap.api.push_subscription.WebPushClientHeader.{DEFAULT_TIMEOUT,
 MESSAGE_URGENCY, TIME_TO_LIVE, TOPIC}
+import org.reactivestreams.Publisher
+import reactor.core.scala.publisher.SMono
+import reactor.netty.http.client.HttpClient
+import reactor.netty.resources.ConnectionProvider
+
+import java.time.Duration
+import java.time.temporal.ChronoUnit
+
+trait WebPushClient {
+  def push(pushServerUrl: PushServerURL, request: PushRequest): Publisher[Void]
+}
+
+case class PushClientConfiguration(maxTimeoutSeconds: Option[Int],
+                                   maxConnections: Option[Int],
+                                   maxRetryTimes: Option[Int],
+                                   requestPerSeconds: Option[Int],
+                                   scheduler: reactor.core.scheduler.Scheduler)
+
+object WebPushClientHeader {
+  val TIME_TO_LIVE: String = "TTL"
+  val MESSAGE_URGENCY: String = "Urgency"
+  val TOPIC: String = "Topic"
+  val DEFAULT_TIMEOUT: Duration = Duration.of(30, ChronoUnit.SECONDS)
+}
+
+object PushServerURL {
+  type PushServerURL = String Refined Url
+
+  def validate(string: String): Either[IllegalArgumentException, 
PushServerURL] =
+    refined.refineV[Url](string)
+      .left
+      .map(new IllegalArgumentException(_))
+}
+
+object DefaultWebPushClient {
+
+  def buildHttpClient(configuration: PushClientConfiguration): HttpClient = {
+    val connectionProviderBuilder: ConnectionProvider.Builder = 
ConnectionProvider.builder(DefaultWebPushClient.getClass.getName)
+    configuration.maxConnections.foreach(configValue => 
connectionProviderBuilder.maxConnections(configValue))
+    configuration.maxTimeoutSeconds.foreach(configValue => 
connectionProviderBuilder.pendingAcquireMaxCount(configValue))
+
+    val responseTimeout: Duration = configuration.maxTimeoutSeconds
+      .map(configValue => Duration.of(configValue, ChronoUnit.SECONDS))
+      .getOrElse(DEFAULT_TIMEOUT)
+
+    HttpClient.create(connectionProviderBuilder.build())
+      .responseTimeout(responseTimeout)
+      .headers(builder => {
+        builder.add("Content-Type", "text/plain;charset=utf8")
+      })
+  }
+}
+
+class DefaultWebPushClient(configuration: PushClientConfiguration) extends 
WebPushClient {
+
+  val httpClient: HttpClient = buildHttpClient(configuration)
+
+  override def push(pushServerUrl: PushServerURL, request: PushRequest): 
Publisher[Void] = {

Review comment:
       Uneeded `{}` spotted

##########
File path: 
server/data/data-jmap/src/test/scala/org.apache.james.jmap/api.push_subscription/PushServerExtension.scala
##########
@@ -0,0 +1,24 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.push_subscription
+
+class PushServerExtension {

Review comment:
       What is this used for?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to