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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations