package com.eactive.eai.agent.bizkey;

import java.util.Vector;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.bizkey.BizKeyManager;
import com.eactive.eai.common.util.Logger;

/**
 * 업무필드 추출 서비스리스트 메모리 동기화 Command 
 * - 오픈뱅킹 EAIServiceLoader_312에서 사용
 * 
 * @author 	openbanking
 * @since		2019.08	
 */
public class ReloadBizKeyListCommand extends Command {

	private static final long serialVersionUID = 1L;

	public ReloadBizKeyListCommand() {
		super("ReloadBizKeyListCommand");
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public Object execute() throws CommandException {
		Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
        if (logger.isInfo()) logger.info(this.name + " is executed");
        
        if( !(args instanceof Vector) ) {
            String rspErrorCode = "RECEAIMCM001";
            String msg = makeException(rspErrorCode, null);
            if (logger.isError()) logger.error(msg);
            throw new CommandException(msg);
        }
        
        BizKeyManager manager = BizKeyManager.getInstance();
        try {
        	Vector keyNameVt = (Vector)args;
        	String keyName ="";
        	for(int i=0; i<keyNameVt.size(); i++) {
        		keyName = (String)keyNameVt.get(i);
        		// BizKeyManager를 변경하지 않고 exrClsNm = {TR, AK} 정의 호출
        		manager.reload(keyName, "TR");
                manager.reload(keyName, "AK");
                if(logger.isWarn()) 
                	logger.warn(this.name + "] "+keyName+" Reload.");
        	}
        } catch (Exception e) {
        	String rspErrorCode = "RECEAIMCM002";
            String msg = makeException(rspErrorCode, e);
            if (logger.isError()) logger.error(msg,e);
            throw new CommandException(msg);
        }
        
        return "success";
	}
}
