Search in sources :

Example 1 with FileInfoEntity

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

Example 2 with FileInfoEntity

use of org.mifos.framework.fileupload.domain.FileInfoEntity 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;
}
Also used : ClientFileEntity(org.mifos.framework.fileupload.domain.ClientFileEntity) ArrayList(java.util.ArrayList) FileInfoEntity(org.mifos.framework.fileupload.domain.FileInfoEntity) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto)

Example 3 with FileInfoEntity

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

Example 4 with FileInfoEntity

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

the class FileStorageManager method createFile.

public static FileInfoEntity createFile(InputStream in, String fileDir, UploadedFileDto uploadedFileDto) throws IOException {
    byte[] data = InputStreamUtils.getBytes(in);
    File file = new File(fileDir + File.separator + uploadedFileDto.getName());
    FileUtils.touch(file);
    FileUtils.writeByteArrayToFile(file, data);
    FileInfoEntity fileInfo = new FileInfoEntity();
    fileInfo.setName(uploadedFileDto.getName());
    fileInfo.setContentType(uploadedFileDto.getContentType());
    fileInfo.setSize(data.length);
    fileInfo.setDescription(uploadedFileDto.getDescription());
    fileInfo.setUploadDate(DateUtils.getCurrentJavaDateTime());
    return fileInfo;
}
Also used : FileInfoEntity(org.mifos.framework.fileupload.domain.FileInfoEntity) File(java.io.File)

Example 5 with FileInfoEntity

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

the class LoanFileServiceFileSystem method create.

public boolean create(Integer accountId, InputStream in, UploadedFileDto uploadedFileDto) {
    try {
        String storageDir = viewOrganizationSettingsServiceFacade.getLoanStorageDirectory();
        String fileDir = storageDir + File.separator + accountId.toString();
        File file = new File(fileDir + File.separator + uploadedFileDto.getName());
        if (file.exists() || loanDao.getLoanUploadedFileByName(accountId, uploadedFileDto.getName()) != null) {
            return update(accountId, in, uploadedFileDto);
        }
        FileInfoEntity fileInfo = FileStorageManager.createFile(in, fileDir, uploadedFileDto);
        hibernateTransactionHelper.startTransaction();
        LoanFileEntity loanFile = new LoanFileEntity();
        loanFile.setLoanId(accountId);
        loanFile.setFileInfo(fileInfo);
        genericDao.getSession().save(loanFile);
        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) File(java.io.File) 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