use of org.motechproject.mds.exception.csv.DataExportException in project motech by motech.
the class PdfTableWriter method close.
@Override
public void close() {
try {
float[] relativeWidths = getRelativeWidths();
List<Integer> lastColumnsForPages = calculateLastColumnsForPages(relativeWidths);
resizeColumns(relativeWidths, lastColumnsForPages);
setTableContentOffset(relativeWidths[0]);
dataTable.setWidths(relativeWidths);
dataTable.setLockedWidth(true);
dataTable.setTotalWidth(calculateTotalTableWidth(relativeWidths));
writeTable(lastColumnsForPages);
pdfDocument.close();
} catch (DocumentException e) {
throw new DataExportException("Unable to add a table to the PDF file", e);
} finally {
pdfWriter.close();
}
}
use of org.motechproject.mds.exception.csv.DataExportException in project motech by motech.
the class AbstractMdsExporter method exportData.
protected long exportData(EntityInfo entityInfo, TableWriter writer, String lookupName, QueryParams params, List<String> headers, Map<String, Object> lookupFields, CsvExportCustomizer exportCustomizer) {
final MotechDataService dataService = DataServiceHelper.getDataService(bundleContext, entityInfo.getClassName());
final Map<String, FieldDto> fieldMap = new HashMap<>();
for (FieldDto field : entityInfo.getFieldDtos()) {
fieldMap.put(exportCustomizer.exportDisplayName(field), field);
}
// we must respect field ordering
String[] orderedHeaders = orderHeaders(entityInfo.getAdvancedSettings().getBrowsing(), headers == null ? fieldsToHeaders(entityInfo.getFieldDtos(), exportCustomizer) : headers.toArray(new String[headers.size()]), entityInfo.getFieldDtos(), exportCustomizer);
try {
writer.writeHeader(orderedHeaders);
long rowsExported = 0;
Map<String, String> row = new HashMap<>();
List<Object> instances = StringUtils.isBlank(lookupName) ? dataService.retrieveAll(params) : mdsLookupService.findMany(entityInfo.getClassName(), lookupName, lookupFields, params);
for (Object instance : instances) {
buildCsvRow(row, fieldMap, instance, orderedHeaders, exportCustomizer);
writer.writeRow(row, orderedHeaders);
rowsExported++;
}
return rowsExported;
} catch (IOException e) {
throw new DataExportException("IO Error when writing data", e);
}
}
Aggregations