Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter versioning quan #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion james-project
Submodule james-project updated 17 files
+2 −2 Jenkinsfile
+3 −3 JenkinsfileStressTests.groovy
+4 −0 event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/History.scala
+147 −0 pom.xml
+1 −1 server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/FilteringManagement.java
+66 −0 server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/Rules.java
+59 −0 server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/Version.java
+6 −2 ...data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/EventSourcingFilteringManagement.java
+6 −2 server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java
+16 −11 server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/FilteringManagementContract.java
+32 −0 server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/RulesTest.java
+32 −0 server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/VersionTest.java
+2 −4 server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetFilterMethod.java
+4 −7 server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/mailet/filter/JMAPFiltering.java
+13 −0 ...egration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedMailboxSetMethodTest.java
+19 −14 ...integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
+1 −1 ...t/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQEventDeadLettersIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ trait LinagoraFilterGetMethodContract {
| "methodResponses": [[
| "Filter/get", {
| "accountId": "$generateAccountIdAsString",
| "state": "0",
| "list": [
| {
| "id": "singleton",
Expand Down Expand Up @@ -135,6 +136,7 @@ trait LinagoraFilterGetMethodContract {
| "methodResponses": [[
| "Filter/get", {
| "accountId": "$generateAccountIdAsString",
| "state": "-1",
| "list": [
| {
| "id": "singleton",
Expand Down Expand Up @@ -316,6 +318,7 @@ trait LinagoraFilterGetMethodContract {
| "methodResponses": [[
| "Filter/get", {
| "accountId": "$generateAccountIdAsString",
| "state": "0",
| "list": [
| {
| "id": "singleton",
Expand Down Expand Up @@ -384,6 +387,7 @@ trait LinagoraFilterGetMethodContract {
| "methodResponses": [[
| "Filter/get", {
| "accountId": "$generateAccountIdAsString",
| "state": "0",
| "list": [
| {
| "id": "singleton",
Expand Down Expand Up @@ -452,6 +456,7 @@ trait LinagoraFilterGetMethodContract {
| "methodResponses": [[
| "Filter/get", {
| "accountId": "$generateAccountIdAsString",
| "state": "0",
| "list": [
|
| ],
Expand Down Expand Up @@ -503,6 +508,7 @@ trait LinagoraFilterGetMethodContract {
| "methodResponses": [[
| "Filter/get", {
| "accountId": "$generateAccountIdAsString",
| "state": "0",
| "list": [],
| "notFound": []
| }, "c1"]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ trait LinagoraFilterSetMethodContract {
| [
| "Filter/get", {
| "accountId": "$generateAccountIdAsString",
| "state": "0",
| "list": [{
| "id": "singleton",
| "rules": [{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.linagora.openpaas.james.jmap.json

import com.linagora.openpaas.james.jmap.model.{Action, AppendIn, Comparator, Condition, Field, Filter, FilterGetIds, FilterGetNotFound, FilterGetRequest, FilterGetResponse, FilterSetError, FilterSetRequest, FilterSetResponse, FilterSetUpdateResponse, Rule, RuleWithId, Update}
import com.linagora.openpaas.james.jmap.model.{Action, AppendIn, Comparator, Condition, Field, Filter, FilterGetIds, FilterGetNotFound, FilterGetRequest, FilterGetResponse, FilterSetError, FilterSetRequest, FilterSetResponse, FilterSetUpdateResponse, FilterState, Rule, RuleWithId, Update}
import eu.timepit.refined.api.{RefType, Validate}
import org.apache.james.jmap.core.SetError.SetErrorDescription
import org.apache.james.jmap.core.{AccountId, State}
Expand Down Expand Up @@ -43,6 +43,7 @@ case class FilterSerializer @Inject()(mailboxIdFactory: MailboxId.Factory) {
implicit val ruleWrites: Writes[Rule] = Json.writes[Rule]
implicit val filterWrites: Writes[Filter] = Json.writes[Filter]
implicit val notFoundWrites: Writes[FilterGetNotFound] = Json.valueWrites[FilterGetNotFound]
implicit val filterState: Writes[FilterState] = Json.valueWrites[FilterState]
implicit val filterGetResponseAccountId: Writes[AccountId] = Json.valueWrites[AccountId]
implicit val filterGetResponseWrites: Writes[FilterGetResponse] = Json.writes[FilterGetResponse]

Expand All @@ -60,14 +61,14 @@ case class FilterSerializer @Inject()(mailboxIdFactory: MailboxId.Factory) {
implicit val updateReads: Reads[Update] = Json.valueReads[Update]
implicit val filterSetRequestReads: Reads[FilterSetRequest] = Json.reads[FilterSetRequest]

def serialize(response: FilterGetResponse): JsValue = Json.toJson(response)

implicit val setErrorDescriptionWrites: Writes[SetErrorDescription] = Json.valueWrites[SetErrorDescription]
implicit val filterSetErrorWrites: Writes[FilterSetError] = Json.writes[FilterSetError]
implicit val filterSetUpdateResponseWrites: Writes[FilterSetUpdateResponse] = Json.valueWrites[FilterSetUpdateResponse]
implicit val stateWrites: Writes[State] = Json.valueWrites[State]
implicit val filterSetResponseWrites: Writes[FilterSetResponse] = Json.writes[FilterSetResponse]

def serializeFilterGetResponse(response: FilterGetResponse): JsValue = Json.toJson(response)

def serializeFilterSetResponse(response: FilterSetResponse): JsValue = Json.toJson(response)

def deserializeFilterGetRequest(input: JsValue): JsResult[FilterGetRequest] = Json.fromJson[FilterGetRequest](input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.inject.AbstractModule
import com.google.inject.multibindings.{Multibinder, ProvidesIntoSet}
import com.linagora.openpaas.james.jmap.json.FilterSerializer
import com.linagora.openpaas.james.jmap.method.CapabilityIdentifier.LINAGORA_FILTER
import com.linagora.openpaas.james.jmap.model.{Filter, FilterGetNotFound, FilterGetRequest, FilterGetResponse, Rule}
import com.linagora.openpaas.james.jmap.model.{Filter, FilterGetNotFound, FilterGetRequest, FilterGetResponse, FilterState, FilterWithVersion, Rule}
import eu.timepit.refined.auto._
import org.apache.james.core.Username
import org.apache.james.jmap.api.filtering.FilteringManagement
Expand All @@ -19,8 +19,10 @@ import org.apache.james.mailbox.model.MailboxId
import org.apache.james.metrics.api.MetricFactory
import org.reactivestreams.Publisher
import play.api.libs.json.{JsError, JsObject, JsSuccess, Json}
import reactor.core.scala.publisher.{SFlux, SMono}
import reactor.core.scala.publisher.SMono

import javax.inject.Inject
import scala.jdk.CollectionConverters._

case object FilterCapabilityProperties extends CapabilityProperties {
override def jsonify(): JsObject = Json.obj()
Expand Down Expand Up @@ -58,7 +60,7 @@ class FilterGetMethod @Inject()(val metricFactory: MetricFactory,
getFilterGetResponse(request, mailboxSession).map(response => InvocationWithContext(
invocation = Invocation(
methodName = methodName,
arguments = Arguments(FilterSerializer(mailboxIdFactory).serialize(response).as[JsObject]),
arguments = Arguments(FilterSerializer(mailboxIdFactory).serializeFilterGetResponse(response).as[JsObject]),
methodCallId = invocation.invocation.methodCallId),
processingContext = invocation.processingContext))

Expand All @@ -69,22 +71,22 @@ class FilterGetMethod @Inject()(val metricFactory: MetricFactory,
case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
}

private def retrieveFilters(username: Username) : SMono[Filter] =
SFlux.fromPublisher(filteringManagement.listRulesForUser(username))
.map(javaRule => Rule.fromJava(javaRule, mailboxIdFactory))
.collectSeq()
.map(rules => Filter("singleton", rules.toList))
private def retrieveFiltersWithVersion(username: Username) : SMono[FilterWithVersion] =
SMono.fromPublisher(filteringManagement.listRulesForUser(username))
.map(rulesWithVersion => FilterWithVersion(Filter("singleton", rulesWithVersion.getRules.asScala.toList.map(rule => Rule.fromJava(rule, mailboxIdFactory))),
rulesWithVersion.getVersion))

private def getFilterGetResponse(request: FilterGetRequest,
mailboxSession: MailboxSession): SMono[FilterGetResponse] =
request.ids match {
case None => retrieveFilters(mailboxSession.getUser)
.map(filter => FilterGetResponse(request.accountId, List(filter), FilterGetNotFound(List())))
case None => retrieveFiltersWithVersion(mailboxSession.getUser)
.map(filterWithVersion => FilterGetResponse(request.accountId, FilterState(filterWithVersion.version.asString()), List(filterWithVersion.filter), FilterGetNotFound(List())))
case Some(ids) => if(ids.value.contains("singleton")) {
retrieveFilters(mailboxSession.getUser)
.map(filter => FilterGetResponse(request.accountId, List(filter), FilterGetNotFound(ids.value.filterNot(id => id.equals("singleton")))))
retrieveFiltersWithVersion(mailboxSession.getUser)
.map(filterWithVersion => FilterGetResponse(request.accountId, FilterState(filterWithVersion.version.asString()), List(filterWithVersion.filter), FilterGetNotFound(ids.value.filterNot(id => id.equals("singleton")))))
} else {
SMono.just(FilterGetResponse(request.accountId, List(), FilterGetNotFound(ids.value)))
retrieveFiltersWithVersion(mailboxSession.getUser)
.map(filterWithVersion => FilterGetResponse(request.accountId, FilterState(filterWithVersion.version.asString()), List(), FilterGetNotFound(ids.value)))
}
}

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

import com.google.common.collect.ImmutableList
import org.apache.james.jmap.api.filtering.{Rule => JavaRule}
import org.apache.james.jmap.api.filtering.{Version, Rule => JavaRule}
import org.apache.james.jmap.core.AccountId
import org.apache.james.jmap.core.Id.Id
import org.apache.james.jmap.mail.Name
Expand All @@ -12,6 +12,7 @@ case class FilterGetRequest(accountId: AccountId,
ids: Option[FilterGetIds]) extends WithAccountId

case class FilterGetResponse(accountId: AccountId,
state: FilterState,
list: List[Filter],
notFound: FilterGetNotFound)

Expand All @@ -31,6 +32,10 @@ case class Rule(name: Name, condition: Condition, action: Action)

case class Filter(id: Id, rules: List[Rule])

case class FilterWithVersion(filter: Filter, version: Version)

case class FilterState(state: String)

case class FilterGetNotFound(value: List[String]) {
def merge(other: FilterGetNotFound): FilterGetNotFound = FilterGetNotFound(this.value ++ other.value)
}
Expand Down