use of net.sf.jasperreports.engine.data.JsonDataSource in project jberet-support by jberet.
the class JasperReportsBatchlet method getJrDataSource.
protected JRDataSource getJrDataSource() throws IOException, JRException {
if (resource != null) {
final String res = resource.toLowerCase();
resourceInputStream = ItemReaderWriterBase.getInputStream(resource, false);
if (res.endsWith(".csv")) {
final JRCsvDataSource csvDataSource = charset == null ? new JRCsvDataSource(resourceInputStream) : new JRCsvDataSource(resourceInputStream, charset);
setCommonJRDataSourceProperties(csvDataSource);
if (useFirstRowAsHeader != null) {
csvDataSource.setUseFirstRowAsHeader(Boolean.parseBoolean(useFirstRowAsHeader));
}
if (recordDelimiter != null) {
csvDataSource.setRecordDelimiter(recordDelimiter);
}
if (fieldDelimiter != null) {
csvDataSource.setFieldDelimiter(fieldDelimiter.trim().charAt(0));
}
if (columnNames != null) {
csvDataSource.setColumnNames(columnNames);
}
return csvDataSource;
}
if (res.endsWith(".xls")) {
final XlsDataSource xlsDataSource = new XlsDataSource(resourceInputStream);
setCommonJRDataSourceProperties(xlsDataSource);
if (columnNames != null) {
xlsDataSource.setColumnNames(columnNames);
}
if (useFirstRowAsHeader != null) {
xlsDataSource.setUseFirstRowAsHeader(Boolean.parseBoolean(useFirstRowAsHeader));
}
return xlsDataSource;
}
if (res.endsWith(".xlsx")) {
final JRXlsxDataSource jrXlsxDataSource = new JRXlsxDataSource(resourceInputStream);
setCommonJRDataSourceProperties(jrXlsxDataSource);
if (columnNames != null) {
jrXlsxDataSource.setColumnNames(columnNames);
}
if (useFirstRowAsHeader != null) {
jrXlsxDataSource.setUseFirstRowAsHeader(Boolean.parseBoolean(useFirstRowAsHeader));
}
return jrXlsxDataSource;
}
if (res.endsWith(".xml")) {
final JRXmlDataSource jrXmlDataSource = new JRXmlDataSource(resourceInputStream);
setCommonJRDataSourceProperties(jrXmlDataSource);
return jrXmlDataSource;
}
if (res.endsWith(".json")) {
final JsonDataSource jsonDataSource = new JsonDataSource(resourceInputStream);
setCommonJRDataSourceProperties(jsonDataSource);
return jsonDataSource;
}
throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, resource, "resource");
} else {
if (jrDataSourceInstance != null && !jrDataSourceInstance.isUnsatisfied()) {
return jrDataSourceInstance.get();
}
}
return new JREmptyDataSource();
}
use of net.sf.jasperreports.engine.data.JsonDataSource in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getRicevutaReportModel.
@SuppressWarnings({ "unchecked", "deprecation" })
public byte[] getRicevutaReportModel(Session cmisSession, Folder application, String contextURL, String nameRicevutaReportModel, boolean immediate) throws CMISApplicationException {
Folder call = application.getFolderParent();
Locale locale = Locale.ITALY;
Properties props = i18nService.loadLabels(locale);
props.putAll(competitionService.getDynamicLabels(call, cmisSession));
ApplicationModel applicationModel = new ApplicationModel(application, cmisSession.getDefaultContext(), props, contextURL);
try {
CMISUser applicationUser = userService.loadUserForConfirm(application.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()));
applicationModel.getProperties().put("jasperReport:user_matricola", applicationUser.getMatricola());
applicationModel.getProperties().put("jasperReport:user_email_comunicazione", applicationUser.getEmail());
applicationModel.getProperties().put("jconon_application:objectId", application.getId());
} catch (CoolUserFactoryException e) {
LOGGER.error("User not found", e);
}
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();
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_ASSOCIATIONS.value()) != null) {
applicationModel.getProperties().put("allegati", getAllegati(application, JCONONPolicyType.JCONON_ATTACHMENT_GENERIC_DOCUMENT, cmisSession, applicationModel));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM.value()) != null) {
applicationModel.getProperties().put("curriculum", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM.value()), application, cmisSession, applicationModel));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM_ULTERIORE.value()) != null) {
applicationModel.getProperties().put("curriculum_ulteriore", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM_ULTERIORE.value()), application, cmisSession, applicationModel));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()) != null) {
applicationModel.getProperties().put("prodotti", getProdotti(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()), application, JCONONPolicyType.PEOPLE_NO_SELECTED_PRODUCT, cmisSession, applicationModel));
applicationModel.getProperties().put("prodottiScelti", getProdotti(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()), application, JCONONPolicyType.PEOPLE_SELECTED_PRODUCT, cmisSession, applicationModel));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_SCHEDE_ANONIME.value()) != null) {
applicationModel.getProperties().put("schedeAnonime", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_SCHEDE_ANONIME.value()), application, cmisSession, applicationModel));
}
applicationModel.getProperties().put(Dichiarazioni.dichiarazioni.name(), getDichiarazioni(bulkInfoService.find(application.getType().getId()), application, JCONONPropertyIds.CALL_ELENCO_ASPECTS, applicationModel, Dichiarazioni.dichiarazioni));
applicationModel.getProperties().put(Dichiarazioni.datiCNR.name(), getDichiarazioni(bulkInfoService.find(application.getType().getId()), application, JCONONPropertyIds.CALL_ELENCO_ASPECTS_SEZIONE_CNR, applicationModel, Dichiarazioni.datiCNR));
applicationModel.getProperties().put(Dichiarazioni.ulterioriDati.name(), getDichiarazioni(bulkInfoService.find(application.getType().getId()), application, JCONONPropertyIds.CALL_ELENCO_ASPECTS_ULTERIORI_DATI, applicationModel, Dichiarazioni.ulterioriDati));
String labelSottoscritto = i18nService.getLabel("application.text.sottoscritto.lower." + application.getPropertyValue(JCONONPropertyIds.APPLICATION_SESSO.value()), locale);
String labelSanzioniPenali = i18nService.getLabel("text.jconon_application_dichiarazione_sanzioni_penali_" + call.getPropertyValue(JCONONPropertyIds.CALL_CODICE.value()), locale);
if (labelSanzioniPenali == null)
labelSanzioniPenali = i18nService.getLabel("text.jconon_application_dichiarazione_sanzioni_penali", locale, labelSottoscritto);
else
labelSanzioniPenali = i18nService.getLabel("text.jconon_application_dichiarazione_sanzioni_penali_" + call.getPropertyValue(JCONONPropertyIds.CALL_CODICE.value()), locale, labelSottoscritto);
applicationModel.getProperties().put("label_jconon_application_dichiarazione_sanzioni_penali", labelSanzioniPenali);
applicationModel.getProperties().put("label_jconon_application_dichiarazione_dati_personali", i18nService.getLabel("text.jconon_application_dichiarazione_dati_personali", locale, labelSottoscritto));
for (Object key : call.getProperty(JCONONPropertyIds.CALL_ELENCO_SEZIONI_DOMANDA.value()).getValues()) {
applicationModel.getProperties().put(String.valueOf(key), props.get(key));
}
if (immediate) {
applicationModel.getProperties().put(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.CONFERMATA.getValue());
applicationModel.getProperties().put(JCONONPropertyIds.APPLICATION_DATA_DOMANDA.value(), Calendar.getInstance());
}
String json = "{\"properties\":" + gson.toJson(applicationModel.getProperties()) + "}";
try {
/**
* Calcolo il QRCODE del link alla stampa
*/
ByteArrayOutputStream qrcode = QrCodeUtil.getQrcode(contextURL + "/rest/application/print-download?nodeRef=" + application.getId());
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());
if (qrcode != null) {
parameters.put("QRCODE", new ByteArrayInputStream(qrcode.toByteArray()));
}
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
parameters.put(JRParameter.REPORT_CLASS_LOADER, classLoader);
JasperReport jasperReport = cacheRepository.jasperReport(PRINT_RESOURCE_PATH + "DomandaConcorso.jrxml", jasperCompileManager());
JasperPrint jasperPrint = jasperFillManager().fill(jasperReport, parameters);
ByteArrayOutputStream os = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
exporter.setParameter(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, Boolean.TRUE);
exporter.exportReport();
return os.toByteArray();
} catch (Exception e) {
throw new CMISApplicationException("Error in JASPER", e);
}
}
use of net.sf.jasperreports.engine.data.JsonDataSource in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method addContentToCmisObject.
public void addContentToCmisObject(ApplicationModel applicationBulk, CmisObject cmisObject, Locale locale) {
BulkInfo bulkInfo = bulkInfoService.find(cmisObject.getType().getId());
String title = bulkInfo.getLongDescription();
if (title == null || title.length() == 0)
title = cmisObject.getType().getDisplayName();
Map<String, Object> parameters = new HashMap<String, Object>();
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();
List<Pair<String, String>> fields = new ArrayList<Pair<String, String>>();
fields.addAll(getFields(cmisObject, applicationBulk));
applicationBulk.getProperties().put("fields", new PrintDetailBulk(null, null, null, fields, null));
String json = "{\"properties\":" + gson.toJson(applicationBulk.getProperties()) + "}";
JRGzipVirtualizer vir = new JRGzipVirtualizer(100);
final ResourceBundle resourceBundle = ResourceBundle.getBundle("net.sf.jasperreports.view.viewer", locale);
try {
JRDataSource datasource = new JsonDataSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), "properties");
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());
parameters.put("title", title);
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
parameters.put(JRParameter.REPORT_CLASS_LOADER, classLoader);
JasperReport jasperReport = cacheRepository.jasperReport(PRINT_RESOURCE_PATH + "prodotti.jrxml", jasperCompileManager());
JasperPrint jasperPrint = jasperFillManager().fill(jasperReport, parameters);
InputStream stream = new ByteArrayInputStream(JasperExportManager.exportReportToPdf(jasperPrint));
ContentStream contentStream = new ContentStreamImpl(cmisObject.getName(), new BigInteger(String.valueOf(stream.available())), "application/pdf", stream);
((Document) cmisObject).setContentStream(contentStream, true);
} catch (Exception e) {
LOGGER.error("Error during print report for object: " + cmisObject.getId(), e);
}
}
use of net.sf.jasperreports.engine.data.JsonDataSource in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getSchedaAnonimaSintetica.
@SuppressWarnings("unchecked")
public byte[] getSchedaAnonimaSintetica(Session cmisSession, Folder application, String contextURL, Locale locale, int index) throws CMISApplicationException {
Folder call = application.getFolderParent();
ApplicationModel applicationModel = new ApplicationModel(application, cmisSession.getDefaultContext(), i18nService.loadLabels(locale), contextURL, false);
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();
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_SCHEDE_ANONIME.value()) != null) {
applicationModel.getProperties().put("schedeAnonime", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_SCHEDE_ANONIME.value()), application, cmisSession, applicationModel));
}
String json = "{\"properties\":" + gson.toJson(applicationModel.getProperties()) + "}";
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("INDICE", index);
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 + "SchedaAnonima.jrxml", jasperCompileManager());
JasperPrint jasperPrint = jasperFillManager().fill(jasperReport, parameters);
ByteArrayOutputStream os = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
exporter.setParameter(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, Boolean.TRUE);
exporter.exportReport();
return os.toByteArray();
} catch (Exception e) {
throw new CMISApplicationException("Error in JASPER", e);
}
}
use of net.sf.jasperreports.engine.data.JsonDataSource in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getSchedaValutazione.
public byte[] getSchedaValutazione(Session cmisSession, Folder application, String contextURL, Locale locale) throws CMISApplicationException {
Folder call = application.getFolderParent();
ApplicationModel applicationModel = new ApplicationModel(application, cmisSession.getDefaultContext(), i18nService.loadLabels(locale), contextURL, false);
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();
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_ASSOCIATIONS.value()) != null) {
applicationModel.getProperties().put("allegati", getAllegati(application, JCONONPolicyType.JCONON_ATTACHMENT_GENERIC_DOCUMENT, cmisSession, applicationModel, false, false));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM.value()) != null) {
applicationModel.getProperties().put("curriculum", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM.value()), application, cmisSession, applicationModel, false));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()) != null) {
applicationModel.getProperties().put("prodotti", getProdotti(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()), application, JCONONPolicyType.PEOPLE_NO_SELECTED_PRODUCT, cmisSession, applicationModel, false));
applicationModel.getProperties().put("prodottiScelti", getProdotti(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()), application, JCONONPolicyType.PEOPLE_SELECTED_PRODUCT, cmisSession, applicationModel, false));
}
String json = "{\"properties\":" + gson.toJson(applicationModel.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");
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("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);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JasperReport report = JasperCompileManager.compileReport(new ClassPathResource(PRINT_RESOURCE_PATH + "scheda_valutazione.jrxml").getInputStream());
JasperPrint jasperPrint = jasperFillManager().fill(report, parameters);
JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(false);
configuration.setDetectCellType(true);
configuration.setCollapseRowSpan(false);
configuration.setRemoveEmptySpaceBetweenRows(true);
configuration.setWhitePageBackground(false);
exporter.setConfiguration(configuration);
exporter.exportReport();
return baos.toByteArray();
} catch (Exception e) {
throw new CMISApplicationException("Error in JASPER", e);
}
}
Aggregations