Search in sources :

Example 1 with ImageInfo

use of org.mifos.framework.image.domain.ImageInfo in project head by mifos.

the class ClientPhotoServiceFileSystem method delete.

@Override
public boolean delete(Long clientId) {
    ClientPhoto clientPhoto = read(clientId);
    if (clientPhoto == null) {
        return false;
    }
    ImageInfo imageInfo = clientPhoto.getImageInfo();
    hibernateTransactionHelper.startTransaction();
    genericDao.getSession().delete(clientPhoto);
    hibernateTransactionHelper.commitTransaction();
    return ImageStorageManager.delete(imageInfo.getPath());
}
Also used : ClientPhoto(org.mifos.framework.image.domain.ClientPhoto) ImageInfo(org.mifos.framework.image.domain.ImageInfo)

Example 2 with ImageInfo

use of org.mifos.framework.image.domain.ImageInfo in project head by mifos.

the class ClientPhotoServiceFileSystem method update.

@Override
public boolean update(Long clientId, InputStream in) {
    if (in == null) {
        return false;
    }
    ClientPhoto clientPhoto = read(clientId);
    if (clientPhoto == null) {
        return create(clientId, in);
    }
    try {
        ImageInfo updateImageInfo = ImageStorageManager.updateImage(in, clientPhoto.getImageInfo());
        if (updateImageInfo == null) {
            return false;
        }
        hibernateTransactionHelper.startTransaction();
        genericDao.getSession().save(updateImageInfo);
        hibernateTransactionHelper.commitTransaction();
    } catch (IOException e) {
        LOG.error("Unable to persist", e);
        return false;
    } catch (Exception e) {
        throw new BusinessRuleException(ClientConstants.INVALID_PHOTO, new Object[] { e.getMessage() }, e);
    }
    return true;
}
Also used : ClientPhoto(org.mifos.framework.image.domain.ClientPhoto) BusinessRuleException(org.mifos.service.BusinessRuleException) IOException(java.io.IOException) ImageInfo(org.mifos.framework.image.domain.ImageInfo) BusinessRuleException(org.mifos.service.BusinessRuleException) IOException(java.io.IOException)

Example 3 with ImageInfo

use of org.mifos.framework.image.domain.ImageInfo in project head by mifos.

the class ClientPhotoServiceDatabase method create.

@Override
public boolean create(Long clientId, InputStream in) {
    boolean transactionStarted = false;
    if (in == null) {
        return false;
    }
    try {
        //create blob
        final Blob blob = this.createBlob(in);
        //create picture            
        final ImageInfo imageInfo = new ImageInfo();
        imageInfo.setContentType(this.determineContentType(in));
        imageInfo.setLength(blob.length());
        CustomerPictureEntity picture = new CustomerPictureEntity(blob);
        imageInfo.setPicture(picture);
        final ClientPhoto clientPhoto = new ClientPhoto();
        clientPhoto.setClientId(clientId);
        clientPhoto.setImageInfo(imageInfo);
        //save
        hibernateTransactionHelper.startTransaction();
        transactionStarted = true;
        this.genericDao.createOrUpdate(clientPhoto);
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception ex) {
        if (transactionStarted) {
            hibernateTransactionHelper.rollbackTransaction();
        }
        LOG.error("Unable to create picture", ex);
        return false;
    }
    return true;
}
Also used : ClientPhoto(org.mifos.framework.image.domain.ClientPhoto) Blob(java.sql.Blob) CustomerPictureEntity(org.mifos.customers.client.business.CustomerPictureEntity) ImageInfo(org.mifos.framework.image.domain.ImageInfo) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Example 4 with ImageInfo

use of org.mifos.framework.image.domain.ImageInfo in project head by mifos.

the class ClientPhotoServiceDatabase method update.

@Override
public boolean update(Long clientId, InputStream in) {
    boolean transactionStarted = false;
    if (in == null) {
        return false;
    }
    try {
        final ClientPhoto clientPhoto = this.read(clientId);
        if (clientPhoto == null) {
            //create new picture
            return this.create(clientId, in);
        } else {
            //get picture
            final Blob blob = this.createBlob(in);
            final String contentType = this.determineContentType(in);
            //update data
            final ImageInfo imageInfo = clientPhoto.getImageInfo();
            imageInfo.setContentType(contentType);
            imageInfo.setLength(blob.length());
            imageInfo.getCustomerPictureEntity().setPicture(blob);
            this.hibernateTransactionHelper.startTransaction();
            transactionStarted = true;
            this.genericDao.createOrUpdate(clientPhoto);
            this.hibernateTransactionHelper.commitTransaction();
        }
    } catch (Exception ex) {
        if (transactionStarted) {
            hibernateTransactionHelper.rollbackTransaction();
        }
        LOG.error("Unable to update picture", ex);
        return false;
    }
    return true;
}
Also used : ClientPhoto(org.mifos.framework.image.domain.ClientPhoto) Blob(java.sql.Blob) ImageInfo(org.mifos.framework.image.domain.ImageInfo) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Example 5 with ImageInfo

use of org.mifos.framework.image.domain.ImageInfo in project head by mifos.

the class ClientPhotoServiceFileSystem method create.

@Override
public boolean create(Long clientId, InputStream in) {
    try {
        ImageInfo imInfo = ImageStorageManager.createImage(in, clientId.toString());
        if (imInfo == null) {
            return false;
        }
        hibernateTransactionHelper.startTransaction();
        ClientPhoto clientPhoto = new ClientPhoto();
        clientPhoto.setClientId(clientId);
        clientPhoto.setImageInfo(imInfo);
        genericDao.getSession().save(clientPhoto);
        hibernateTransactionHelper.commitTransaction();
    } catch (IOException e) {
        LOG.error("Unable to persist", e);
        return false;
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(ClientConstants.INVALID_PHOTO, new Object[] { e.getMessage() }, e);
    }
    return true;
}
Also used : ClientPhoto(org.mifos.framework.image.domain.ClientPhoto) BusinessRuleException(org.mifos.service.BusinessRuleException) IOException(java.io.IOException) ImageInfo(org.mifos.framework.image.domain.ImageInfo) BusinessRuleException(org.mifos.service.BusinessRuleException) IOException(java.io.IOException)

Aggregations

ImageInfo (org.mifos.framework.image.domain.ImageInfo)8 ClientPhoto (org.mifos.framework.image.domain.ClientPhoto)7 IOException (java.io.IOException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Blob (java.sql.Blob)2 SQLException (java.sql.SQLException)2 Test (org.junit.Test)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 File (java.io.File)1 CustomerPictureEntity (org.mifos.customers.client.business.CustomerPictureEntity)1