package com.eactive.eai.apim.apigroup.command;

import com.eactive.eai.apim.apigroup.ApiGroupManager;
import com.eactive.eai.adapter.AdapterManager;
import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.dao.DAOException;
import com.eactive.eai.common.util.Logger;

public class ReloadApiGroupCommand extends Command {
    Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);

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

    @Override
    public Object execute() throws CommandException {
        if (logger.isInfo())
            logger.info(this.name + " is execute");

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

        ApiGroupManager manager = ApiGroupManager.getInstance();
        String apiGroupId = (String) args;

        try {
            manager.reloadApiGroup(apiGroupId);
        } catch (Exception e) {
            String rspErrorCode = "RECEAIMCM002";
            String msg = makeException(rspErrorCode, e);
            if (logger.isError())
                logger.error(msg, e);
            throw new CommandException(msg);
        }
        return "success";
    }

}
