You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/12/19 04:10:32 UTC
[06/13] james-project git commit: MAILBOX-362 Group all non event
DTOs to DTOs scala file
MAILBOX-362 Group all non event DTOs to DTOs scala file
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8eaf1f64
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8eaf1f64
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8eaf1f64
Branch: refs/heads/master
Commit: 8eaf1f6416ffd1432c98f53857b5a9147f1840de
Parents: 892f95a
Author: datph <dp...@linagora.com>
Authored: Tue Dec 18 11:07:23 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:53 2018 +0700
----------------------------------------------------------------------
.../org/apache/james/event/json/DTOs.scala | 54 ++++++++++++++++++++
.../james/event/json/EventSerializer.scala | 54 +++++---------------
2 files changed, 68 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/8eaf1f64/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
new file mode 100644
index 0000000..8d8af9e
--- /dev/null
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
@@ -0,0 +1,54 @@
+/****************************************************************
+ * 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.event.json
+
+import org.apache.james.core.quota.QuotaValue
+import org.apache.james.mailbox.model.{MailboxPath => JavaMailboxPath, Quota => JavaQuota}
+
+import scala.collection.JavaConverters._
+
+object DTOs {
+ object MailboxPath {
+ def fromJava(javaMailboxPath: JavaMailboxPath): MailboxPath = MailboxPath(
+ Option(javaMailboxPath.getNamespace),
+ Option(javaMailboxPath.getUser),
+ javaMailboxPath.getName)
+ }
+
+ object Quota {
+ def toScala[T <: QuotaValue[T]](java: JavaQuota[T]): Quota[T] = Quota(
+ used = java.getUsed,
+ limit = java.getLimit,
+ limits = java.getLimitByScope.asScala.toMap)
+ }
+
+ case class MailboxPath(namespace: Option[String], user: Option[String], name: String) {
+ def toJava: JavaMailboxPath = new JavaMailboxPath(namespace.orNull, user.orNull, name)
+ }
+
+ case class Quota[T <: QuotaValue[T]](used: T, limit: T, limits: Map[JavaQuota.Scope, T]) {
+ def toJava: JavaQuota[T] =
+ JavaQuota.builder[T]
+ .used(used)
+ .computedLimit(limit)
+ .limitsByScope(limits.asJava)
+ .build()
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8eaf1f64/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index 9c89b58..544859b 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -25,40 +25,19 @@ import java.util.Optional
import julienrf.json.derived
import org.apache.james.core.quota.{QuotaCount, QuotaSize, QuotaValue}
import org.apache.james.core.{Domain, User}
+import org.apache.james.event.json.DTOs.{MailboxPath, Quota}
import org.apache.james.mailbox.MailboxListener.{MailboxAdded => JavaMailboxAdded, MailboxDeletion => JavaMailboxDeletion, MailboxRenamed => JavaMailboxRenamed, QuotaUsageUpdatedEvent => JavaQuotaUsageUpdatedEvent}
import org.apache.james.mailbox.MailboxSession.SessionId
-import org.apache.james.mailbox.model.{MailboxId, QuotaRoot, MailboxPath => JavaMailboxPath, Quota => JavaQuota}
+import org.apache.james.mailbox.model.{MailboxId, QuotaRoot, Quota => JavaQuota}
import org.apache.james.mailbox.{Event => JavaEvent}
import play.api.libs.json.{JsError, JsNull, JsNumber, JsObject, JsResult, JsString, JsSuccess, Json, OFormat, Reads, Writes}
-import scala.collection.JavaConverters._
-
private sealed trait Event {
def toJava: JavaEvent
}
private object DTO {
- object MailboxPath {
- def fromJava(javaMailboxPath: JavaMailboxPath): MailboxPath = DTO.MailboxPath(
- Option(javaMailboxPath.getNamespace),
- Option(javaMailboxPath.getUser),
- javaMailboxPath.getName)
- }
-
- case class MailboxPath(namespace: Option[String], user: Option[String], name: String) {
- def toJava: JavaMailboxPath = new JavaMailboxPath(namespace.orNull, user.orNull, name)
- }
-
- case class Quota[T <: QuotaValue[T]](used: T, limit: T, limits: Map[JavaQuota.Scope, T]) {
- def toJava: JavaQuota[T] =
- JavaQuota.builder[T]
- .used(used)
- .computedLimit(limit)
- .limitsByScope(limits.asJava)
- .build()
- }
-
case class QuotaUsageUpdatedEvent(user: User, quotaRoot: QuotaRoot, countQuota: Quota[QuotaCount],
sizeQuota: Quota[QuotaSize], time: Instant) extends Event {
override def toJava: JavaEvent = new JavaQuotaUsageUpdatedEvent(user, quotaRoot, countQuota.toJava, sizeQuota.toJava, time)
@@ -81,20 +60,15 @@ private object DTO {
}
private object ScalaConverter {
- private def toScala[T <: QuotaValue[T]](java: JavaQuota[T]): DTO.Quota[T] = DTO.Quota(
- used = java.getUsed,
- limit = java.getLimit,
- limits = java.getLimitByScope.asScala.toMap)
-
private def toScala(event: JavaQuotaUsageUpdatedEvent): DTO.QuotaUsageUpdatedEvent = DTO.QuotaUsageUpdatedEvent(
user = event.getUser,
quotaRoot = event.getQuotaRoot,
- countQuota = toScala(event.getCountQuota),
- sizeQuota = toScala(event.getSizeQuota),
+ countQuota = Quota.toScala(event.getCountQuota),
+ sizeQuota = Quota.toScala(event.getSizeQuota),
time = event.getInstant)
private def toScala(event: JavaMailboxAdded): DTO.MailboxAdded = DTO.MailboxAdded(
- mailboxPath = DTO.MailboxPath.fromJava(event.getMailboxPath),
+ mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
mailboxId = event.getMailboxId,
user = event.getUser,
sessionId = event.getSessionId)
@@ -102,15 +76,15 @@ private object ScalaConverter {
private def toScala(event: JavaMailboxRenamed): DTO.MailboxRenamed = DTO.MailboxRenamed(
sessionId = event.getSessionId,
user = event.getUser,
- path = DTO.MailboxPath.fromJava(event.getMailboxPath),
+ path = MailboxPath.fromJava(event.getMailboxPath),
mailboxId = event.getMailboxId,
- newPath = DTO.MailboxPath.fromJava(event.getNewPath))
+ newPath = MailboxPath.fromJava(event.getNewPath))
private def toScala(event: JavaMailboxDeletion): DTO.MailboxDeletion = DTO.MailboxDeletion(
sessionId = event.getSessionId,
user = event.getUser,
quotaRoot = event.getQuotaRoot,
- path = DTO.MailboxPath.fromJava(event.getMailboxPath),
+ path = MailboxPath.fromJava(event.getMailboxPath),
deletedMessageCount = event.getDeletedMessageCount,
totalDeletedSize = event.getTotalDeletedSize,
mailboxId = event.getMailboxId)
@@ -129,9 +103,9 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
implicit val quotaRootWrites: Writes[QuotaRoot] = quotaRoot => JsString(quotaRoot.getValue)
implicit val quotaValueWrites: Writes[QuotaValue[_]] = value => if (value.isUnlimited) JsNull else JsNumber(value.asLong())
implicit val quotaScopeWrites: Writes[JavaQuota.Scope] = value => JsString(value.name)
- implicit val quotaCountWrites: Writes[DTO.Quota[QuotaCount]] = Json.writes[DTO.Quota[QuotaCount]]
- implicit val quotaSizeWrites: Writes[DTO.Quota[QuotaSize]] = Json.writes[DTO.Quota[QuotaSize]]
- implicit val mailboxPathWrites: Writes[DTO.MailboxPath] = Json.writes[DTO.MailboxPath]
+ implicit val quotaCountWrites: Writes[Quota[QuotaCount]] = Json.writes[Quota[QuotaCount]]
+ implicit val quotaSizeWrites: Writes[Quota[QuotaSize]] = Json.writes[Quota[QuotaSize]]
+ implicit val mailboxPathWrites: Writes[MailboxPath] = Json.writes[MailboxPath]
implicit val mailboxIdWrites: Writes[MailboxId] = value => JsString(value.serialize())
implicit val sessionIdWrites: Writes[SessionId] = value => JsNumber(value.getValue)
@@ -176,9 +150,9 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
JsObject(m.map { case (k, v) => (k.toString, vr.writes(v)) }.toSeq)
}
- implicit val quotaCReads: Reads[DTO.Quota[QuotaCount]] = Json.reads[DTO.Quota[QuotaCount]]
- implicit val quotaSReads: Reads[DTO.Quota[QuotaSize]] = Json.reads[DTO.Quota[QuotaSize]]
- implicit val mailboxPathReads: Reads[DTO.MailboxPath] = Json.reads[DTO.MailboxPath]
+ implicit val quotaCReads: Reads[Quota[QuotaCount]] = Json.reads[Quota[QuotaCount]]
+ implicit val quotaSReads: Reads[Quota[QuotaSize]] = Json.reads[Quota[QuotaSize]]
+ implicit val mailboxPathReads: Reads[MailboxPath] = Json.reads[MailboxPath]
implicit val eventOFormat: OFormat[Event] = derived.oformat()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org