Search in sources :

Example 6 with FileInfoEntity

use of org.mifos.framework.fileupload.domain.FileInfoEntity in project head by mifos.

the class LoanFileServiceFileSystem method readAll.

public List<UploadedFileDto> readAll(Integer accountId) {
    List<LoanFileEntity> loanFileEntities = loanDao.getLoanAllUploadedFiles(accountId);
    List<UploadedFileDto> uploadedFiles = new ArrayList<UploadedFileDto>();
    for (LoanFileEntity entity : loanFileEntities) {
        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;
}
Also used : LoanFileEntity(org.mifos.framework.fileupload.domain.LoanFileEntity) ArrayList(java.util.ArrayList) FileInfoEntity(org.mifos.framework.fileupload.domain.FileInfoEntity) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto)

Example 7 with FileInfoEntity

use of org.mifos.framework.fileupload.domain.FileInfoEntity in project head by mifos.

the class LoanFileServiceFileSystem method delete.

public boolean delete(Integer accountId, Long fileId) {
    LoanFileEntity loanFile = loanDao.getUploadedFile(fileId);
    if (loanFile != null) {
        FileInfoEntity fileInfo = loanFile.getFileInfo();
        hibernateTransactionHelper.startTransaction();
        genericDao.getSession().delete(loanFile);
        hibernateTransactionHelper.commitTransaction();
        return FileStorageManager.delete(viewOrganizationSettingsServiceFacade.getLoanStorageDirectory() + File.separator + accountId.toString() + File.separator + fileInfo.getName());
    } else {
        return false;
    }
}
Also used : LoanFileEntity(org.mifos.framework.fileupload.domain.LoanFileEntity) FileInfoEntity(org.mifos.framework.fileupload.domain.FileInfoEntity)

Example 8 with FileInfoEntity

use of org.mifos.framework.fileupload.domain.FileInfoEntity in project head by mifos.

the class LoanFileServiceFileSystem method update.

public boolean update(Integer accountId, InputStream in, UploadedFileDto uploadedFileDto) {
    LoanFileEntity loanFile = loanDao.getLoanUploadedFileByName(accountId, uploadedFileDto.getName());
    if (loanFile == null) {
        return create(accountId, in, uploadedFileDto);
    }
    try {
        String storageDir = viewOrganizationSettingsServiceFacade.getLoanStorageDirectory();
        String fileDir = storageDir + File.separator + accountId.toString();
        FileInfoEntity updateFileInfo = FileStorageManager.updateFile(in, fileDir, loanFile.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;
}
Also used : LoanFileEntity(org.mifos.framework.fileupload.domain.LoanFileEntity) FileInfoEntity(org.mifos.framework.fileupload.domain.FileInfoEntity) IOException(java.io.IOException) IOException(java.io.IOException)

Example 9 with FileInfoEntity

use of org.mifos.framework.fileupload.domain.FileInfoEntity 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;
}
Also used : ClientFileEntity(org.mifos.framework.fileupload.domain.ClientFileEntity) FileInfoEntity(org.mifos.framework.fileupload.domain.FileInfoEntity) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

FileInfoEntity (org.mifos.framework.fileupload.domain.FileInfoEntity)9 IOException (java.io.IOException)4 ClientFileEntity (org.mifos.framework.fileupload.domain.ClientFileEntity)4 LoanFileEntity (org.mifos.framework.fileupload.domain.LoanFileEntity)4 File (java.io.File)3 ArrayList (java.util.ArrayList)2 UploadedFileDto (org.mifos.dto.screen.UploadedFileDto)2