ObjectPhoto objectPhoto = (ObjectPhoto) command;
boolean isNew = (objectPhoto.getPhotoId() == null);
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
BuildingObject buildingObject = buildingObjectManager.getBuildingObject(objectPhoto.getObjectId().toString());
buildingObject.getPhotoes().remove(objectPhoto);
objectPhotoManager.removeObjectPhoto(objectPhoto.getPhotoId().toString());
buildingObject.getPhotoes().remove(objectPhoto);
buildingObjectManager.saveBuildingObject(buildingObject);
saveMessage(request, getText("objectPhoto.deleted", locale));
} else {
MultipartHttpServletRequest multipartRequest =
(MultipartHttpServletRequest) request;
CommonsMultipartFile file =
(CommonsMultipartFile) multipartRequest.getFile("file");
if (file.getSize() > 0) {
String fileName = ImageUtil.getUniqueJPEGFile(request);
FileOutputStream fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + fileName);
fileOutputStream.write(file.getBytes());
fileOutputStream.close();
InputStream imageStream = ImageUtil.scaleImage(new FileInputStream(FileHelper.getCurrentPath(request) + fileName), 400, 400);
fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + fileName);
byte[] bufer = new byte[62000];
while (imageStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
fileOutputStream.close();
objectPhoto.setWayToPhoto(fileName);
objectPhoto.setPhotoBlob(Hibernate.createBlob(new FileInputStream(FileHelper.getCurrentPath(request) + fileName)));
// if (!isNew) {
// objectPhotoManager.evict(objectPhoto);
// }
if (isNew) {
BuildingObject buildingObject = buildingObjectManager.getBuildingObject(objectPhoto.getObjectId().toString());
buildingObject.getPhotoes().add(objectPhoto);
buildingObjectManager.saveBuildingObject(buildingObject);
// objectPhoto.setPhotoPosition(new Integer(buildingObject.getPhotoes().size()));
//
// objectPhotoManager.saveObjectPhoto(objectPhoto);
} else {