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:34 UTC
[08/13] james-project git commit: MAILBOX-362 Alphabetically order
EventSerializer.scala
MAILBOX-362 Alphabetically order EventSerializer.scala
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e25c2472
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e25c2472
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e25c2472
Branch: refs/heads/master
Commit: e25c24720979ac665cb6d41475454a296ca77092
Parents: 2d5abee
Author: datph <dp...@linagora.com>
Authored: Tue Dec 18 11:18:06 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:56:44 2018 +0700
----------------------------------------------------------------------
.../james/event/json/EventSerializer.scala | 83 ++++++++++----------
1 file changed, 41 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/e25c2472/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 7dcffbc..5a14668 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
@@ -37,20 +37,14 @@ private sealed trait Event {
}
private object DTO {
-
- 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)
+ case class MailboxACLUpdated(sessionId: SessionId, user: User, mailboxPath: MailboxPath, aclDiff: ACLDiff, mailboxId: MailboxId) extends Event {
+ override def toJava: JavaEvent = new JavaMailboxACLUpdated(sessionId, user, mailboxPath.toJava, aclDiff.toJava, mailboxId)
}
case class MailboxAdded(mailboxPath: MailboxPath, mailboxId: MailboxId, user: User, sessionId: SessionId) extends Event {
override def toJava: JavaEvent = new JavaMailboxAdded(sessionId, user, mailboxPath.toJava, mailboxId)
}
- case class MailboxRenamed(sessionId: SessionId, user: User, path: MailboxPath, mailboxId: MailboxId, newPath: MailboxPath) extends Event {
- override def toJava: JavaEvent = new JavaMailboxRenamed(sessionId, user, path.toJava, mailboxId, newPath.toJava)
- }
-
case class MailboxDeletion(sessionId: SessionId, user: User, path: MailboxPath, quotaRoot: QuotaRoot,
deletedMessageCount: QuotaCount, totalDeletedSize: QuotaSize, mailboxId: MailboxId) extends Event {
override def toJava: JavaEvent = new JavaMailboxDeletion(sessionId, user, path.toJava, quotaRoot, deletedMessageCount,
@@ -58,18 +52,23 @@ private object DTO {
mailboxId)
}
- case class MailboxACLUpdated(sessionId: SessionId, user: User, mailboxPath: MailboxPath, aclDiff: ACLDiff, mailboxId: MailboxId) extends Event {
- override def toJava: JavaEvent = new JavaMailboxACLUpdated(sessionId, user, mailboxPath.toJava, aclDiff.toJava, mailboxId)
+ case class MailboxRenamed(sessionId: SessionId, user: User, path: MailboxPath, mailboxId: MailboxId, newPath: MailboxPath) extends Event {
+ override def toJava: JavaEvent = new JavaMailboxRenamed(sessionId, user, path.toJava, mailboxId, newPath.toJava)
+ }
+
+ 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)
}
}
private object ScalaConverter {
- private def toScala(event: JavaQuotaUsageUpdatedEvent): DTO.QuotaUsageUpdatedEvent = DTO.QuotaUsageUpdatedEvent(
+ private def toScala(event: JavaMailboxACLUpdated): DTO.MailboxACLUpdated = DTO.MailboxACLUpdated(
+ sessionId = event.getSessionId,
user = event.getUser,
- quotaRoot = event.getQuotaRoot,
- countQuota = Quota.toScala(event.getCountQuota),
- sizeQuota = Quota.toScala(event.getSizeQuota),
- time = event.getInstant)
+ mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
+ aclDiff = ACLDiff.fromJava(event.getAclDiff),
+ mailboxId = event.getMailboxId)
private def toScala(event: JavaMailboxAdded): DTO.MailboxAdded = DTO.MailboxAdded(
mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
@@ -77,13 +76,6 @@ private object ScalaConverter {
user = event.getUser,
sessionId = event.getSessionId)
- private def toScala(event: JavaMailboxRenamed): DTO.MailboxRenamed = DTO.MailboxRenamed(
- sessionId = event.getSessionId,
- user = event.getUser,
- path = MailboxPath.fromJava(event.getMailboxPath),
- mailboxId = event.getMailboxId,
- newPath = MailboxPath.fromJava(event.getNewPath))
-
private def toScala(event: JavaMailboxDeletion): DTO.MailboxDeletion = DTO.MailboxDeletion(
sessionId = event.getSessionId,
user = event.getUser,
@@ -93,19 +85,26 @@ private object ScalaConverter {
totalDeletedSize = event.getTotalDeletedSize,
mailboxId = event.getMailboxId)
- private def toScala(event: JavaMailboxACLUpdated): DTO.MailboxACLUpdated = DTO.MailboxACLUpdated(
+ private def toScala(event: JavaMailboxRenamed): DTO.MailboxRenamed = DTO.MailboxRenamed(
sessionId = event.getSessionId,
user = event.getUser,
- mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
- aclDiff = ACLDiff.fromJava(event.getAclDiff),
- mailboxId = event.getMailboxId)
+ path = MailboxPath.fromJava(event.getMailboxPath),
+ mailboxId = event.getMailboxId,
+ newPath = MailboxPath.fromJava(event.getNewPath))
+
+ private def toScala(event: JavaQuotaUsageUpdatedEvent): DTO.QuotaUsageUpdatedEvent = DTO.QuotaUsageUpdatedEvent(
+ user = event.getUser,
+ quotaRoot = event.getQuotaRoot,
+ countQuota = Quota.toScala(event.getCountQuota),
+ sizeQuota = Quota.toScala(event.getSizeQuota),
+ time = event.getInstant)
def toScala(javaEvent: JavaEvent): Event = javaEvent match {
- case e: JavaQuotaUsageUpdatedEvent => toScala(e)
+ case e: JavaMailboxACLUpdated => toScala(e)
case e: JavaMailboxAdded => toScala(e)
- case e: JavaMailboxRenamed => toScala(e)
case e: JavaMailboxDeletion => toScala(e)
- case e: JavaMailboxACLUpdated => toScala(e)
+ case e: JavaMailboxRenamed => toScala(e)
+ case e: JavaQuotaUsageUpdatedEvent => toScala(e)
case _ => throw new RuntimeException("no Scala convertion known")
}
}
@@ -132,25 +131,21 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
case JsString(rightsAsString) => JsSuccess(JavaMailboxACL.Rfc4314Rights.deserialize(rightsAsString))
case _ => JsError()
}
- implicit val userReads: Reads[User] = {
- case JsString(userAsString) => JsSuccess(User.fromUsername(userAsString))
- case _ => JsError()
- }
implicit val mailboxIdReads: Reads[MailboxId] = {
case JsString(serializedMailboxId) => JsSuccess(mailboxIdFactory.fromString(serializedMailboxId))
case _ => JsError()
}
- implicit val sessionIdReads: Reads[SessionId] = {
- case JsNumber(id) => JsSuccess(SessionId.of(id.longValue()))
+ implicit val quotaCountReads: Reads[QuotaCount] = {
+ case JsNumber(count) => JsSuccess(QuotaCount.count(count.toLong))
+ case JsNull => JsSuccess(QuotaCount.unlimited())
case _ => JsError()
}
implicit val quotaRootReads: Reads[QuotaRoot] = {
case JsString(quotaRoot) => JsSuccess(QuotaRoot.quotaRoot(quotaRoot, Optional.empty[Domain]))
case _ => JsError()
}
- implicit val quotaCountReads: Reads[QuotaCount] = {
- case JsNumber(count) => JsSuccess(QuotaCount.count(count.toLong))
- case JsNull => JsSuccess(QuotaCount.unlimited())
+ implicit val quotaScopeReads: Reads[JavaQuota.Scope] = {
+ case JsString(value) => JsSuccess(JavaQuota.Scope.valueOf(value))
case _ => JsError()
}
implicit val quotaSizeReads: Reads[QuotaSize] = {
@@ -158,8 +153,12 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
case JsNull => JsSuccess(QuotaSize.unlimited())
case _ => JsError()
}
- implicit val quotaScopeReads: Reads[JavaQuota.Scope] = {
- case JsString(value) => JsSuccess(JavaQuota.Scope.valueOf(value))
+ implicit val sessionIdReads: Reads[SessionId] = {
+ case JsNumber(id) => JsSuccess(SessionId.of(id.longValue()))
+ case _ => JsError()
+ }
+ implicit val userReads: Reads[User] = {
+ case JsString(userAsString) => JsSuccess(User.fromUsername(userAsString))
case _ => JsError()
}
@@ -183,10 +182,10 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
JsObject(m.map { case (k, v) => (k.toString, vr.writes(v)) }.toSeq)
}
+ implicit val aclDiffReads: Reads[ACLDiff] = Json.reads[ACLDiff]
+ implicit val mailboxPathReads: Reads[MailboxPath] = Json.reads[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 aclDiffReads: Reads[ACLDiff] = Json.reads[ACLDiff]
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