Skip to content

Commit

Permalink
Move JMAPExtensionConfiguration into its own module
Browse files Browse the repository at this point in the history
- Because it does not belong to the API module, but we want to share it with other modules that need it e.g. cassandra-jmap-extensions
  • Loading branch information
HoussemNasri committed Dec 1, 2024
1 parent 3c39b47 commit 7a5c52a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 30 deletions.
19 changes: 19 additions & 0 deletions tmail-backend/jmap/extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@
<artifactId>jmap-extensions-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jmap-extensions-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jmap-extensions-configuration</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jmap-extensions-configuration</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.linagora.tmail.james.jmap.json

import com.linagora.tmail.james.jmap.LanguageLocation
import com.linagora.tmail.james.jmap.model.CalendarEventParse.UnparsedBlobId
import com.linagora.tmail.james.jmap.model.{CalendarEventNotDone, CalendarEventNotFound, CalendarEventReplyAcceptedResponse, CalendarEventReplyMaybeResponse, CalendarEventReplyRejectedResponse, CalendarEventReplyRequest, CalendarEventReplyResponse, LanguageLocation}
import com.linagora.tmail.james.jmap.model.{CalendarEventNotDone, CalendarEventNotFound, CalendarEventReplyAcceptedResponse, CalendarEventReplyMaybeResponse, CalendarEventReplyRejectedResponse, CalendarEventReplyRequest, CalendarEventReplyResponse}
import org.apache.james.jmap.core.SetError
import org.apache.james.jmap.json.mapWrites
import org.apache.james.jmap.mail.{BlobId, BlobIds}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CalendarEventReplyPerformer @Inject()(blobCalendarResolver: BlobCalendarRe
})

private def getLanguageLocale(request: CalendarEventReplyRequest): Locale =
request.language.map(_.language).getOrElse(CalendarEventReplySupportedLanguage.LANGUAGE_DEFAULT)
request.language.map(_.language).getOrElse(JMAPExtensionConfiguration.CALENDAR_LANGUAGE_DEFAULT)
}

class BlobCalendarResolver @Inject()(blobResolvers: BlobResolvers) {
Expand All @@ -128,14 +128,10 @@ class BlobCalendarResolver @Inject()(blobResolvers: BlobResolvers) {
}
}

object CalendarEventReplySupportedLanguage {
val LANGUAGE_DEFAULT: Locale = Locale.ENGLISH
}

