use of it.cnr.si.cool.jconon.model.ApplicationModel in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method printConvocazione.
public byte[] printConvocazione(Session cmisSession, Folder application, String contextURL, Locale locale, String tipoSelezione, String luogo, Calendar data, Boolean testoLibero, String note, String firma) throws CMISApplicationException {
ApplicationModel applicationBulk = new ApplicationModel(application, cmisSession.getDefaultContext(), i18nService.loadLabels(locale), contextURL, false);
applicationBulk.getProperties().put("tipoSelezione", tipoSelezione);
applicationBulk.getProperties().put("luogo", luogo);
applicationBulk.getProperties().put("data", data);
applicationBulk.getProperties().put("note", note);
applicationBulk.getProperties().put("firma", firma);
applicationBulk.getProperties().put("testoLibero", testoLibero);
final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(GregorianCalendar.class, new JsonSerializer<GregorianCalendar>() {
@Override
public JsonElement serialize(GregorianCalendar src, Type typeOfSrc, JsonSerializationContext context) {
return context.serialize(src.getTime());
}
}).create();
String json = "{\"properties\":" + gson.toJson(applicationBulk.getProperties()) + "}";
LOGGER.debug(json);
try {
Map<String, Object> parameters = new HashMap<String, Object>();
JRDataSource datasource = new JsonDataSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), "properties");
JRGzipVirtualizer vir = new JRGzipVirtualizer(100);
final ResourceBundle resourceBundle = ResourceBundle.getBundle("net.sf.jasperreports.view.viewer", locale);
parameters.put(JRParameter.REPORT_LOCALE, locale);
parameters.put(JRParameter.REPORT_RESOURCE_BUNDLE, resourceBundle);
parameters.put(JRParameter.REPORT_DATA_SOURCE, datasource);
parameters.put(JRParameter.REPORT_VIRTUALIZER, vir);
parameters.put("DIR_IMAGE", new ClassPathResource(PRINT_RESOURCE_PATH).getPath());
parameters.put("SUBREPORT_DIR", new ClassPathResource(PRINT_RESOURCE_PATH).getPath());
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
parameters.put(JRParameter.REPORT_CLASS_LOADER, classLoader);
JasperReport jasperReport = cacheRepository.jasperReport(PRINT_RESOURCE_PATH + "convocazione.jrxml", jasperCompileManager());
JasperPrint jasperPrint = jasperFillManager().fill(jasperReport, parameters);
return JasperExportManager.exportReportToPdf(jasperPrint);
} catch (Exception e) {
throw new CMISApplicationException("Error in JASPER", e);
}
}
Aggregations