// Path: src/main/java/org/scrutmydocs/webapp/util/PropertyScanner.java
// public class PropertyScanner {
// 
//     public static ScrutMyDocsProperties scanPropertyFile() throws IOException {
// 		ScrutMyDocsProperties smdProps = new ScrutMyDocsProperties();
// 		
// 		String userHome = System.getProperty("user.home");
// 		FileSystemResource resource = new FileSystemResource(userHome + "/.scrutmydocs/config/scrutmydocs.properties");
// 		Properties props = null;
// 		try {
// 			props = PropertiesLoaderUtils.loadProperties(resource);		
// 		} catch (FileNotFoundException e) {
// 			// File does not exists ? Who cares ?
// 		}
// 
// 		if (props == null) {
// 			// Build the file from the Classpath
// 			FileSystemResource configDir = new FileSystemResource(userHome + "/.scrutmydocs/config/");
// 			ClassPathResource classPathResource = new ClassPathResource("/scrutmydocs/config/scrutmydocs.properties");
// 			
// 			File from = classPathResource.getFile();
// 			File dest = new File(configDir.getFile(),from.getName());
// 			Files.createParentDirs(dest);
// 			Files.copy(from, dest);
// 
// 			props = PropertiesLoaderUtils.loadProperties(resource);
// 		}
// 		
// 		if (props == null) {
// 			throw new RuntimeException("Can not build ~/.scrutmydocs/config/scrutmydocs.properties file. Check that current user have a write access");
// 		}
// 		else {
// 			smdProps.setNodeEmbedded(getProperty(props, "node.embedded", true));
// 			smdProps.setClusterName(getProperty(props, "cluster.name", "scrutmydocs"));
// 			FileSystemResource configDir = new FileSystemResource(userHome + "/.scrutmydocs/config/esdata/");
// 			smdProps.setPathData(getProperty(props, "path.data", configDir.getPath()));
// 			smdProps.setNodeAdresses(getPropertyAsArray(props, "node.addresses", "localhost:9300,localhost:9301"));
// 
// 			// We check some rules here :
// 			// if node.embedded = false, we must have an array of node.adresses
// 			if (!smdProps.isNodeEmbedded() && (smdProps.getNodeAdresses() == null || smdProps.getNodeAdresses().length < 1)) {
// 				throw new RuntimeException("If you don't want embedded node, you MUST set node.addresses property.");
// 			}
// 		}
// 		
// 		return smdProps;
// 	}
// 
//     private static boolean getProperty(Properties props, String path,
// 	    boolean defaultValue) {
// 	String sValue = getProperty(props, path, Boolean.toString(defaultValue));
// 	if (sValue == null)
// 	    return false;
// 	return Boolean.parseBoolean(sValue);
//     }
// 
//     private static String getProperty(Properties props, String path,
// 	    String defaultValue) {
// 	return props.getProperty(path, defaultValue);
//     }
// 
//     private static String[] getPropertyAsArray(Properties props, String path,
// 	    String defaultValue) {
// 	String sValue = getProperty(props, path, defaultValue);
// 	if (sValue == null)
// 	    return null;
// 
// 	// Remove spaces and split results with comma
// 	String[] arrStr = StringUtils.commaDelimitedListToStringArray(sValue);
// 
// 	return arrStr;
//     }
// }


import fr.pilato.spring.elasticsearch.ElasticsearchAbstractClientFactoryBean;
import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean;
import fr.pilato.spring.elasticsearch.ElasticsearchNodeFactoryBean;
import fr.pilato.spring.elasticsearch.ElasticsearchTransportClientFactoryBean;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.node.Node;
import org.scrutmydocs.webapp.util.PropertyScanner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
 * Licensed to scrutmydocs.org (the "Author") under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. Author 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.scrutmydocs.webapp.configuration;


@Configuration
public class AppConfig {

	private ESLogger logger = Loggers.getLogger(getClass().getName());

