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.DefectZone;
import com.vst.service.DefectZoneManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class DefectZoneController implements Controller {
private final Log log = LogFactory.getLog(DefectZoneController.class);
private DefectZoneManager defectZoneManager = null;
public void setDefectZoneManager(DefectZoneManager defectZoneManager) {
this.defectZoneManager = defectZoneManager;
}
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");
}
String pageNumber = request.getParameter("d-6604929-p");
if (pageNumber != null) {
request.setAttribute("pageNumber", "d-6604929-p=" + pageNumber);
}
if (request.getParameter("delete") != null) {
String defectZoneId = request.getParameter("id");
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
boolean hasFatalError = false;
try {
if (defectZoneManager.removeDefectZone(defectZoneId)) {
request.setAttribute("message", bundle.getString("defectZone.deleted"));
} else {
request.setAttribute("errormessage", bundle.getString("defectZone.isUsed"));
request.setAttribute("refferenceList", defectZoneManager.getConnectedRefferences(defectZoneId));
}
} catch (Exception e) {
hasFatalError = true;
}
if (hasFatalError) {
request.setAttribute("errormessage", bundle.getString("commonMistake"));
}
}
DefectZone defectZone = new DefectZone();
// populate object with request parameters
BeanUtils.populate(defectZone, request.getParameterMap());
List defectZones = defectZoneManager.getDefectZones(defectZone);
return new ModelAndView("defectZoneList", Constants.DEFECTZONE_LIST, defectZones);
}
}