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.Measure;
import com.vst.service.MeasureManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class MeasureController implements Controller {
private final Log log = LogFactory.getLog(MeasureController.class);
private MeasureManager measureManager = null;
public void setMeasureManager(MeasureManager measureManager) {
this.measureManager = measureManager;
}
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 measureId = request.getParameter("id");
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
boolean hasFatalError = false;
try {
if (measureManager.removeMeasure(measureId)) {
request.setAttribute("message", bundle.getString("measure.deleted"));
} else {
request.setAttribute("errormessage", bundle.getString("measure.isUsed"));
request.setAttribute("refferenceList", measureManager.getConnectedRefferences(measureId));
}
} catch (Exception e) {
hasFatalError = true;
}
if (hasFatalError) {
request.setAttribute("errormessage", bundle.getString("commonMistake"));
}
}
Measure measure = new Measure();
// populate object with request parameters
BeanUtils.populate(measure, request.getParameterMap());
List measures = measureManager.getMeasures(measure);
return new ModelAndView("measureList", Constants.MEASURE_LIST, measures);
}
}