Search in sources :

Example 1 with ReleaseExportFile

use of org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile in project oc-explorer by devgateway.

the class ExcelGenerator method getExcelDownload.

/**
 * Method that returns a byte array with excel export.
 *
 * @param filter
 * @return
 * @throws IOException
 */
@Cacheable
public byte[] getExcelDownload(final YearFilterPagingRequest filter) throws IOException {
    PageRequest pageRequest = new PageRequest(filter.getPageNumber(), filter.getPageSize(), Sort.Direction.ASC, "id");
    List<Release> releases = mongoTemplate.find(query(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)).with(pageRequest), Release.class);
    ExcelFile releaseExcelFile = new ReleaseExportFile(releases);
    Workbook workbook = releaseExcelFile.createWorkbook();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    workbook.write(baos);
    byte[] bytes = baos.toByteArray();
    return bytes;
}
Also used : ReleaseExportFile(org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile) PageRequest(org.springframework.data.domain.PageRequest) ExcelFile(org.devgateway.ocds.persistence.mongo.excel.ExcelFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Release(org.devgateway.ocds.persistence.mongo.Release) Workbook(org.apache.poi.ss.usermodel.Workbook) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with ReleaseExportFile

use of org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile in project ocvn by devgateway.

the class ExcelGenerator method getExcelDownload.

/**
 * Method that returns a byte array with excel export.
 *
 * @param filter
 * @return
 * @throws IOException
 */
@Cacheable
public byte[] getExcelDownload(final YearFilterPagingRequest filter) throws IOException {
    PageRequest pageRequest = new PageRequest(filter.getPageNumber(), filter.getPageSize(), Sort.Direction.ASC, "id");
    List<Release> releases = mongoTemplate.find(query(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)).with(pageRequest), Release.class);
    ExcelFile releaseExcelFile = new ReleaseExportFile(releases);
    Workbook workbook = releaseExcelFile.createWorkbook();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    workbook.write(baos);
    byte[] bytes = baos.toByteArray();
    return bytes;
}
Also used : ReleaseExportFile(org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile) PageRequest(org.springframework.data.domain.PageRequest) ExcelFile(org.devgateway.ocds.persistence.mongo.excel.ExcelFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Release(org.devgateway.ocds.persistence.mongo.Release) Workbook(org.apache.poi.ss.usermodel.Workbook) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 Release (org.devgateway.ocds.persistence.mongo.Release)2 ExcelFile (org.devgateway.ocds.persistence.mongo.excel.ExcelFile)2 ReleaseExportFile (org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 PageRequest (org.springframework.data.domain.PageRequest)2