james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [12/12] james-project git commit: JAMES-1901 Strong typing for Index and Types
Date Fri, 03 Feb 2017 09:44:40 GMT
JAMES-1901 Strong typing for Index and Types


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b54f9604
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b54f9604
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b54f9604

Branch: refs/heads/master
Commit: b54f9604d69be4fb268e9c98e25fd115f7cd0112
Parents: 263976a
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Feb 2 11:51:55 2017 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Feb 3 16:43:43 2017 +0700

----------------------------------------------------------------------
 .../backends/es/DeleteByQueryPerformer.java     | 16 ++++-----
 .../james/backends/es/ElasticSearchIndexer.java | 20 +++++++----
 .../james/backends/es/IndexCreationFactory.java |  8 ++---
 .../org/apache/james/backends/es/IndexName.java | 32 +++++++++++++++++
 .../james/backends/es/NodeMappingFactory.java   |  6 ++--
 .../org/apache/james/backends/es/TypeName.java  | 32 +++++++++++++++++
 .../backends/es/ElasticSearchIndexerTest.java   | 32 ++++++++---------
 .../backends/es/EmbeddedElasticSearch.java      | 10 +++---
 .../backends/es/search/ScrollIterableTest.java  | 38 ++++++++++----------
 .../MailboxElasticsearchConstants.java          |  7 ++--
 .../elasticsearch/MailboxMappingFactory.java    |  2 +-
 .../search/ElasticSearchSearcher.java           |  4 +--
 .../mailbox/ElasticSearchMailboxModule.java     |  4 +++
 13 files changed, 146 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
index 065fe19..6a44754 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
@@ -43,16 +43,16 @@ public class DeleteByQueryPerformer {
     private final Client client;
     private final ExecutorService executor;
     private final int batchSize;
-    private final String indexName;
-    private final String typeName;
+    private final IndexName indexName;
+    private final TypeName typeName;
 
     @Inject
-    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService
executor, String indexName, String typeName) {
+    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService
executor, IndexName indexName, TypeName typeName) {
         this(client, executor, DEFAULT_BATCH_SIZE, indexName, typeName);
     }
 
     @VisibleForTesting
