package com.eactive.eai.agent.businessday;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.util.Logger;
import com.kbstar.eai.common.businessday.BusinessDayManager;
import com.kbstar.eai.common.businessday.BusinessDayVO;

public class AddBusinessDayCommand extends Command {
	private static final long serialVersionUID = 1L;

	public AddBusinessDayCommand(String name) {
		super(name);
	}

	public AddBusinessDayCommand() {
		super("AddBusinessDayCommand");
	}

	public Object execute() throws CommandException {

		Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
		if (logger.isInfo())
			logger.info(this.name + " is executed");

		if (!(args instanceof BusinessDayVO)) {
			String rspErrorCode = "RECEAIMIM001";
			String msg = makeException(rspErrorCode, null);
			if (logger.isError())
				logger.error(msg);
			throw new CommandException(msg);
		}

		BusinessDayVO vo = (BusinessDayVO) args;

		try {
			BusinessDayManager manager = BusinessDayManager.getInstance();
			manager.setMessage(vo);
		} catch (Exception e) {
			String rspErrorCode = "RECEAIMIM002";
			String msg = makeException(rspErrorCode, e);
			if (logger.isError())
				logger.error(msg, e);
			throw new CommandException(msg);
		}
		return "success";
	}

//    public static void main(String[] args) throws Exception
//    {
//        BusinessDayVO vo = new BusinessDayVO(args[0]);
//        Command command = new AddBusinessDayCommand("AddBusinessDayCommand");
//        command.setArgs(vo);
//        AgentUtil.broadcast(command);
//    }
}
