HttpServletResponse response,
Object command,
BindException errors) throws Exception, SQLException {
ModelAndView mav = new ModelAndView(getSuccessView());
PipeLineElementDefect pipeLineElementDefect = (PipeLineElementDefect) command;
Integer elementId = Integer.valueOf(request.getSession().getAttribute("pipeElementId").toString());
PipeLineElement pipeLineElement = pipeLineElementManager.getPipeLineElementById(elementId);
pipeLineElementDefect.setDangerCategory(dangerCategoryManager.getDangerCategory(String.valueOf(pipeLineElementDefect.getDangerCategory().getDangerCategoryId())));
pipeLineElementDefect.setDefectType(defectTypeManager.getDefectType(String.valueOf(pipeLineElementDefect.getDefectType().getDefectTypeId())));
if (pipeLineElementDefect.getDefectVarity().getVarityId()!=null && pipeLineElementDefect.getDefectVarity().getVarityId().longValue()!=-1){
pipeLineElementDefect.setDefectVarity(defectVarityManager.getDefectVarity(String.valueOf(pipeLineElementDefect.getDefectVarity().getVarityId())));
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
CommonsMultipartFile ffile = (CommonsMultipartFile) multipartRequest.getFile("firstPhoto.file");
CommonsMultipartFile sfile = (CommonsMultipartFile) multipartRequest.getFile("secondPhoto.file");
if (pipeLineElementDefect.getDefectId() != null) {
pipeLineElementDefect = pipeLineElementDefectManager.getPipeLineElementDefectById(pipeLineElementDefect.getDefectId());
Photo photo = photoManager.getByIdPhoto(pipeLineElementDefect.getFirstPhoto().getPhotoId());
photoManager.update(photo, ffile, FileHelper.getCurrentPath(request));
photo = photoManager.getByIdPhoto(pipeLineElementDefect.getSecondPhoto().getPhotoId());
photoManager.update(photo, sfile, FileHelper.getCurrentPath(request));
pipeLineElementDefectManager.update(pipeLineElementDefect);
return new ModelAndView("redirect:/pipeLineElementDefectList.html?objectId=" + request.getParameter("objectId") + "&detailType=" + request.getParameter("detailType") + "&pipeElementId=" + elementId);
} else {
if (ffile != null && ffile.getSize() > 0) {
Photo photo = photoManager.insertPhoto(ffile, FileHelper.getCurrentPath(request));
pipeLineElementDefect.setFirstPhoto(photo);
} else {
Photo photo = new Photo();
photo.setWayToPhoto("no photo");
photoManager.insert(photo);
pipeLineElementDefect.setFirstPhoto(photo);
}
if (sfile != null && sfile.getSize() > 0) {
Photo photo = photoManager.insertPhoto(sfile, FileHelper.getCurrentPath(request));
pipeLineElementDefect.setSecondPhoto(photo);
} else {
Photo photo = new Photo();
photo.setWayToPhoto("no photo");
photoManager.insert(photo);
pipeLineElementDefect.setSecondPhoto(photo);
}
pipeLineElementDefectManager.insert(pipeLineElementDefect);
pipeLineElement.getPipeLineElementDefectList().add(pipeLineElementDefect);
pipeLineElementManager.update(pipeLineElement);
mav.addObject("result", new Integer(1));
}
mav.addObject("objectId", request.getParameter("objectId"));
mav.addObject("detailType", request.getParameter("detailType"));
mav.addObject("pipeElementId", elementId);
mav.addObject("pipeLineElementDefect", new PipeLineElementDefect());
return mav;
}