package com.n2bb.sysmonui.availability;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.apache.struts.action.*;
import com.n2bb.util.N2bbSettings;
import com.n2bb.action.AbstractAction;
import com.n2bb.web.util.ListPage;
import com.n2bb.form.ListForm;

/**
 * View/edit server details.
 *
 * @author kmatsuoka
 * @version $Id: EditServerAction.java,v 1.1 2006/08/30 18:34:04 kmehta Exp $
 */
public class EditServerAction extends AbstractAction {
    private static final Log log = LogFactory.getLog(N2bbSettings.N2BB_LOG);

    protected ActionForward executeAction(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionErrors errors = new ActionErrors();
        String name = request.getParameter("name");
        if (name != null) {
            ServerBean server =
                AvailabilityFacade.getInstance().getServer(name);
            request.setAttribute("server", server);
            List newHosts = AvailabilityFacade.getInstance().getAvailableHosts(server);
            request.setAttribute("newHosts", newHosts);
            if (server == null) {
                errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("sysmonui.error.server.notFound"));
            }
        }
        if (!errors.isEmpty()) {
            saveErrors(request, errors);
            return mapping.findForward("failure");
        }
        return mapping.findForward("success");
    }
}
