Search in sources :

Example 1 with CustomerPictureEntity

use of org.mifos.customers.client.business.CustomerPictureEntity 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 2 with CustomerPictureEntity

use of org.mifos.customers.client.business.CustomerPictureEntity in project head by mifos.

the class CustomerPersistence method retrievePicture.

public CustomerPictureEntity retrievePicture(final Integer customerId) throws PersistenceException {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("customerId", customerId);
    List queryResult = executeNamedQuery(NamedQueryConstants.GET_CUSTOMER_PICTURE, queryParameters);
    return (CustomerPictureEntity) queryResult.get(0);
}
Also used : CustomerPictureEntity(org.mifos.customers.client.business.CustomerPictureEntity) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

CustomerPictureEntity (org.mifos.customers.client.business.CustomerPictureEntity)2 IOException (java.io.IOException)1 Blob (java.sql.Blob)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ClientPhoto (org.mifos.framework.image.domain.ClientPhoto)1 ImageInfo (org.mifos.framework.image.domain.ImageInfo)1