You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/10/25 04:04:03 UTC

[GitHub] [james-project] Arsnael commented on a change in pull request #707: JAMES-3539 Implement inmemory PushSubscriptionRepository and contract tests

Arsnael commented on a change in pull request #707:
URL: https://github.com/apache/james-project/pull/707#discussion_r735240005



##########
File path: server/data/data-jmap/src/main/java/org/apache/james/jmap/api/pushsubscription/PushSubscriptionRepository.java
##########
@@ -0,0 +1,56 @@
+/******************************************************************
+ * 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.pushsubscription;
+
+import java.time.Clock;
+import java.time.ZonedDateTime;
+import java.util.Set;
+
+import org.apache.james.core.Username;
+import org.apache.james.jmap.change.TypeName;
+import org.apache.james.jmap.core.ExpireTimeInvalidException;
+import org.apache.james.jmap.core.PushSubscription;
+import org.apache.james.jmap.core.PushSubscriptionCreationRequest;
+import org.apache.james.jmap.core.PushSubscriptionId;
+import org.reactivestreams.Publisher;
+
+public interface PushSubscriptionRepository {
+    Publisher<PushSubscriptionId> save(Username username, PushSubscriptionCreationRequest pushSubscriptionCreationRequest);
+
+    Publisher<Void> updateExpireTime(Username username, PushSubscriptionId id, ZonedDateTime newExpire);
+
+    Publisher<Void> updateTypes(Username username, PushSubscriptionId id, Set<TypeName> types);
+
+    Publisher<Void> revoke(Username username, PushSubscriptionId id);
+
+    Publisher<PushSubscription> get(Username username, Set<PushSubscriptionId> ids);
+
+    Publisher<PushSubscription> list(Username username);
+
+    Publisher<Void> validateVerificationCode(Username username, PushSubscriptionId id);
+
+    default void expireTimePreconditions(ZonedDateTime dateTime, Clock clock) {
+        if (!PushSubscription.invalidExpireTime(dateTime, clock)) {
+            throw new ExpireTimeInvalidException(dateTime,
+                String.format("expires must be greater than now and smaller than %s days",
+                    PushSubscription.EXPIRES_TIME_MAX_DAY()));

Review comment:
       This is Java code here though?

##########
File path: server/data/data-jmap/src/main/java/org/apache/james/jmap/api/pushsubscription/PushSubscriptionRepository.java
##########
@@ -0,0 +1,56 @@
+/******************************************************************
+ * 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.pushsubscription;
+
+import java.time.Clock;
+import java.time.ZonedDateTime;
+import java.util.Set;
+
+import org.apache.james.core.Username;
+import org.apache.james.jmap.change.TypeName;
+import org.apache.james.jmap.core.ExpireTimeInvalidException;
+import org.apache.james.jmap.core.PushSubscription;
+import org.apache.james.jmap.core.PushSubscriptionCreationRequest;
+import org.apache.james.jmap.core.PushSubscriptionId;
+import org.reactivestreams.Publisher;
+
+public interface PushSubscriptionRepository {
+    Publisher<PushSubscriptionId> save(Username username, PushSubscriptionCreationRequest pushSubscriptionCreationRequest);
+
+    Publisher<Void> updateExpireTime(Username username, PushSubscriptionId id, ZonedDateTime newExpire);
+
+    Publisher<Void> updateTypes(Username username, PushSubscriptionId id, Set<TypeName> types);
+
+    Publisher<Void> revoke(Username username, PushSubscriptionId id);
+
+    Publisher<PushSubscription> get(Username username, Set<PushSubscriptionId> ids);
+
+    Publisher<PushSubscription> list(Username username);
+
+    Publisher<Void> validateVerificationCode(Username username, PushSubscriptionId id);
+
+    default void expireTimePreconditions(ZonedDateTime dateTime, Clock clock) {
+        if (!PushSubscription.invalidExpireTime(dateTime, clock)) {
+            throw new ExpireTimeInvalidException(dateTime,
+                String.format("expires must be greater than now and smaller than %s days",
+                    PushSubscription.EXPIRES_TIME_MAX_DAY()));

Review comment:
       You should not throw an exception when expires is bigger than max allowed. You should put it to max allowed in that case. You only throw when expires < now

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/PushSubscription.scala
##########
@@ -42,6 +47,32 @@ case class PushSubscriptionCreationRequest(deviceClientId: DeviceClientId,
                                            expires: Option[PushSubscriptionExpiredTime],
                                            types: Seq[TypeName])
 
+object PushSubscription {
+  val DEFAULT_VALIDATED: Boolean = false
+  val EXPIRES_TIME_MAX_DAY: Int = 7
+
+  def from(creationRequest: PushSubscriptionCreationRequest,
+           id: PushSubscriptionId,
+           expireTime: ZonedDateTime,
+           verificationCode: VerificationCode): PushSubscription =
+    PushSubscription(id = id,
+      deviceClientId = creationRequest.deviceClientId,
+      url = creationRequest.url,
+      keys = creationRequest.keys,
+      verificationCode = verificationCode,
+      validated = DEFAULT_VALIDATED,
+      expires = PushSubscriptionExpiredTime(expireTime),
+      types = creationRequest.types)
+
+  def invalidExpireTime(time: ZonedDateTime, clock: Clock): Boolean = {
+    val now: ZonedDateTime = ZonedDateTime.now(clock)
+    time.isAfter(now) && time.isBefore(now.plusDays(EXPIRES_TIME_MAX_DAY))

Review comment:
       That doesn't mean it's invalid... If I understand your code correctly guys, this means you throw when expires is bigger than max days... while it should not throw and set expires to max days in that case




-- 
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: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org