james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1688132 - in /james/mailbox/trunk/elasticsearch/src/main: java/org/apache/james/mailbox/elasticsearch/ java/org/apache/james/mailbox/elasticsearch/json/ resources/META-INF/spring/
Date Mon, 29 Jun 2015 08:35:37 GMT
Author: btellier
Date: Mon Jun 29 08:35:37 2015
New Revision: 1688132

URL: http://svn.apache.org/r1688132
Log:
MAILBOX-155 Using a Junit rule to launch embedded ElasticSearch

Added:
    james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/NodeMappingFactory.java
Modified:
    james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java
    james/mailbox/trunk/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml

Added: james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/NodeMappingFactory.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/NodeMappingFactory.java?rev=1688132&view=auto
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/NodeMappingFactory.java
(added)
+++ james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/NodeMappingFactory.java
Mon Jun 29 08:35:37 2015
@@ -0,0 +1,193 @@
+/****************************************************************
+ * 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.mailbox.elasticsearch;
+
+import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
+
+import java.io.IOException;
+
+import org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.node.Node;
+
+import com.google.common.base.Throwables;
+
+public class NodeMappingFactory {
+
+    public static final String BOOLEAN = "boolean";
+    public static final String TYPE = "type";
+    public static final String LONG = "long";
+    public static final String INDEX = "index";
+    public static final String NOT_ANALYZED = "not_analyzed";
+    public static final String STRING = "string";
+    public static final String PROPERTIES = "properties";
+    public static final String DATE = "date";
+    public static final String FORMAT = "format";
+    public static final String NESTED = "nested";
+
+    public static Node applyMapping(Node node) {
+        try (Client client = node.client()) {
+            client.admin()
+                .indices()
+                .preparePutMapping(ElasticSearchIndexer.MAILBOX_INDEX)
+                .setType(ElasticSearchIndexer.MESSAGE_TYPE)
+                .setSource(getMappingContent())
+                .execute()
+                .actionGet();
+        }
+        return node;
+    }
+
+    private static XContentBuilder getMappingContent() {
+        try {
+            return jsonBuilder()
+                .startObject()
+                    .startObject(ElasticSearchIndexer.MESSAGE_TYPE)
+                        .startObject(PROPERTIES)
+                            .startObject(JsonMessageConstants.ID)
+                                .field(TYPE, LONG)
+                            .endObject()
+                            .startObject(JsonMessageConstants.MODSEQ)
+                                .field(TYPE, LONG)
+                            .endObject()
+                            .startObject(JsonMessageConstants.SIZE)
+                                .field(TYPE, LONG)
+                            .endObject()
+                            .startObject(JsonMessageConstants.IS_ANSWERED)
+                                .field(TYPE, BOOLEAN)
+                            .endObject()
+                            .startObject(JsonMessageConstants.IS_DELETED)
+                                .field(TYPE, BOOLEAN)
+                            .endObject()
+                            .startObject(JsonMessageConstants.IS_DRAFT)
+                                .field(TYPE, BOOLEAN)
+                            .endObject()
+                            .startObject(JsonMessageConstants.IS_FLAGGED)
+                                .field(TYPE, BOOLEAN)
+                            .endObject()
+                            .startObject(JsonMessageConstants.IS_RECENT)
+                                .field(TYPE, BOOLEAN)
+                            .endObject()
+                            .startObject(JsonMessageConstants.IS_UNREAD)
+                                .field(TYPE, BOOLEAN)
+                            .endObject()
+                            .startObject(JsonMessageConstants.DATE)
+                                .field(TYPE, DATE)
+                                .field(FORMAT, "yyyy-MM-dd'T'HH:mm:ssZ")
+                            .endObject()
+                            .startObject(JsonMessageConstants.SENT_DATE)
+                                .field(TYPE, DATE)
+                                .field(FORMAT, "yyyy-MM-dd'T'HH:mm:ssZ")
+                            .endObject()
+                            .startObject(JsonMessageConstants.MEDIA_TYPE)
+                                .field(TYPE, STRING)
+                                .field(INDEX, NOT_ANALYZED)
+                            .endObject()
+                            .startObject(JsonMessageConstants.SUBTYPE)
+                                .field(TYPE, STRING)
+                                .field(INDEX, NOT_ANALYZED)
+                            .endObject()
+                            .startObject(JsonMessageConstants.USER_FLAGS)
+                                .field(TYPE, STRING)
+                                .field(INDEX, NOT_ANALYZED)
+                            .endObject()
+
+                            .startObject(JsonMessageConstants.FROM)
+                                .field(TYPE, NESTED)
+                                .startObject(PROPERTIES)
+                                    .startObject(JsonMessageConstants.EMailer.NAME)
+                                        .field(TYPE, STRING)
+                                    .endObject()
+                                    .startObject(JsonMessageConstants.EMailer.ADDRESS)
+                                        .field(TYPE, STRING)
+                                        .field(INDEX, NOT_ANALYZED)
+                                    .endObject()
+                                .endObject()
+                            .endObject()
+
+                            .startObject(JsonMessageConstants.TO)
+                                .field(TYPE, NESTED)
+                                .startObject(PROPERTIES)
+                                    .startObject(JsonMessageConstants.EMailer.NAME)
+                                        .field(TYPE, STRING)
+                                    .endObject()
+                                    .startObject(JsonMessageConstants.EMailer.ADDRESS)
+                                        .field(TYPE, STRING)
+                                        .field(INDEX, NOT_ANALYZED)
+                                    .endObject()
+                                .endObject()
+                            .endObject()
+
+                            .startObject(JsonMessageConstants.CC)
+                                .field(TYPE, NESTED)
+                                .startObject(PROPERTIES)
+                                    .startObject(JsonMessageConstants.EMailer.NAME)
+                                        .field(TYPE, STRING)
+                                    .endObject()
+                                    .startObject(JsonMessageConstants.EMailer.ADDRESS)
+                                        .field(TYPE, STRING)
+                                        .field(INDEX, NOT_ANALYZED)
+                                    .endObject()
+                                .endObject()
+                            .endObject()
+
+                            .startObject(JsonMessageConstants.BCC)
+                                .field(TYPE, NESTED)
+                                .startObject(PROPERTIES)
+                                    .startObject(JsonMessageConstants.EMailer.NAME)
+                                        .field(TYPE, STRING)
+                                    .endObject()
+                                    .startObject(JsonMessageConstants.EMailer.ADDRESS)
+                                        .field(TYPE, STRING)
+                                        .field(INDEX, NOT_ANALYZED)
+                                    .endObject()
+                                .endObject()
+                            .endObject()
+
+                            .startObject(JsonMessageConstants.MAILBOX_ID)
+                                .field(TYPE, STRING)
+                                .field(INDEX, NOT_ANALYZED)
+                            .endObject()
+                            .startObject(JsonMessageConstants.PROPERTIES)
+                                .field(TYPE, NESTED)
+                                .startObject(PROPERTIES)
+                                    .startObject(JsonMessageConstants.Property.NAMESPACE)
+                                        .field(TYPE, STRING)
+                                        .field(INDEX, NOT_ANALYZED)
+                                    .endObject()
+                                    .startObject(JsonMessageConstants.Property.NAME)
+                                        .field(TYPE, STRING)
+                                        .field(INDEX, NOT_ANALYZED)
+                                    .endObject()
+                                    .startObject(JsonMessageConstants.Property.VALUE)
+                                        .field(TYPE, STRING)
+                                    .endObject()
+                                .endObject()
+                            .endObject()
+                        .endObject()
+                    .endObject()
+                .endObject();
+        } catch (IOException e) {
+            throw Throwables.propagate(e);
+        }
+    }
+
+}

Modified: james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java?rev=1688132&r1=1688131&r2=1688132&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java
(original)
+++ james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java
Mon Jun 29 08:35:37 2015
@@ -67,4 +67,11 @@ public interface JsonMessageConstants {
         String FILENAME = "fileName";
         String FILE_EXTENSION = "fileExtension";
     }
+
+    interface Property {
+        String NAMESPACE = "namespace";
+        String NAME = "name";
+        String VALUE = "value";
+    }
+
 }

Modified: james/mailbox/trunk/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml?rev=1688132&r1=1688131&r2=1688132&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml
(original)
+++ james/mailbox/trunk/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml
Mon Jun 29 08:35:37 2015
@@ -38,12 +38,25 @@
         <constructor-arg index="0" ref="elasticsearch-node"/>
     </bean>
 
-    <bean id="elasticsearch-node" class="org.apache.james.mailbox.elasticsearch.NodeProvider"
factory-method="createNodeForClusterName">
-        <constructor-arg index="0" value="${elasticsearch.clusterName}"/>
-        <constructor-arg index="1" value="${elasticsearch.masterHost}"/>
+    <bean id="elasticsearch-json" class="org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson">
+
+    <bean id="elasticsearch-searcher" class="org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher">
+        <constructor-arg index="0" ref="elasticsearch-node"/>
     </bean>
 
-    <bean id="elasticsearch-json" class="org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson">
+    <bean id="elasticsearch-node-no-index" class="org.apache.james.mailbox.cassandra.elasticsearch.NodeProvider"
factory-method="createNodeForClusterName">
+        <constructor-arg index="0" ref="${elasticsearch.clusterName}"/>
+        <constructor-arg index="1" ref="${elasticsearch.masterHost}"/>
+    </bean>
+
+    <bean id="elasticsearch-node-index" class="org.apache.james.mailbox.elasticsearch"
factory-method="createNodeForClusterName">
+        <constructor-arg index="0" ref="elasticsearch-node-no-index"/>
+        <constructor-arg index="1" value="${elasticsearch.shards}"/>
+        <constructor-arg index="2" value="${elasticsearch.replicas}"/>
+    </bean>
+
+    <bean id="elasticsearch-node" class="org.apache.james.mailbox.elasticsearch.NodeProvider"
factory-method="createNodeForClusterName">
+        <constructor-arg index="0" ref="elasticsearch-node-index"/>
     </bean>
 
 </beans>



---------------------------------------------------------------------
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