package in.cdac.medinfo.csnotk.launch;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import in.cdac.medinfo.csnotk.csnolib.agents.SNOMEDAgent;
import in.cdac.medinfo.csnotk.csnolib.commons.Constants;

public class Configurator {

	public static void main(String[] args) {
		
		Properties propSetup=new Properties();
		File jarFile=null;
		String confPath=null;
		
		try {
				jarFile = new File(Configurator.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());		
				confPath=jarFile.getParentFile().getPath() + File.separator+"csnoserv"+File.separator + "system.properties";
				propSetup.load(new FileInputStream(new File(confPath)));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		if(args.length!=2)
			return;
		SNOMEDAgent agent = new SNOMEDAgent();
		
		System.out.println(propSetup.getProperty(Constants.DATA_DIR));
		agent.init(propSetup.getProperty(Constants.DATA_DIR), propSetup.getProperty(Constants.ERROR_LOG_DIR),
				propSetup.getProperty(Constants.SEARCH_RETURNLIMIT) != null
						? Integer.valueOf(propSetup.getProperty(Constants.SEARCH_RETURNLIMIT)) : null,
								propSetup.getProperty(Constants.SUGGEST_RETURNLIMIT) != null
						? Integer.valueOf(propSetup.getProperty(Constants.SUGGEST_RETURNLIMIT)) : null,
								propSetup.getProperty(Constants.TOP_SUGGEST_RETURNLIMIT) != null
						? Integer.valueOf(propSetup.getProperty(Constants.TOP_SUGGEST_RETURNLIMIT)) : null);
		
		if(args[0].equalsIgnoreCase("0"))
			agent.createSNOMEDdb(args[1], true);
		
		if(args[0].equalsIgnoreCase("1"))
			agent.createExtensiondb(args[1], true);
		
		if(args[0].equalsIgnoreCase("2"))
			agent.createRefsetdb(args[1], true);
		
		if(args[0].equalsIgnoreCase("3"))
			agent.createSNOMEDRefsetdb(args[1],true);
		
		

	}

}
