package com.vst.service.impl;
import com.vst.dao.PhotoDao;
import com.vst.model.Photo;
import com.vst.model.PhotoObjectInspection;
import com.vst.model.PhotoOborudovanie;
import com.vst.service.PhotoManager;
import com.vst.util.ImageUtil;
import com.lowagie.text.Image;
import org.hibernate.Hibernate;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.*;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 28.04.2009
* Time: 15:51:55
* To change this template use File | Settings | File Templates.
*/
public class PhotoManagerImpl extends BaseManager implements PhotoManager {
PhotoDao dao;
public void setDao(PhotoDao dao) {
this.dao = dao;
}
public Photo insertPhoto(CommonsMultipartFile file, String currentPath) throws Exception {
Photo photo=new Photo();
if(file!=null && file.getSize()>0)
{
Date date=new Date();
String wayToPhoto=String.valueOf(date.getTime())+".jpg";
OutputStream fl=new FileOutputStream(currentPath+wayToPhoto);
try {
fl.write(file.getBytes());
fl.close();
InputStream inputStream=new FileInputStream(currentPath+wayToPhoto);
photo.setPhotoPlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
photo.setWayToPhoto(wayToPhoto);
} catch (IOException e) {
e.printStackTrace();
}
}
dao.insert(photo);
return photo;
}
public Photo update(Photo photo, CommonsMultipartFile file, String currentPath) throws Exception {
if(file!=null && file.getSize()>0)
{
Date date=new Date();
String wayToPhoto=String.valueOf(date.getTime())+".jpg";
OutputStream fl=new FileOutputStream(currentPath+wayToPhoto);
try {
fl.write(file.getBytes());
fl.close();
InputStream inputStream=new FileInputStream(currentPath+wayToPhoto);
photo.setPhotoPlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
photo.setWayToPhoto(wayToPhoto);
} catch (IOException e) {
e.printStackTrace();
}
}
dao.update(photo);
return photo;
}
public Photo insertPhoto(CommonsMultipartFile file, String currentPath,int w,int h) throws Exception {
Photo photo=new Photo();
if(file!=null && file.getSize()>0)
{
Date date=new Date();
String wayToPhoto=String.valueOf(date.getTime())+".jpg";
OutputStream fl=new FileOutputStream(currentPath+wayToPhoto);
try {
fl.write(file.getBytes());
fl.close();
InputStream inputStream=new FileInputStream(currentPath+wayToPhoto);
photo.setPhotoPlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream,w,h)));
photo.setWayToPhoto(wayToPhoto);
} catch (IOException e) {
e.printStackTrace();
}
}
dao.insert(photo);
return photo;
}
public Photo update(Photo photo, CommonsMultipartFile file, String currentPath,int w,int h) throws Exception {
if(file!=null && file.getSize()>0)
{
Date date=new Date();
String wayToPhoto=String.valueOf(date.getTime())+".jpg";
OutputStream fl=new FileOutputStream(currentPath+wayToPhoto);
try {
fl.write(file.getBytes());
fl.close();
InputStream inputStream=new FileInputStream(currentPath+wayToPhoto);
photo.setPhotoPlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream,w,h)));
photo.setWayToPhoto(wayToPhoto);
} catch (IOException e) {
e.printStackTrace();
}
}
dao.update(photo);
return photo;
}
public void prepareForOpen(Photo photo,String currentPath) throws IOException, SQLException {
FileOutputStream fileOutputStream = new FileOutputStream(currentPath+photo.getWayToPhoto());
Blob blob = photo.getPhotoPlob();
byte[] bufer = new byte[62000];
InputStream inputStream = blob.getBinaryStream();
while (inputStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
inputStream.close();
fileOutputStream.close();
}
public PhotoOborudovanie insertPhotoOborudovanie(CommonsMultipartFile file, String currentPath) throws Exception {
PhotoOborudovanie photo=new PhotoOborudovanie();
if(file.getSize()>0)
{
Date date=new Date();
String wayToPhoto=String.valueOf(date.getTime())+".jpg";
OutputStream fl=new FileOutputStream(currentPath+wayToPhoto);
try {
fl.write(file.getBytes());
fl.close();
InputStream inputStream=new FileInputStream(currentPath+wayToPhoto);
photo.setPhotoPlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
photo.setWayToPhoto(wayToPhoto);
} catch (IOException e) {
e.printStackTrace();
}
}
dao.insert(photo);
return photo;
}
public PhotoOborudovanie update(PhotoOborudovanie photo, CommonsMultipartFile file, String currentPath) throws Exception {
if(file.getSize()>0)
{
Date date=new Date();
String wayToPhoto=String.valueOf(date.getTime())+".jpg";
OutputStream fl=new FileOutputStream(currentPath+wayToPhoto);
try {
fl.write(file.getBytes());
fl.close();
InputStream inputStream=new FileInputStream(currentPath+wayToPhoto);
photo.setPhotoPlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
photo.setWayToPhoto(wayToPhoto);
} catch (IOException e) {
e.printStackTrace();
}
}
dao.update(photo);
return photo;
}
public void prepareForOpen(PhotoOborudovanie photo,String currentPath) throws IOException, SQLException {
FileOutputStream fileOutputStream = new FileOutputStream(currentPath+photo.getWayToPhoto());
Blob blob = photo.getPhotoPlob();
byte[] bufer = new byte[62000];
InputStream inputStream = blob.getBinaryStream();
while (inputStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
inputStream.close();
fileOutputStream.close();
}
public PhotoObjectInspection insertPhotoObjectInspection(CommonsMultipartFile file, String currentPath) throws Exception {
PhotoObjectInspection photo=new PhotoObjectInspection();
if(file.getSize()>0)
{
Date date=new Date();
String wayToPhoto=String.valueOf(date.getTime())+".jpg";
OutputStream fl=new FileOutputStream(currentPath+wayToPhoto);
try {
fl.write(file.getBytes());
fl.close();
InputStream inputStream=new FileInputStream(currentPath+wayToPhoto);
photo.setPhotoPlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
photo.setWayToPhoto(wayToPhoto);
} catch (IOException e) {
e.printStackTrace();
}
}
dao.insert(photo);
return photo;
}
public PhotoObjectInspection update(PhotoObjectInspection photo, CommonsMultipartFile file, String currentPath) throws Exception {
if(file.getSize()>0)
{
Date date=new Date();
String wayToPhoto=String.valueOf(date.getTime())+".jpg";
OutputStream fl=new FileOutputStream(currentPath+wayToPhoto);
try {
fl.write(file.getBytes());
fl.close();
InputStream inputStream=new FileInputStream(currentPath+wayToPhoto);
photo.setPhotoPlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
photo.setWayToPhoto(wayToPhoto);
} catch (IOException e) {
e.printStackTrace();
}
}
dao.update(photo);
return photo;
}
public void prepareForOpen(PhotoObjectInspection photo,String currentPath) throws IOException, SQLException {
FileOutputStream fileOutputStream = new FileOutputStream(currentPath+photo.getWayToPhoto());
Blob blob = photo.getPhotoPlob();
byte[] bufer = new byte[62000];
InputStream inputStream = blob.getBinaryStream();
while (inputStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
inputStream.close();
fileOutputStream.close();
}
public void insert(PhotoOborudovanie photo) {
dao.insert(photo);
}
public void update(PhotoOborudovanie photo) {
dao.update(photo); //To change body of implemented methods use File | Settings | File Templates.
}
public void delete(PhotoOborudovanie photo) {
dao.delete(photo); //To change body of implemented methods use File | Settings | File Templates.
}
public PhotoOborudovanie getByIdPhotoOborudovanie(Integer id) {
return dao.getByIdPhotoOborudovanie(id); //To change body of implemented methods use File | Settings | File Templates.
}
public List getAllPhotoPhotoOborudovanie() {
return dao.getAllPhotoOborudovanie(); //To change body of implemented methods use File | Settings | File Templates.
}
public void insert(Photo photo) {
dao.insert(photo);
}
public void update(Photo photo) {
dao.update(photo); //To change body of implemented methods use File | Settings | File Templates.
}
public void delete(Photo photo) {
dao.delete(photo); //To change body of implemented methods use File | Settings | File Templates.
}
public Photo getByIdPhoto(Integer id) {
return dao.getByIdPhoto(id); //To change body of implemented methods use File | Settings | File Templates.
}
public List getAllPhoto() {
return dao.getAllPhoto(); //To change body of implemented methods use File | Settings | File Templates.
}
public void insert(PhotoObjectInspection photo) {
dao.insert(photo);
}
public void update(PhotoObjectInspection photo) {
dao.update(photo);
}
public void delete(PhotoObjectInspection photo) {
dao.delete(photo);
}
public PhotoObjectInspection getByIdPhotoObjectInspection(Integer id) {
return dao.getByIdPhotoObjectInspection(id); //To change body of implemented methods use File | Settings | File Templates.
}
public List getAllPhotoPhotoObjectInspection() {
return dao.getAllPhotoObjectInspection(); //To change body of implemented methods use File | Settings | File Templates.
}
}