package com.eactive.eai.agent.b2bextractor;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.b2bextractor.B2BExtractManager;
import com.eactive.eai.common.util.Logger;

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

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

	public Object execute() throws CommandException {
		Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
		if (logger.isInfo())
			logger.info(this.name + " is executed");

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

		String key = null;
		B2BExtractManager manager = B2BExtractManager.getInstance();
		try {
			key = (String) args;
			manager.removeB2BExtract(key);

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

	}

}