	@Bean
	public ScrutMyDocsProperties smdProperties() throws Exception {

// Path: src/main/java/org/scrutmydocs/webapp/util/PropertyScanner.java
// public class PropertyScanner {
// 
//     public static ScrutMyDocsProperties scanPropertyFile() throws IOException {
// 		ScrutMyDocsProperties smdProps = new ScrutMyDocsProperties();
// 		
// 		String userHome = System.getProperty("user.home");
// 		FileSystemResource resource = new FileSystemResource(userHome + "/.scrutmydocs/config/scrutmydocs.properties");
// 		Properties props = null;
// 		try {
// 			props = PropertiesLoaderUtils.loadProperties(resource);		
// 		} catch (FileNotFoundException e) {
// 			// File does not exists ? Who cares ?
// 		}
// 
// 		if (props == null) {
// 			// Build the file from the Classpath
// 			FileSystemResource configDir = new FileSystemResource(userHome + "/.scrutmydocs/config/");
// 			ClassPathResource classPathResource = new ClassPathResource("/scrutmydocs/config/scrutmydocs.properties");
// 			
// 			File from = classPathResource.getFile();
// 			File dest = new File(configDir.getFile(),from.getName());
// 			Files.createParentDirs(dest);
// 			Files.copy(from, dest);
// 
// 			props = PropertiesLoaderUtils.loadProperties(resource);
// 		}
// 		
// 		if (props == null) {
// 			throw new RuntimeException("Can not build ~/.scrutmydocs/config/scrutmydocs.properties file. Check that current user have a write access");
// 		}
// 		else {
// 			smdProps.setNodeEmbedded(getProperty(props, "node.embedded", true));
// 			smdProps.setClusterName(getProperty(props, "cluster.name", "scrutmydocs"));
// 			FileSystemResource configDir = new FileSystemResource(userHome + "/.scrutmydocs/config/esdata/");
// 			smdProps.setPathData(getProperty(props, "path.data", configDir.getPath()));
// 			smdProps.setNodeAdresses(getPropertyAsArray(props, "node.addresses", "localhost:9300,localhost:9301"));
// 
// 			// We check some rules here :
// 			// if node.embedded = false, we must have an array of node.adresses
// 			if (!smdProps.isNodeEmbedded() && (smdProps.getNodeAdresses() == null || smdProps.getNodeAdresses().length < 1)) {
// 				throw new RuntimeException("If you don't want embedded node, you MUST set node.addresses property.");
// 			}
// 		}
// 		
// 		return smdProps;
// 	}
// 
//     private static boolean getProperty(Properties props, String path,
// 	    boolean defaultValue) {
// 	String sValue = getProperty(props, path, Boolean.toString(defaultValue));
// 	if (sValue == null)
// 	    return false;
// 	return Boolean.parseBoolean(sValue);
//     }
// 
//     private static String getProperty(Properties props, String path,
// 	    String defaultValue) {
// 	return props.getProperty(path, defaultValue);
//     }
// 
//     private static String[] getPropertyAsArray(Properties props, String path,
// 	    String defaultValue) {
// 	String sValue = getProperty(props, path, defaultValue);
// 	if (sValue == null)
// 	    return null;
// 
// 	// Remove spaces and split results with comma
// 	String[] arrStr = StringUtils.commaDelimitedListToStringArray(sValue);
// 
// 	return arrStr;
//     }
// }


// Path: src/main/java/org/scrutmydocs/webapp/configuration/AppConfig.java
import fr.pilato.spring.elasticsearch.ElasticsearchAbstractClientFactoryBean;
import fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean;
import fr.pilato.spring.elasticsearch.ElasticsearchNodeFactoryBean;
import fr.pilato.spring.elasticsearch.ElasticsearchTransportClientFactoryBean;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.node.Node;
import org.scrutmydocs.webapp.util.PropertyScanner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
 * Licensed to scrutmydocs.org (the "Author") under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. Author 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.scrutmydocs.webapp.configuration;


@Configuration
public class AppConfig {

	private ESLogger logger = Loggers.getLogger(getClass().getName());

	@Bean
	public ScrutMyDocsProperties smdProperties() throws Exception {

		ScrutMyDocsProperties smdProperties = PropertyScanner.scanPropertyFile();
