Search in sources :

Example 16 with ConfigValue

use of com.typesafe.config.ConfigValue in project play2-elasticsearch by cleverage.

the class IndexConfig method loadMappingFromConfig.

/**
     * Load additional mappings from config entry "elasticsearch.index.mapping"
     * @param indexName
     */
private void loadMappingFromConfig(String indexName) {
    Configuration mappingConfig = (configuration.getConfig("elasticsearch." + indexName + ".mappings") == Option.apply((Configuration) null)) ? null : configuration.getConfig("elasticsearch." + indexName + ".mappings").get();
    if (mappingConfig != null) {
        Iterator<Tuple2<String, ConfigValue>> iter = mappingConfig.entrySet().iterator();
        while (iter.hasNext()) {
            Tuple2<String, ConfigValue> mapping = iter.next();
            String indexType = mapping._1();
            IndexQueryPath indexQueryPath = new IndexQueryPath(indexName, indexType);
            if (mapping._2().unwrapped() instanceof String) {
                indexMappings.put(indexQueryPath, (String) mapping._2().unwrapped());
            } else {
                try {
                    indexMappings.put(indexQueryPath, Json.toJson(mapping._2().unwrapped()).toString());
                } catch (Exception e) {
                    Logger.warn("Incorrect value in elasticsearch.index.mappings", e);
                }
            }
        }
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) Configuration(play.api.Configuration) Tuple2(scala.Tuple2)

Aggregations

ConfigValue (com.typesafe.config.ConfigValue)16 ConfigException (com.typesafe.config.ConfigException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ConfigObject (com.typesafe.config.ConfigObject)3 Config (com.typesafe.config.Config)2 ConfigList (com.typesafe.config.ConfigList)2 ParaObject (com.erudika.para.core.ParaObject)1 ConfigValueType (com.typesafe.config.ConfigValueType)1 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 AbstractMap (java.util.AbstractMap)1 EnumMap (java.util.EnumMap)1 List (java.util.List)1