package kr.co.kihyun.beans.batch;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GroupInfoConnector {

	private static final Logger LOG = LoggerFactory.getLogger(GroupConinfoUp.class);
    private ResultSet rs = null;
    private int count = 0;
    PreparedStatement pstmt = null;
    Statement stmt = null;
    PrintWriter out=null;

    public String[] getDeptFullTextData(int start) {
    	String deptArr[] = null;
    	String url = "http://dev-cmmnn-api.knu.ac.kr:9080/api/cmmnn/support/itttn/selectlistitttn.knu";
    	
    	HttpClient client = new HttpClient();
//        client.setHttpHost("gpd.hi.co.kr");
//        client.setHttpLoginURL("/names.nsf?login");
//        client.setHttpLogoutURL("/names.nsf?logout");
        client.setHttpPort("80");
        client.setHttpProtocol("http");
        client.setHttpUserID("ucpostadmin");
        client.setHttpUserPassword("!ucPost12#$");
        client.isAnonymous(false);
        client.isDomino(true);
        client.initialize();
        client.requestLogin();
	
    	
        if (client.getHttpStatus().equalsIgnoreCase("0")) {
    		String data = client.getData(url);
            LOG.info("부서 동기화 주소 : " + client.getRequestedUrl());
//                System.out.println("##### client.getData() : " +  data);
            deptArr = data.split("¶");
            LOG.info("부서 COUNT:" + deptArr.length);
        	
        }
        client.requestLogout();
        return deptArr;
    }
    
    public String[] getUserFullTextData(int start) {
    	String userArr[] = null;
    	String url = "http://dev-cmmnn-api.knu.ac.kr:9080/openapi/cmmnn/support/user/selectlistidntcno.knu";
    	
    	HttpClient client = new HttpClient();
//        client.setHttpHost("gpd.hi.co.kr");
//        client.setHttpLoginURL("/names.nsf?login");
//        client.setHttpLogoutURL("/names.nsf?logout");
        client.setHttpPort("80");
        client.setHttpProtocol("http");
        //client.setHttpUserID("ucpostadmin");
        //client.setHttpUserPassword("!ucPost12#$");
        //client.isAnonymous(false);
        //client.isDomino(true);
        //client.initialize();
        //client.requestLogin();
        
        if (client.getHttpStatus().equalsIgnoreCase("0")) {
        	String data = client.getData(url);
        	LOG.info("사용자 동기화 주소 : " + client.getRequestedUrl());
//            System.out.println("##### client.getData() : " +  data);
            
            userArr = data.split("¶");
            LOG.info("사용자 COUNT : " + userArr.length);
        }
        client.requestLogout();
        return userArr;
    }
}
