You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2020/09/04 03:02:52 UTC
[james-project] 02/04: JAMES-3362 add a vararg constructor for
Properties
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit affcd7e0c684ce11ff7472c277cb891daac29fcc
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Sep 3 15:16:41 2020 +0700
JAMES-3362 add a vararg constructor for Properties
---
.../scala/org/apache/james/jmap/mail/Mailbox.scala | 10 +++++-----
.../org/apache/james/jmap/mail/MailboxSet.scala | 6 +++---
.../apache/james/jmap/mail/VacationResponse.scala | 5 ++---
.../james/jmap/method/MailboxSetMethod.scala | 22 +++++++++++-----------
.../org/apache/james/jmap/model/Properties.scala | 4 +++-
.../jmap/json/MailboxGetSerializationTest.scala | 4 ++--
.../VacationResponseGetSerializationTest.scala | 4 ++--
7 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
index c8eacb5..28b094c 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
@@ -147,12 +147,12 @@ case class Mailbox(id: MailboxId,
}
object Mailbox {
- val allProperties: Properties = Properties(Set("id", "name", "parentId", "role", "sortOrder", "totalEmails", "unreadEmails",
- "totalThreads", "unreadThreads", "myRights", "isSubscribed", "namespace", "rights", "quotas"))
- val idProperty: Properties = Properties(Set("id"))
+ val allProperties: Properties = Properties("id", "name", "parentId", "role", "sortOrder", "totalEmails", "unreadEmails",
+ "totalThreads", "unreadThreads", "myRights", "isSubscribed", "namespace", "rights", "quotas")
+ val idProperty: Properties = Properties("id")
val propertiesForCapabilities: Map[CapabilityIdentifier, Properties] = Map(
- CapabilityIdentifier.JAMES_QUOTA -> Properties(Set("quotas")),
- CapabilityIdentifier.JAMES_SHARES -> Properties(Set("namespace", "rights")))
+ CapabilityIdentifier.JAMES_QUOTA -> Properties("quotas"),
+ CapabilityIdentifier.JAMES_SHARES -> Properties("namespace", "rights"))
def propertiesFiltered(requestedProperties: Properties, allowedCapabilities : Set[CapabilityIdentifier]) : Properties = {
val propertiesToHide: Properties = propertiesForCapabilities.filterNot(entry => allowedCapabilities.contains(entry._1))
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
index a1f293b..1b330ca 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
@@ -240,10 +240,10 @@ object MailboxSetError {
}
object MailboxCreationResponse {
- val allProperties: Properties = Properties(Set("id", "sortOrder", "role", "totalEmails", "unreadEmails",
- "totalThreads", "unreadThreads", "myRights", "isSubscribed", "quotas"))
+ val allProperties: Properties = Properties("id", "sortOrder", "role", "totalEmails", "unreadEmails",
+ "totalThreads", "unreadThreads", "myRights", "isSubscribed", "quotas")
val propertiesForCapabilities: Map[CapabilityIdentifier, Properties] = Map(
- CapabilityIdentifier.JAMES_QUOTA -> Properties(Set("quotas")))
+ CapabilityIdentifier.JAMES_QUOTA -> Properties("quotas"))
def propertiesFiltered(allowedCapabilities : Set[CapabilityIdentifier]) : Properties = {
val propertiesToHide = propertiesForCapabilities.filterNot(entry => allowedCapabilities.contains(entry._1))
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/VacationResponse.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/VacationResponse.scala
index 4955c39..6220484 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/VacationResponse.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/VacationResponse.scala
@@ -23,7 +23,6 @@ import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.collection.NonEmpty
import org.apache.james.jmap.api.vacation.Vacation
-import org.apache.james.jmap.mail.Mailbox.idProperty
import org.apache.james.jmap.model.Id.Id
import org.apache.james.jmap.model.{Properties, UTCDate}
@@ -53,8 +52,8 @@ object VacationResponse {
htmlBody = vacation.getHtmlBody.asScala.map(HtmlBody)
)
- val allProperties: Properties = Properties(Set("id", "isEnabled", "fromDate", "toDate", "subject", "textBody", "htmlBody"))
- val idProperty: Properties = Properties(Set("id"))
+ val allProperties: Properties = Properties("id", "isEnabled", "fromDate", "toDate", "subject", "textBody", "htmlBody")
+ val idProperty: Properties = Properties("id")
def propertiesFiltered(requestedProperties: Properties) : Properties = idProperty ++ requestedProperties
}
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
index 2c1dcb0..729b8d1 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
@@ -53,11 +53,11 @@ sealed trait CreationResult {
case class CreationSuccess(mailboxCreationId: MailboxCreationId, mailboxCreationResponse: MailboxCreationResponse) extends CreationResult
case class CreationFailure(mailboxCreationId: MailboxCreationId, exception: Exception) extends CreationResult {
def asMailboxSetError: SetError = exception match {
- case e: MailboxNotFoundException => SetError.invalidArguments(SetErrorDescription(e.getMessage), Some(Properties(Set("parentId"))))
- case e: MailboxExistsException => SetError.invalidArguments(SetErrorDescription(e.getMessage), Some(Properties(Set("name"))))
- case e: MailboxNameException => SetError.invalidArguments(SetErrorDescription(e.getMessage), Some(Properties(Set("name"))))
+ case e: MailboxNotFoundException => SetError.invalidArguments(SetErrorDescription(e.getMessage), Some(Properties("parentId")))
+ case e: MailboxExistsException => SetError.invalidArguments(SetErrorDescription(e.getMessage), Some(Properties("name")))
+ case e: MailboxNameException => SetError.invalidArguments(SetErrorDescription(e.getMessage), Some(Properties("name")))
case e: MailboxCreationParseException => e.setError
- case _: InsufficientRightsException => SetError.forbidden(SetErrorDescription("Insufficient rights"), Properties(Set("parentId")))
+ case _: InsufficientRightsException => SetError.forbidden(SetErrorDescription("Insufficient rights"), Properties("parentId"))
case _ => SetError.serverFail(SetErrorDescription(exception.getMessage))
}
}
@@ -114,16 +114,16 @@ case class UpdateFailure(mailboxId: UnparsedMailboxId, exception: Throwable, pat
def asMailboxSetError: SetError = exception match {
case e: MailboxNotFoundException => SetError.notFound(SetErrorDescription(e.getMessage))
- case e: MailboxNameException => SetError.invalidArguments(SetErrorDescription(e.getMessage), filter(Properties(Set("name", "parentId"))))
- case e: MailboxExistsException => SetError.invalidArguments(SetErrorDescription(e.getMessage), filter(Properties(Set("name", "parentId"))))
- case e: UnsupportedPropertyUpdatedException => SetError.invalidArguments(SetErrorDescription(s"${e.property} property do not exist thus cannot be updated"), Some(Properties(Set(e.property))))
- case e: InvalidUpdateException => SetError.invalidArguments(SetErrorDescription(s"${e.cause}"), Some(Properties(Set(e.property))))
- case e: ServerSetPropertyException => SetError.invalidArguments(SetErrorDescription("Can not modify server-set properties"), Some(Properties(Set(e.property))))
+ case e: MailboxNameException => SetError.invalidArguments(SetErrorDescription(e.getMessage), filter(Properties("name", "parentId")))
+ case e: MailboxExistsException => SetError.invalidArguments(SetErrorDescription(e.getMessage), filter(Properties("name", "parentId")))
+ case e: UnsupportedPropertyUpdatedException => SetError.invalidArguments(SetErrorDescription(s"${e.property} property do not exist thus cannot be updated"), Some(Properties(e.property)))
+ case e: InvalidUpdateException => SetError.invalidArguments(SetErrorDescription(s"${e.cause}"), Some(Properties(e.property)))
+ case e: ServerSetPropertyException => SetError.invalidArguments(SetErrorDescription("Can not modify server-set properties"), Some(Properties(e.property)))
case e: InvalidPropertyException => SetError.invalidPatch(SetErrorDescription(s"${e.cause}"))
case e: InvalidPatchException => SetError.invalidPatch(SetErrorDescription(s"${e.cause}"))
- case e: SystemMailboxChangeException => SetError.invalidArguments(SetErrorDescription("Invalid change to a system mailbox"), filter(Properties(Set("name", "parentId"))))
+ case e: SystemMailboxChangeException => SetError.invalidArguments(SetErrorDescription("Invalid change to a system mailbox"), filter(Properties("name", "parentId")))
case e: InsufficientRightsException => SetError.invalidArguments(SetErrorDescription("Invalid change to a delegated mailbox"))
- case e: MailboxHasChildException => SetError.invalidArguments(SetErrorDescription(s"${e.mailboxId.serialize()} parentId property cannot be updated as this mailbox has child mailboxes"), Some(Properties(Set("parentId"))))
+ case e: MailboxHasChildException => SetError.invalidArguments(SetErrorDescription(s"${e.mailboxId.serialize()} parentId property cannot be updated as this mailbox has child mailboxes"), Some(Properties("parentId")))
case _ => SetError.serverFail(SetErrorDescription(exception.getMessage))
}
}
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Properties.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Properties.scala
index cbbdf6d..1827630 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Properties.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Properties.scala
@@ -25,7 +25,9 @@ import eu.timepit.refined.types.string.NonEmptyString
import play.api.libs.json.JsObject
object Properties {
- def empty(): Properties = Properties(Set())
+ def empty(): Properties = Properties()
+
+ def apply(values: NonEmptyString*): Properties = Properties(values.toSet)
}
case class Properties(value: Set[NonEmptyString]) {
diff --git a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
index 0506280..ae971e9 100644
--- a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
+++ b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
@@ -42,7 +42,7 @@ object MailboxGetSerializationTest {
private val MAILBOX_ID_1: UnparsedMailboxId = "1"
private val MAILBOX_ID_2: UnparsedMailboxId = "2"
- private val PROPERTIES: Properties = Properties(Set("name", "role"))
+ private val PROPERTIES: Properties = Properties("name", "role")
}
class MailboxGetSerializationTest extends AnyWordSpec with Matchers {
@@ -98,7 +98,7 @@ class MailboxGetSerializationTest extends AnyWordSpec with Matchers {
val expectedRequestObject = MailboxGetRequest(
accountId = ACCOUNT_ID,
ids = Some(Ids(List(MAILBOX_ID_1))),
- properties = Some(Properties(Set())))
+ properties = Some(Properties.empty()))
SERIALIZER.deserializeMailboxGetRequest(
"""
diff --git a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/VacationResponseGetSerializationTest.scala b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/VacationResponseGetSerializationTest.scala
index d1f3271..fc53679 100644
--- a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/VacationResponseGetSerializationTest.scala
+++ b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/VacationResponseGetSerializationTest.scala
@@ -39,7 +39,7 @@ object VacationResponseGetSerializationTest {
private val ACCOUNT_ID: AccountId = AccountId(id)
private val SINGLETON_ID: UnparsedVacationResponseId = "singleton"
- private val PROPERTIES: Properties = Properties(Set("isEnabled", "fromDate"))
+ private val PROPERTIES: Properties = Properties("isEnabled", "fromDate")
}
class VacationResponseGetSerializationTest extends AnyWordSpec with Matchers {
@@ -94,7 +94,7 @@ class VacationResponseGetSerializationTest extends AnyWordSpec with Matchers {
val expectedRequestObject = VacationResponseGetRequest(
accountId = ACCOUNT_ID,
ids = Some(VacationResponseIds(List(SINGLETON_ID))),
- properties = Some(Properties(Set())))
+ properties = Some(Properties.empty()))
SERIALIZER.deserializeVacationResponseGetRequest(
"""
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org