Search in sources :

Example 11 with ApplicationModel

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);
    }
}
Also used : JsonDataSource(net.sf.jasperreports.engine.data.JsonDataSource) ApplicationModel(it.cnr.si.cool.jconon.model.ApplicationModel) JRGzipVirtualizer(net.sf.jasperreports.engine.fill.JRGzipVirtualizer) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) ClassPathResource(org.springframework.core.io.ClassPathResource) JSONException(org.json.JSONException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) WriterException(com.google.zxing.WriterException) ParseException(java.text.ParseException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) ACLType(it.cnr.cool.cmis.model.ACLType) Type(java.lang.reflect.Type) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject)

Aggregations

ApplicationModel (it.cnr.si.cool.jconon.model.ApplicationModel)11 WriterException (com.google.zxing.WriterException)10 ACLType (it.cnr.cool.cmis.model.ACLType)10 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)10 CMISApplicationException (it.cnr.cool.web.scripts.exception.CMISApplicationException)10 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)10 Type (java.lang.reflect.Type)10 ParseException (java.text.ParseException)10 JsonDataSource (net.sf.jasperreports.engine.data.JsonDataSource)10 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)10 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 PDImageXObject (org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject)10 JSONException (org.json.JSONException)10 JSONObject (org.json.JSONObject)10 ClassPathResource (org.springframework.core.io.ClassPathResource)10 JRGzipVirtualizer (net.sf.jasperreports.engine.fill.JRGzipVirtualizer)9 CMISUser (it.cnr.cool.security.service.impl.alfresco.CMISUser)4 SimpleExporterInput (net.sf.jasperreports.export.SimpleExporterInput)4 SimpleOutputStreamExporterOutput (net.sf.jasperreports.export.SimpleOutputStreamExporterOutput)4