
package usda.weru.remoteDataAccess.jdbc.soil.soilDataMart;

import java.util.Arrays;
import java.util.Properties;
import usda.weru.remoteDataAccess.jdbc.soil.JdbcSoilInterfaceDatabase;
import usda.weru.soil.ArsSoapSoilDatabase;
import usda.weru.soil.arssql.ConnectionARS;
import usda.weru.util.ConfigData;

/**
 *
 * @author mhaas
 */
public class SdmInterfaceDatabase extends JdbcSoilInterfaceDatabase {

    @Override
    public void initialize () {
        
        Properties props = new Properties();

//        props.put("host", "https://SDMDataAccess.nrcs.usda.gov");
//        props.put("name", "NRCS Soil Data Mart");
        props.put("host", ConfigData.getDefault().getData("CD-WS-SDM-soils-params-host"));
//        props.put("name", ConfigData.getDefault().getData("CD-WS-SDM-soils-params-name"));

        soilsDatabase = new ArsSoapSoilDatabase(props);

        // just makes the root node.  Needed?
        Arrays.asList(soilsDatabase.createNodes());

        soilsDbConnection = new ConnectionARS(props.getProperty("host"));
    }
    
    
//    @Override
//    public void initialize () {
//        File soilsConfigFile;
//        
//        if (soilsDatabase == null) {
//        
//            String path = usda.weru.util.ConfigData.getDefault().getDataParsed(ConfigData.SoilDB);
//            soilsConfigFile = new File(path, "SDMDataAccess.nrcs.usda.gov.db");
//
//            //generic db file
//            Properties props = new Properties();
//            Reader reader = null;
//            try {
//
//                // from SoilTreeModel.TemplatesNode.CreatDatabases()
//                reader = new TFileReader(soilsConfigFile);
//                props.load(reader);
//                String type = props.getProperty("type");
//                if (ArsSoapSoilDatabase.TYPE.equals(type)) {
//                    soilsDatabase = new ArsSoapSoilDatabase(props);
//
//                    // just makes the root node.  Needed?
//                    Arrays.asList(soilsDatabase.createNodes());
//
//                    // from ArsSoapSoilDatabase new and createConnection();
//                    String host = props.getProperty("host");
//                    soilsDbHostName = host != null ? host : "SDMDataAccess.nrcs.usda.gov";
//                    soilsDbConnection = new ConnectionARS(soilsDbHostName);
//                } else {
//                }
//            } catch (FileNotFoundException fnfe) {
//                //Ignore, shouldn't be here
//            } catch (IOException ioe) {
//                //TODO: add log message indicating there was an error reading the database file
//            } finally {
//                try {
//                    reader.close();
//                } catch (IOException e) {
//                }
//            }
//        }
//        
//    }
    
}