-    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService
executor, int batchSize, String indexName, String typeName) {
+    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService
executor, int batchSize, IndexName indexName, TypeName typeName) {
         this.client = client;
         this.executor = executor;
         this.batchSize = batchSize;
@@ -66,8 +66,8 @@ public class DeleteByQueryPerformer {
 
     protected void doDeleteByQuery(QueryBuilder queryBuilder) {
         new ScrollIterable(client,
-            client.prepareSearch(indexName)
-                .setTypes(typeName)
+            client.prepareSearch(indexName.getValue())
+                .setTypes(typeName.getValue())
                 .setScroll(TIMEOUT)
                 .setNoFields()
                 .setQuery(queryBuilder)
@@ -80,8 +80,8 @@ public class DeleteByQueryPerformer {
         BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
         for (SearchHit hit : searchResponse.getHits()) {
             bulkRequestBuilder.add(client.prepareDelete()
-                .setIndex(indexName)
-                .setType(typeName)
+                .setIndex(indexName.getValue())
+                .setType(typeName.getValue())
                 .setId(hit.getId()));
         }
         return bulkRequestBuilder.execute();

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
index 5cbf1f4..f1df1d7 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
@@ -59,11 +59,11 @@ public class ElasticSearchIndexer {
     
     private final Client client;
     private final DeleteByQueryPerformer deleteByQueryPerformer;
-    private final String indexName;
-    private final String typeName;
+    private final IndexName indexName;
+    private final TypeName typeName;
 
     @Inject
-    public ElasticSearchIndexer(Client client, DeleteByQueryPerformer deleteByQueryPerformer,
String indexName, String typeName) {
+    public ElasticSearchIndexer(Client client, DeleteByQueryPerformer deleteByQueryPerformer,
IndexName indexName, TypeName typeName) {
         this.client = client;
         this.deleteByQueryPerformer = deleteByQueryPerformer;
         this.indexName = indexName;
@@ -73,7 +73,7 @@ public class ElasticSearchIndexer {
     public IndexResponse indexMessage(String id, String content) {
         checkArgument(content);
         LOGGER.debug(String.format("Indexing %s: %s", id, content));
-        return client.prepareIndex(indexName, typeName, id)
+        return client.prepareIndex(indexName.getValue(), typeName.getValue(), id)
             .setSource(content)
             .get();
     }
@@ -81,14 +81,22 @@ public class ElasticSearchIndexer {
     public BulkResponse updateMessages(List<UpdatedRepresentation> updatedDocumentParts)
{
         Preconditions.checkNotNull(updatedDocumentParts);
         BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
-        updatedDocumentParts.forEach(updatedDocumentPart -> bulkRequestBuilder.add(client.prepareUpdate(indexName,
typeName, updatedDocumentPart.getId())
+        updatedDocumentParts.forEach(updatedDocumentPart -> bulkRequestBuilder.add(
+            client.prepareUpdate(
+                indexName.getValue(),
+                typeName.getValue(),
+                updatedDocumentPart.getId())
             .setDoc(updatedDocumentPart.getUpdatedDocumentPart())));
         return bulkRequestBuilder.get();
     }
 
     public BulkResponse deleteMessages(List<String> ids) {
         BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
-        ids.forEach(id -> bulkRequestBuilder.add(client.prepareDelete(indexName, typeName,
id)));
+        ids.forEach(id -> bulkRequestBuilder.add(
+            client.prepareDelete(
+                indexName.getValue(),
+                typeName.getValue(),
+                id)));
         return bulkRequestBuilder.get();
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
index cab6021..eb6771a 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
@@ -36,7 +36,7 @@ public class IndexCreationFactory {
     private static final int DEFAULT_NB_REPLICA = 0;
     public static final String CASE_INSENSITIVE = "case_insensitive";
 
-    public static Client createIndex(Client client, String name, int nbShards, int nbReplica)
{
+    public static Client createIndex(Client client, IndexName name, int nbShards, int nbReplica)
{
         try {
             return createIndex(client, name, generateSetting(nbShards, nbReplica));
         } catch (IOException e) {
@@ -45,15 +45,15 @@ public class IndexCreationFactory {
         }
     }
 
-    public static Client createIndex(Client client, String name) {
+    public static Client createIndex(Client client, IndexName name) {
         return createIndex(client, name, DEFAULT_NB_SHARDS, DEFAULT_NB_REPLICA);
     }
 
-    private static Client createIndex(Client client, String name, XContentBuilder settings)
{
+    private static Client createIndex(Client client, IndexName name, XContentBuilder settings)
{
         try {
                 client.admin()
                     .indices()
-                    .prepareCreate(name)
+                    .prepareCreate(name.getValue())
                     .setSettings(settings)
                     .execute()
                     .actionGet();

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java
new file mode 100644
index 0000000..8936bb2
--- /dev/null
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.backends.es;
+
+public class IndexName {
+    private final String value;
+
+    public IndexName(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
index 876c741..f60bcd2 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
@@ -41,11 +41,11 @@ public class NodeMappingFactory {
     public static final String IGNORE_ABOVE = "ignore_above";
     public static final int LUCENE_LIMIT = 32766;
 
-    public static Client applyMapping(Client client, String indexName, String typeName, XContentBuilder
mappingsSources) {
+    public static Client applyMapping(Client client, IndexName indexName, TypeName typeName,
XContentBuilder mappingsSources) {
         client.admin()
             .indices()
-            .preparePutMapping(indexName)
-            .setType(typeName)
+            .preparePutMapping(indexName.getValue())
+            .setType(typeName.getValue())
             .setSource(mappingsSources)
             .execute()
             .actionGet();

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/TypeName.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/TypeName.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/TypeName.java
new file mode 100644
index 0000000..e6c638b
--- /dev/null
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/TypeName.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.backends.es;
+
+public class TypeName {
+    private final String value;
+
+    public TypeName(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
index cb42956..60ce997 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
@@ -43,8 +43,8 @@ public class ElasticSearchIndexerTest {
 
     private static final int MINIMUM_BATCH_SIZE = 1;
     private static final String CONTENT = "content";
-    private static final String INDEX_NAME = "index_name";
-    private static final String TYPE_NAME = "type_name";
+    private static final IndexName INDEX_NAME = new IndexName("index_name");
+    private static final TypeName TYPE_NAME = new TypeName("type_name");
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
     private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder,
INDEX_NAME);
 
@@ -80,8 +80,8 @@ public class ElasticSearchIndexerTest {
         embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
-            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME)
-                    .setTypes(TYPE_NAME)
+            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME.getValue())
+                    .setTypes(TYPE_NAME.getValue())
                     .setQuery(QueryBuilders.matchQuery("message", "trying"))
                     .get();
             assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(1);
@@ -105,16 +105,16 @@ public class ElasticSearchIndexerTest {
         embeddedElasticSearch.awaitForElasticSearch();
 
         try (Client client = node.client()) {
-            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME)
-                .setTypes(TYPE_NAME)
+            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME.getValue())
+                .setTypes(TYPE_NAME.getValue())
                 .setQuery(QueryBuilders.matchQuery("message", "mastering"))
                 .get();
             assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(1);
         }
 
         try (Client client = node.client()) {
-            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME)
-                .setTypes(TYPE_NAME)
+            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME.getValue())
+                .setTypes(TYPE_NAME.getValue())
                 .setQuery(QueryBuilders.matchQuery("field", "unchanged"))
                 .get();
             assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(1);
@@ -153,8 +153,8 @@ public class ElasticSearchIndexerTest {
         embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
-            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME)
-                    .setTypes(TYPE_NAME)
+            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME.getValue())
+                    .setTypes(TYPE_NAME.getValue())
                     .setQuery(QueryBuilders.matchAllQuery())
                     .get();
             assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(0);
@@ -183,8 +183,8 @@ public class ElasticSearchIndexerTest {
         embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
-            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME)
-                    .setTypes(TYPE_NAME)
+            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME.getValue())
+                    .setTypes(TYPE_NAME.getValue())
                     .setQuery(QueryBuilders.matchAllQuery())
                     .get();
             assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(1);
@@ -203,8 +203,8 @@ public class ElasticSearchIndexerTest {
         embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
-            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME)
-                    .setTypes(TYPE_NAME)
+            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME.getValue())
+                    .setTypes(TYPE_NAME.getValue())
                     .setQuery(QueryBuilders.matchAllQuery())
                     .get();
             assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(0);
@@ -233,8 +233,8 @@ public class ElasticSearchIndexerTest {
         embeddedElasticSearch.awaitForElasticSearch();
 
         try (Client client = node.client()) {
-            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME)
-                .setTypes(TYPE_NAME)
+            SearchResponse searchResponse = client.prepareSearch(INDEX_NAME.getValue())
+                .setTypes(TYPE_NAME.getValue())
                 .setQuery(QueryBuilders.matchAllQuery())
                 .get();
             assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(1);

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
index 2902cde..5f37189 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
@@ -45,7 +45,7 @@ public class EmbeddedElasticSearch extends ExternalResource {
     private static final Logger LOGGER = LoggerFactory.getLogger(EmbeddedElasticSearch.class);
 
     private final Supplier<Path> folder;
-    private final String indexName;
+    private final IndexName indexName;
     private Node node;
 
     private static Path createTempDir(TemporaryFolder temporaryFolder) {
@@ -56,15 +56,15 @@ public class EmbeddedElasticSearch extends ExternalResource {
         }
     }
 
-    public EmbeddedElasticSearch(TemporaryFolder temporaryFolder, String indexName) {
+    public EmbeddedElasticSearch(TemporaryFolder temporaryFolder, IndexName indexName) {
         this(() -> EmbeddedElasticSearch.createTempDir(temporaryFolder), indexName);
     }
 
-    public EmbeddedElasticSearch(Path folder, String indexName) {
+    public EmbeddedElasticSearch(Path folder, IndexName indexName) {
         this(() -> folder, indexName);
     }
 
-    private EmbeddedElasticSearch(Supplier<Path> folder, String indexName) {
+    private EmbeddedElasticSearch(Supplier<Path> folder, IndexName indexName) {
         this.folder = folder;
         this.indexName = indexName;
     }
@@ -86,7 +86,7 @@ public class EmbeddedElasticSearch extends ExternalResource {
         try (Client client = node.client()) {
             client.admin()
                 .indices()
-                .delete(new DeleteIndexRequest(indexName))
+                .delete(new DeleteIndexRequest(indexName.getValue()))
                 .actionGet();
         } catch (Exception e) {
             LOGGER.warn("Error while closing ES connection", e);

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
index 5b53a76..121b8b7 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
@@ -31,7 +31,9 @@ import java.util.stream.Collectors;
 import org.apache.james.backends.es.ClientProvider;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.backends.es.IndexCreationFactory;
+import org.apache.james.backends.es.IndexName;
 import org.apache.james.backends.es.NodeMappingFactory;
+import org.apache.james.backends.es.TypeName;
 import org.apache.james.backends.es.utils.TestingClientProvider;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.client.Client;
@@ -49,8 +51,8 @@ public class ScrollIterableTest {
     public static final TimeValue TIMEOUT = new TimeValue(6000);
     public static final int SIZE = 2;
     public static final String MESSAGE = "message";
-    public static final String INDEX_NAME = "index";
-    public static final String MESSAGES = "messages";
+    public static final IndexName INDEX_NAME = new IndexName("index");
+    public static final TypeName TYPE_NAME = new TypeName("messages");
 
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
     private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder,
INDEX_NAME);
@@ -65,13 +67,13 @@ public class ScrollIterableTest {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
         IndexCreationFactory.createIndex(clientProvider.get(), INDEX_NAME);
         embeddedElasticSearch.awaitForElasticSearch();
-        NodeMappingFactory.applyMapping(clientProvider.get(), INDEX_NAME, MESSAGES, getMappingsSources());
+        NodeMappingFactory.applyMapping(clientProvider.get(), INDEX_NAME, TYPE_NAME, getMappingsSources());
     }
 
     private XContentBuilder getMappingsSources() throws IOException {
         return jsonBuilder()
             .startObject()
-                .startObject(MESSAGES)
+                .startObject(TYPE_NAME.getValue())
                     .startObject(NodeMappingFactory.PROPERTIES)
                         .startObject(MESSAGE)
                             .field(NodeMappingFactory.TYPE, NodeMappingFactory.STRING)
@@ -84,8 +86,8 @@ public class ScrollIterableTest {
     @Test
     public void scrollIterableShouldWorkWhenEmpty() {
         try (Client client = clientProvider.get()) {
-            SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
-                .setTypes(MESSAGES)
+            SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME.getValue())
+                .setTypes(TYPE_NAME.getValue())
                 .setScroll(TIMEOUT)
                 .setQuery(matchAllQuery())
                 .setSize(SIZE);
@@ -97,14 +99,14 @@ public class ScrollIterableTest {
     public void scrollIterableShouldWorkWhenOneElement() {
         try (Client client = clientProvider.get()) {
             String id = "1";
-            client.prepareIndex(INDEX_NAME, MESSAGES, id)
+            client.prepareIndex(INDEX_NAME.getValue(), TYPE_NAME.getValue(), id)
                 .setSource(MESSAGE, "Sample message")
                 .execute();
 
             embeddedElasticSearch.awaitForElasticSearch();
 
-            SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
-                .setTypes(MESSAGES)
+            SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME.getValue())
+                .setTypes(TYPE_NAME.getValue())
                 .setScroll(TIMEOUT)
                 .setQuery(matchAllQuery())
                 .setSize(SIZE);
@@ -116,19 +118,19 @@ public class ScrollIterableTest {
     public void scrollIterableShouldWorkWhenSizeElement() {
         try (Client client = clientProvider.get()) {
             String id1 = "1";
-            client.prepareIndex(INDEX_NAME, MESSAGES, id1)
+            client.prepareIndex(INDEX_NAME.getValue(), TYPE_NAME.getValue(), id1)
                 .setSource(MESSAGE, "Sample message")
                 .execute();
 
             String id2 = "2";
-            client.prepareIndex(INDEX_NAME, MESSAGES, id2)
+            client.prepareIndex(INDEX_NAME.getValue(), TYPE_NAME.getValue(), id2)
                 .setSource(MESSAGE, "Sample message")
                 .execute();
 
             embeddedElasticSearch.awaitForElasticSearch();
 
-            SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
-                .setTypes(MESSAGES)
+            SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME.getValue())
+                .setTypes(TYPE_NAME.getValue())
                 .setScroll(TIMEOUT)
                 .setQuery(matchAllQuery())
                 .setSize(SIZE);
@@ -140,24 +142,24 @@ public class ScrollIterableTest {
     public void scrollIterableShouldWorkWhenMoreThanSizeElement() {
         try (Client client = clientProvider.get()) {
             String id1 = "1";
-            client.prepareIndex(INDEX_NAME, MESSAGES, id1)
+            client.prepareIndex(INDEX_NAME.getValue(), TYPE_NAME.getValue(), id1)
                 .setSource(MESSAGE, "Sample message")
                 .execute();
 
             String id2 = "2";
-            client.prepareIndex(INDEX_NAME, MESSAGES, id2)
+            client.prepareIndex(INDEX_NAME.getValue(), TYPE_NAME.getValue(), id2)
                 .setSource(MESSAGE, "Sample message")
                 .execute();
 
             String id3 = "3";
-            client.prepareIndex(INDEX_NAME, MESSAGES, id3)
+            client.prepareIndex(INDEX_NAME.getValue(), TYPE_NAME.getValue(), id3)
                 .setSource(MESSAGE, "Sample message")
                 .execute();
 
             embeddedElasticSearch.awaitForElasticSearch();
 
-            SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
-                .setTypes(MESSAGES)
+            SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME.getValue())
+                .setTypes(TYPE_NAME.getValue())
                 .setScroll(TIMEOUT)
                 .setQuery(matchAllQuery())
                 .setSize(SIZE);

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
index 4977950..4cf9bd1 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
@@ -19,7 +19,10 @@
 
 package org.apache.james.mailbox.elasticsearch;
 
+import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.TypeName;
+
 public interface MailboxElasticsearchConstants {
-    String MAILBOX_INDEX = "mailbox";
-    String MESSAGE_TYPE = "message";
+    IndexName MAILBOX_INDEX = new IndexName("mailbox");
+    TypeName MESSAGE_TYPE = new TypeName("message");
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
index 1cfce9b..ad2d16b 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
@@ -38,7 +38,7 @@ public class MailboxMappingFactory {
             return jsonBuilder()
                 .startObject()
 
-                    .startObject(MailboxElasticsearchConstants.MESSAGE_TYPE)
+                    .startObject(MailboxElasticsearchConstants.MESSAGE_TYPE.getValue())
                         .startObject(NodeMappingFactory.PROPERTIES)
                             .startObject(JsonMessageConstants.MESSAGE_ID)
                                 .field(NodeMappingFactory.TYPE, NodeMappingFactory.STRING)

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
index d8339f7..1599559 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
@@ -83,8 +83,8 @@ public class ElasticSearchSearcher {
         return query.getSearchQuery().getSorts()
             .stream()
             .reduce(
-                client.prepareSearch(MailboxElasticsearchConstants.MAILBOX_INDEX)
-                    .setTypes(MailboxElasticsearchConstants.MESSAGE_TYPE)
+                client.prepareSearch(MailboxElasticsearchConstants.MAILBOX_INDEX.getValue())
+                    .setTypes(MailboxElasticsearchConstants.MESSAGE_TYPE.getValue())
                     .setScroll(TIMEOUT)
                     .addFields(JsonMessageConstants.UID, JsonMessageConstants.MAILBOX_ID,
JsonMessageConstants.MESSAGE_ID)
                     .setQuery(queryConverter.from(users, query))

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54f9604/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
index 8d79af2..bbea50a 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
@@ -29,7 +29,9 @@ import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.backends.es.ClientProvider;
 import org.apache.james.backends.es.ClientProviderImpl;
 import org.apache.james.backends.es.IndexCreationFactory;
+import org.apache.james.backends.es.IndexName;
 import org.apache.james.backends.es.NodeMappingFactory;
+import org.apache.james.backends.es.TypeName;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
 import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
@@ -58,6 +60,8 @@ public class ElasticSearchMailboxModule extends AbstractModule {
 
     @Override
     protected void configure() {
+        bind(IndexName.class).toInstance(MailboxElasticsearchConstants.MAILBOX_INDEX);
+        bind(TypeName.class).toInstance(MailboxElasticsearchConstants.MESSAGE_TYPE);
         bind(ElasticSearchListeningMessageSearchIndex.class).in(Scopes.SINGLETON);
         bind(MessageSearchIndex.class).to(ElasticSearchListeningMessageSearchIndex.class);
         bind(ListeningMessageSearchIndex.class).to(ElasticSearchListeningMessageSearchIndex.class);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message