id = -1;
}
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline; filename=" + module + ".pdf"); // TODO add more information about the entity into the filename.
final Dto dto = readService.get(module, id);
final ModuleDto moduleDto = config.getModuleDtos().get(module);
document.add(new Paragraph(moduleDto.getTitle(), new Font(FontFamily.HELVETICA, 20, Font.BOLD)));
for (final Entry<String, Serializable> entry : dto.getAllData().entrySet()) {
if ("id".equals(entry.getKey()) || entry.getKey().endsWith("_resolved")) {
continue;
}
final String label = moduleDto.getFieldById(entry.getKey()).getLabel();
final String value;
if (dto.getAllData().containsKey(entry.getKey() + "_resolved")) {
final Dto resolved = (Dto) dto.getAllData().get(entry.getKey() + "_resolved");
value = String.valueOf(resolved.get("name"));
} else {
value = null == entry.getValue() ? "-" : String.valueOf(entry.getValue());
}
if (entry.getValue() instanceof List<?>) {
if (!((List<?>)entry.getValue() ).isEmpty()) {
final List<Dto> list = (List<Dto>) entry.getValue();
final ModuleDto listModuleDto = config.getModuleDtos().get(list.get(0).getModule());
PdfPTable table = new PdfPTable(listModuleDto.getListFieldIds().length);
table.setHeaderRows(1);
for (final String col: listModuleDto.getListFieldIds()) {
final String colHeader = listModuleDto.getFieldById(col).getLabel();
table.addCell(new Phrase(colHeader, new Font(FontFamily.HELVETICA, 12, Font.BOLD)));
}
for (int i = 0; i < list.size(); i++) {
for (final String col: listModuleDto.getListFieldIds()) {
final String colValue;
if (list.get(i).getAllData().containsKey(col + "_resolved")) {
final Dto resolved = (Dto) list.get(i).get(col + "_resolved");
colValue = String.valueOf(resolved.get("name"));
} else {
colValue = String.valueOf(list.get(i).get(col));
}
if ("true".equals(colValue) || "false".equals(colValue)) {