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);