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/14 10:34:30 UTC

[14/18] james-project git commit: MAILBOX-359 Separate toScala methods in a separate object

MAILBOX-359 Separate toScala methods in a separate object


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/58375321
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/58375321
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/58375321

Branch: refs/heads/master
Commit: 58375321855f5bb97e871d9c40c8febfa54c23c8
Parents: 9e47d6e
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Dec 13 13:04:34 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 14 17:13:32 2018 +0700

----------------------------------------------------------------------
 .../james/event/json/EventSerializer.scala      | 51 +++++++++++---------
 1 file changed, 27 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/58375321/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 9e4c182..3248713 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
@@ -69,6 +69,32 @@ 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),
+    time = event.getInstant)
+
+  private def toScala(event: JavaMailboxAdded): DTO.MailboxAdded = DTO.MailboxAdded(
+    mailboxPath = DTO.MailboxPath.fromJava(event.getMailboxPath),
+    mailboxId = event.getMailboxId,
+    user = event.getUser,
+    sessionId = event.getSessionId)
+
+  def toScala(javaEvent: JavaEvent): Event = javaEvent match {
+    case e: JavaQuotaUsageUpdatedEvent => toScala(e)
+    case e: JavaMailboxAdded => toScala(e)
+    case _ => throw new RuntimeException("no Scala convertion known")
+  }
+}
+
 private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
   implicit val userWriters: Writes[User] = (user: User) => JsString(user.asString)
   implicit val quotaRootWrites: Writes[QuotaRoot] = quotaRoot => JsString(quotaRoot.getValue)
@@ -133,30 +159,7 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
 }
 
 class EventSerializer(mailboxIdFactory: MailboxId.Factory) {
-
-  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),
-      time = event.getInstant)
-
-  private def toScala(event: JavaMailboxAdded): DTO.MailboxAdded = DTO.MailboxAdded(
-      mailboxPath = DTO.MailboxPath.fromJava(event.getMailboxPath),
-      mailboxId = event.getMailboxId,
-      user = event.getUser,
-      sessionId = event.getSessionId)
-
-  def toJson(event: JavaEvent): String = event match {
-    case e: JavaQuotaUsageUpdatedEvent => new JsonSerialize(mailboxIdFactory).toJson(toScala(e))
-    case e: JavaMailboxAdded => new JsonSerialize(mailboxIdFactory).toJson(toScala(e))
-    case _ => throw new RuntimeException("no encoder found")
-  }
+  def toJson(event: JavaEvent): String = new JsonSerialize(mailboxIdFactory).toJson(ScalaConverter.toScala(event))
 
   def fromJson(json: String): JsResult[JavaEvent] = {
     new JsonSerialize(mailboxIdFactory)


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