class CalendarEventReplySupportedLanguage @Inject()(jmapExtensionConfiguration: JMAPExtensionConfiguration) {

private val supportedLanguages: Set[Locale] = jmapExtensionConfiguration.calendarEventReplySupportedLanguagesConfig.supportedLanguages match {
case supportedLanguages if supportedLanguages.isEmpty => Set(CalendarEventReplySupportedLanguage.LANGUAGE_DEFAULT)
case supportedLanguages if supportedLanguages.isEmpty => JMAPExtensionConfiguration.CALENDAR_SUPPORTED_LANGUAGES_DEFAULT
case supportedLanguages => supportedLanguages
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.linagora.tmail.james.jmap.model

import java.util.Locale

import com.linagora.tmail.james.jmap.LanguageLocation
import com.linagora.tmail.james.jmap.method.CalendarEventReplyPerformer.LOGGER
import com.linagora.tmail.james.jmap.model.CalendarEventParse.UnparsedBlobId
import com.linagora.tmail.james.jmap.model.CalendarEventReplyRequest.MAXIMUM_NUMBER_OF_BLOB_IDS
Expand All @@ -11,23 +10,6 @@ import org.apache.james.jmap.mail.{BlobId, BlobIds, RequestTooLargeException}
import org.apache.james.jmap.method.WithAccountId
import org.apache.james.mailbox.MailboxSession

import scala.util.Try

object LanguageLocation {
def fromString(languageCode: String): Try[LanguageLocation] = detectLocale(languageCode).map(LanguageLocation.apply)

def detectLocale(languageCode: String): Try[Locale] =
if (Locale.getISOLanguages.contains(languageCode)) {
Try(Locale.forLanguageTag(languageCode))
} else {
throw new IllegalArgumentException("The language must be a valid ISO language code")
}
}

case class LanguageLocation(language: Locale) {
def value: String = language.toLanguageTag
}

object CalendarEventReplyRequest {
val MAXIMUM_NUMBER_OF_BLOB_IDS: Int = 16
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.linagora.tmail.james.jmap.json

import com.linagora.tmail.james.jmap.LanguageLocation
import com.linagora.tmail.james.jmap.json.{CalendarEventReplySerializer => testee}
import com.linagora.tmail.james.jmap.model.{CalendarEventNotDone, CalendarEventNotFound, CalendarEventReplyAcceptedResponse, CalendarEventReplyRequest, LanguageLocation}
import com.linagora.tmail.james.jmap.model.{CalendarEventNotDone, CalendarEventNotFound, CalendarEventReplyAcceptedResponse, CalendarEventReplyRequest}
import eu.timepit.refined.auto._
import org.apache.james.core.Username
import org.apache.james.jmap.core.SetError.SetErrorDescription
Expand Down
43 changes: 43 additions & 0 deletions tmail-backend/jmap/jmap-extensions-configuration/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.linagora.tmail</groupId>
<artifactId>tmail-backend</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>jmap-extensions-configuration</artifactId>
<name>Twake Mail :: JMAP :: Extensions :: Configuration</name>

<dependencies>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-jmap-rfc-8621</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-data-jmap</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-configuration</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.github.evis</groupId>
<artifactId>scalafix-maven-plugin_2.13</artifactId>
<configuration>
<config>${project.parent.parent.basedir}/.scalafix.conf</config>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import java.time.temporal.ChronoUnit
import java.util.Locale

import com.linagora.tmail.james.jmap.JMAPExtensionConfiguration.{CALENDAR_EVENT_REPLY_SUPPORTED_LANGUAGES_DEFAULT, PUBLIC_ASSET_TOTAL_SIZE_LIMIT_DEFAULT, TICKET_IP_VALIDATION_ENABLED}
import com.linagora.tmail.james.jmap.method.CalendarEventReplySupportedLanguage.LANGUAGE_DEFAULT
import com.linagora.tmail.james.jmap.model.LanguageLocation
import eu.timepit.refined
import org.apache.commons.configuration2.Configuration
import org.apache.james.core.MailAddress
Expand All @@ -22,8 +20,10 @@ object JMAPExtensionConfiguration {
val PUBLIC_ASSET_TOTAL_SIZE_LIMIT_DEFAULT: PublicAssetTotalSizeLimit = PublicAssetTotalSizeLimit.of(Size.of(20L, Size.Unit.M)).get
val TICKET_IP_VALIDATION_PROPERTY: String = "authentication.strategy.rfc8621.tickets.ip.validation.enabled"
val TICKET_IP_VALIDATION_ENABLED: TicketIpValidationEnable = TicketIpValidationEnable(true)
val CALENDAR_LANGUAGE_DEFAULT: Locale = Locale.ENGLISH
val CALENDAR_SUPPORTED_LANGUAGES_DEFAULT: Set[Locale] = Set(CALENDAR_LANGUAGE_DEFAULT)
val CALENDAR_EVENT_REPLY_SUPPORTED_LANGUAGES_PROPERTY: String = "calendarEvent.reply.supportedLanguages"
val CALENDAR_EVENT_REPLY_SUPPORTED_LANGUAGES_DEFAULT: CalendarEventReplySupportedLanguagesConfig = CalendarEventReplySupportedLanguagesConfig(Set(LANGUAGE_DEFAULT))
val CALENDAR_EVENT_REPLY_SUPPORTED_LANGUAGES_DEFAULT: CalendarEventReplySupportedLanguagesConfig = CalendarEventReplySupportedLanguagesConfig(CALENDAR_SUPPORTED_LANGUAGES_DEFAULT)

val SUPPORT_MAIL_ADDRESS_PROPERTY: String = "support.mail.address"

Expand Down Expand Up @@ -84,6 +84,21 @@ case class JMAPExtensionConfiguration(publicAssetTotalSizeLimit: PublicAssetTota
}
}

object LanguageLocation {
def fromString(languageCode: String): Try[LanguageLocation] = detectLocale(languageCode).map(LanguageLocation.apply)

def detectLocale(languageCode: String): Try[Locale] =
if (Locale.getISOLanguages.contains(languageCode)) {
Try(Locale.forLanguageTag(languageCode))
} else {
throw new IllegalArgumentException("The language must be a valid ISO language code")
}
}

case class LanguageLocation(language: Locale) {
def value: String = language.toLanguageTag
}

case class PublicAssetTotalSizeLimit(value: UnsignedInt) {
def asLong(): Long = value.value
}
Expand Down

0 comments on commit 7a5c52a

Please sign in to comment.