package com.vst.webapp.action;
import com.vst.model.ObjectInspection;
import com.vst.model.PipelineSubtype;
import com.vst.service.ObjectInspectionManager;
import com.vst.service.PhotoManager;
import com.vst.util.FileHelper;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 28.04.2009
* Time: 16:37:42
* To change this template use File | Settings | File Templates.
*/
public class LookObjectInspectionController implements Controller {
ObjectInspectionManager objectInspectionManager;
PhotoManager photoManager;
public void setPhotoManager(PhotoManager photoManager) {
this.photoManager = photoManager;
}
public void setObjectInspectionManager(ObjectInspectionManager objectInspectionManager) {
this.objectInspectionManager = objectInspectionManager;
}
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView mav = new ModelAndView("lookObjectInspection");
Integer page = new Integer(0);
Integer pageCount = new Integer(1);
if (httpServletRequest.getParameter("page") != null) {
page = (Integer) Integer.parseInt(httpServletRequest.getParameter("page"));
}
if (httpServletRequest.getParameter("delete") != null) {
Integer id = (Integer) Integer.parseInt(httpServletRequest.getParameter("objectId"));
ObjectInspection obj = objectInspectionManager.getObjectInspectionBy(id);
objectInspectionManager.deleteObjectInspection(obj);
}
List list = objectInspectionManager.getListObjectInspection(page);
for (int i = 0; i < list.size(); i++) {
ObjectInspection objectInspection = (ObjectInspection) list.get(i);
photoManager.prepareForOpen(objectInspection.getDemand(), FileHelper.getCurrentPath(httpServletRequest));
photoManager.prepareForOpen(objectInspection.getCertificate(), FileHelper.getCurrentPath(httpServletRequest));
}
pageCount = (Integer) objectInspectionManager.getListObjectInspection().size();
if (pageCount.intValue() == 0) {
pageCount = new Integer(1);
}
if ((pageCount.intValue() % 10) > 0) {
pageCount = (Integer) (1 + (pageCount.intValue() / 10));
} else {
pageCount = (Integer) (pageCount.intValue() / 10);
}
System.out.println("pageCount = " + pageCount);
mav.addObject("page", page);
mav.addObject("pageCount", pageCount);
mav.addObject("objectList", list);
objectInspectionManager.fillQuestionsLists(list);
return mav; //To change body of implemented methods use File | Settings | File Templates.
}
}