use of org.mifos.framework.fileupload.domain.ClientFileEntity in project head by mifos.
the class ClientFileServiceFileSystem method create.
public boolean create(Integer clientId, InputStream in, UploadedFileDto uploadedFileDto) {
try {
String storageDir = viewOrganizationSettingsServiceFacade.getClientStorageDirectory();
String fileDir = storageDir + File.separator + clientId.toString();
File file = new File(fileDir + File.separator + uploadedFileDto.getName());
if (file.exists() || customerDao.getClientUploadedFileByName(clientId, uploadedFileDto.getName()) != null) {
return update(clientId, in, uploadedFileDto);
}
FileInfoEntity fileInfo = FileStorageManager.createFile(in, fileDir, uploadedFileDto);
hibernateTransactionHelper.startTransaction();
ClientFileEntity clientFile = new ClientFileEntity();
clientFile.setClientId(clientId);
clientFile.setFileInfo(fileInfo);
genericDao.getSession().save(clientFile);
hibernateTransactionHelper.commitTransaction();
} catch (IOException e) {
logger.error("Unable to persist", e);
return false;
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
}
return true;
}
use of org.mifos.framework.fileupload.domain.ClientFileEntity in project head by mifos.
the class ClientFileServiceFileSystem method readAll.
public List<UploadedFileDto> readAll(Integer clientId) {
List<ClientFileEntity> clientFileEntities = customerDao.getClientAllUploadedFiles(clientId);
List<UploadedFileDto> uploadedFiles = new ArrayList<UploadedFileDto>();
for (ClientFileEntity entity : clientFileEntities) {
FileInfoEntity fileInfo = entity.getFileInfo();
Long uploadFileId = entity.getFileId();
String fileName = fileInfo.getName();
String contentType = fileInfo.getContentType();
Integer fileSize = fileInfo.getSize();
String description = fileInfo.getDescription();
java.util.Date uploadDate = fileInfo.getUploadDate();
uploadedFiles.add(new UploadedFileDto(uploadFileId, fileName, contentType, fileSize, description, uploadDate));
}
return uploadedFiles;
}
use of org.mifos.framework.fileupload.domain.ClientFileEntity in project head by mifos.
the class ClientFileServiceFileSystem method delete.
public boolean delete(Integer clientId, Long fileId) {
ClientFileEntity clientFile = customerDao.getUploadedFile(fileId);
if (clientFile != null) {
FileInfoEntity fileInfo = clientFile.getFileInfo();
hibernateTransactionHelper.startTransaction();
genericDao.getSession().delete(clientFile);
hibernateTransactionHelper.commitTransaction();
return FileStorageManager.delete(viewOrganizationSettingsServiceFacade.getClientStorageDirectory() + File.separator + clientId.toString() + File.separator + fileInfo.getName());
} else {
return false;
}
}
use of org.mifos.framework.fileupload.domain.ClientFileEntity in project head by mifos.
the class ClientFileServiceFileSystem method update.
public boolean update(Integer clientId, InputStream in, UploadedFileDto uploadedFileDto) {
ClientFileEntity clientFile = customerDao.getClientUploadedFileByName(clientId, uploadedFileDto.getName());
if (clientFile == null) {
return create(clientId, in, uploadedFileDto);
}
try {
String storageDir = viewOrganizationSettingsServiceFacade.getClientStorageDirectory();
String fileDir = storageDir + File.separator + clientId.toString();
FileInfoEntity updateFileInfo = FileStorageManager.updateFile(in, fileDir, clientFile.getFileInfo(), uploadedFileDto);
if (updateFileInfo == null) {
return false;
}
hibernateTransactionHelper.startTransaction();
genericDao.getSession().save(updateFileInfo);
hibernateTransactionHelper.commitTransaction();
} catch (IOException e) {
logger.error("Unable to persist", e);
return false;
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
}
return true;
}
Aggregations