package com.vst.webapp.action;
import java.util.List;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.beanutils.BeanUtils;
import com.vst.Constants;
import com.vst.model.Parameter;
import com.vst.service.ParameterManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class ParameterController implements Controller {
private final Log log = LogFactory.getLog(PainterController.class);
private ParameterManager parameterManager = null;
public void setParameterManager(ParameterManager parameterManager) {
this.parameterManager = parameterManager;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'handleRequest' method...");
}
if (request.getParameter("edited") != null) {
request.setAttribute("addition", "?edited=1");
}
if (request.getParameter("delete") != null) {
String parameterId = request.getParameter("id");
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
boolean hasFatalError = false;
try {
if (parameterManager.removeParameter(parameterId)) {
request.setAttribute("message", bundle.getString("parameter.deleted"));
} else {
request.setAttribute("errormessage", bundle.getString("parameter.isUsed"));
request.setAttribute("refferenceList", parameterManager.getConnectedRefferences(parameterId));
}
} catch (Exception e) {
hasFatalError = true;
}
if (hasFatalError) {
request.setAttribute("errormessage", bundle.getString("commonMistake"));
}
}
Parameter parameter = new Parameter();
// populate object with request parameters
BeanUtils.populate(parameter, request.getParameterMap());
List parameters = parameterManager.getParameters(parameter);
return new ModelAndView("parameterList", Constants.PARAMETER_LIST, parameters);
}
}