BindException errors) throws Exception {
ModelAndView mav = new ModelAndView(getSuccessView());
Expert expert = (Expert) command;
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
CommonsMultipartFile frontFile = (CommonsMultipartFile) multipartRequest.getFile("frontFile");
CommonsMultipartFile backFile = (CommonsMultipartFile) multipartRequest.getFile("backFile");
if (expert.getExpertId() != null) {
String dateNew;
Date d;
d = expert.getDataComplite();
// d.setMonth(d.getMonth()); ?? for what this code
expert.setDataComplite(d);
dateNew = StringUtil.formatDate(d);
expert.setDateForLook(dateNew);
d = expert.getDataStart();
// d.setMonth(d.getMonth());
expert.setDataStart(d);
dateNew = StringUtil.formatDate(d);
expert.setStartDateForLook(dateNew);
if (frontFile.getSize() > 0) {
Date date = new Date();
String wayToPhoto = String.valueOf(date.getTime()) + ".jpg";
OutputStream fl = null;
fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
fl.write(frontFile.getBytes());
fl.close();
InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
expert.setFrontExpertBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
expert.setFrontWayToPhoto(wayToPhoto);
} else {
Expert ex = expertManager.getExpertById(expert.getExpertId());
expert.setFrontExpertBlob(ex.getFrontExpertBlob());
expert.setFrontWayToPhoto(ex.getFrontWayToPhoto());
}
if (backFile.getSize() > 0) {
Date date = new Date();
String wayToPhoto = String.valueOf(date.getTime()) + ".jpg";
OutputStream fl = null;
fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
fl.write(backFile.getBytes());
fl.close();
InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
expert.setBackExpertBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
expert.setBackWayToPhoto(wayToPhoto);
} else {
Expert ex = expertManager.getExpertById(expert.getExpertId());
if (ex.getBackExpertBlob()!=null && ex.getBackWayToPhoto()!=null){
expert.setBackExpertBlob(ex.getBackExpertBlob());
expert.setBackWayToPhoto(ex.getBackWayToPhoto());
} else{
expert.setBackWayToPhoto("no photo");
}
}
expertManager.updateExpert(expert);
if (expert.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + expert.getExpertId() + "&fieldId=" + request.getParameter("fieldId"));
}
} else {
Date d = expert.getDataComplite();
// d.setMonth(d.getMonth());
expert.setDataComplite(d);
String dateNew = StringUtil.formatDate(d);
expert.setDateForLook(dateNew);
d = expert.getDataStart();
// d.setMonth(d.getMonth());
expert.setDataComplite(d);
dateNew = StringUtil.formatDate(d);
expert.setStartDateForLook(dateNew);
if (frontFile.getSize() > 0) {
Date date = new Date();
String wayToPhoto = String.valueOf(date.getTime()) + ".jpg";
OutputStream fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
fl.write(frontFile.getBytes());
fl.close();
InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
expert.setFrontExpertBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
expert.setFrontWayToPhoto(wayToPhoto);
}
if (backFile.getSize() > 0) {
Date date = new Date();
String wayToPhoto = String.valueOf(date.getTime()) + ".jpg";
OutputStream fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
fl.write(backFile.getBytes());
fl.close();
InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
expert.setBackExpertBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
expert.setBackWayToPhoto(wayToPhoto);
}else{
expert.setBackWayToPhoto("no photo");
}
expertManager.insertExpert(expert);
mav.addObject("expert", new Expert());
mav.addObject("result", new Integer(1));
if (expert.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + expert.getExpertId() + "&fieldId=" + request.getParameter("fieldId"));