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 ro...@apache.org on 2019/07/26 08:13:19 UTC
[james-project] 11/12: JAMES-2813 extract Combinator to separate
file
This is an automated email from the ASF dual-hosted git repository.
rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 29a68a854975344469be6d892e266a6c75e64055
Author: Rémi Kowalski <rk...@linagora.com>
AuthorDate: Mon Jul 22 17:57:26 2019 +0200
JAMES-2813 extract Combinator to separate file
---
.../org/apache/james/vault/dto/query/QueryDTO.java | 4 +-
.../james/vault/dto/query/QueryTranslator.java | 44 ++++++++--------------
.../org/apache/james/vault/search/Combinator.java | 33 ++++++++++++++++
3 files changed, 52 insertions(+), 29 deletions(-)
diff --git a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/dto/query/QueryDTO.java b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/dto/query/QueryDTO.java
index 2a379de..f72ff0c 100644
--- a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/dto/query/QueryDTO.java
+++ b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/dto/query/QueryDTO.java
@@ -22,6 +22,8 @@ package org.apache.james.vault.dto.query;
import java.util.List;
import java.util.Objects;
+import org.apache.james.vault.search.Combinator;
+
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -33,7 +35,7 @@ public class QueryDTO implements QueryElement {
@VisibleForTesting
static QueryDTO and(QueryElement... queryElements) {
- return new QueryDTO(QueryTranslator.Combinator.AND.getValue(), ImmutableList.copyOf(queryElements));
+ return new QueryDTO(Combinator.AND.getValue(), ImmutableList.copyOf(queryElements));
}
private final String combinator;
diff --git a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/dto/query/QueryTranslator.java b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/dto/query/QueryTranslator.java
index d76f884..0467343 100644
--- a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/dto/query/QueryTranslator.java
+++ b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/dto/query/QueryTranslator.java
@@ -42,6 +42,7 @@ import javax.mail.internet.AddressException;
import org.apache.james.core.MailAddress;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.vault.search.Combinator;
import org.apache.james.vault.search.Criterion;
import org.apache.james.vault.search.CriterionFactory;
import org.apache.james.vault.search.FieldName;
@@ -76,21 +77,6 @@ public class QueryTranslator {
.orElseThrow(() -> new QueryTranslatorException("operator: '" + operator + "' is not supported"));
}
- enum Combinator {
- AND("and");
-
- private final String value;
-
- Combinator(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
- }
-
-
interface FieldValueParser<T> {
class MailboxIdValueParser implements FieldValueParser<MailboxId> {
@@ -128,7 +114,7 @@ public class QueryTranslator {
FieldValueSerializer<MailboxId> MAILBOX_ID_SERIALIZER = MailboxId::serialize;
FieldValueSerializer<ZonedDateTime> ZONED_DATE_TIME_SERIALIZER = ZonedDateTime::toString;
FieldValueSerializer<String> STRING_SERIALIZER = input -> input;
- FieldValueSerializer<Boolean> BOOLEAN_SERIALIZER = input -> input.toString();
+ FieldValueSerializer<Boolean> BOOLEAN_SERIALIZER = Object::toString;
FieldValueSerializer<MailAddress> MAIL_ADDRESS_SERIALIZER = MailAddress::asString;
static Optional<FieldValueSerializer> getSerializerForValue(Object value) {
@@ -208,21 +194,23 @@ public class QueryTranslator {
}
public QueryDTO toDTO(Query query) throws QueryTranslatorException {
- List<QueryElement> queryElements = query.getCriteria().stream().map(criterion -> {
- FieldName fieldName = criterion.getField().fieldName();
- Operator operator = criterion.getValueMatcher().operator();
- Object value = criterion.getValueMatcher().expectedValue();
+ List<QueryElement> queryElements = query.getCriteria().stream()
+ .map(this::toDTO)
+ .collect(Guavate.toImmutableList());
+ return new QueryDTO(Combinator.AND.getValue(), queryElements);
+ }
- FieldValueSerializer fieldValueSerializer = FieldValueSerializer.getSerializerForValue(value).orElseThrow(
- () -> new IllegalArgumentException("Value of type " + value.getClass().getSimpleName()
- + "' is not handled by the combinaison of operator : " + operator.name()
- + " and field :" + fieldName.name())
- );
+ private CriterionDTO toDTO(Criterion<?> criterion) {
+ FieldName fieldName = criterion.getField().fieldName();
+ Operator operator = criterion.getValueMatcher().operator();
+ Object value = criterion.getValueMatcher().expectedValue();
- return new CriterionDTO(fieldName.getValue(), operator.getValue(), fieldValueSerializer.serialize(value));
- }).collect(Guavate.toImmutableList());
+ FieldValueSerializer fieldValueSerializer = FieldValueSerializer.getSerializerForValue(value).orElseThrow(
+ () -> new IllegalArgumentException("Value of type " + value.getClass().getSimpleName()
+ + "' is not handled by the combinaison of operator : " + operator.name()
+ + " and field :" + fieldName.name()));
- return new QueryDTO(Combinator.AND.value, queryElements);
+ return new CriterionDTO(fieldName.getValue(), operator.getValue(), fieldValueSerializer.serialize(value));
}
Query translate(QueryDTO queryDTO) throws QueryTranslatorException {
diff --git a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/search/Combinator.java b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/search/Combinator.java
new file mode 100644
index 0000000..e822903
--- /dev/null
+++ b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/search/Combinator.java
@@ -0,0 +1,33 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.vault.search;
+
+public enum Combinator {
+ AND("and");
+
+ private final String value;
+
+ Combinator(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org