use of it.cnr.si.cool.jconon.model.ApplicationModel in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method printEsclusione.
public byte[] printEsclusione(Session cmisSession, Folder application, String contextURL, Locale locale, boolean stampaPunteggi, String note, String firma, String proveConseguite) throws CMISApplicationException {
ApplicationModel applicationBulk = new ApplicationModel(application, cmisSession.getDefaultContext(), i18nService.loadLabels(locale), contextURL, false);
applicationBulk.getProperties().put("stampaPunteggi", stampaPunteggi);
applicationBulk.getProperties().put("note", note);
applicationBulk.getProperties().put("firma", firma);
applicationBulk.getProperties().put("proveConseguite", proveConseguite);
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 + "esclusione.jrxml", jasperCompileManager());
JasperPrint jasperPrint = jasperFillManager().fill(jasperReport, parameters);
return JasperExportManager.exportReportToPdf(jasperPrint);
} catch (Exception e) {
throw new CMISApplicationException("Error in JASPER", e);
}
}
use of it.cnr.si.cool.jconon.model.ApplicationModel in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getModuloDaFirmare.
public byte[] getModuloDaFirmare(Session cmisSession, Folder application, String contextURL, Locale locale, String jasperName) throws CMISApplicationException {
ApplicationModel applicationBulk = new ApplicationModel(application, cmisSession.getDefaultContext(), i18nService.loadLabels(locale), contextURL);
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 + jasperName, jasperCompileManager());
JasperPrint jasperPrint = jasperFillManager().fill(jasperReport, parameters);
return JasperExportManager.exportReportToPdf(jasperPrint);
} catch (Exception e) {
throw new CMISApplicationException("Error in JASPER", e);
}
}
use of it.cnr.si.cool.jconon.model.ApplicationModel in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getAllegati.
private List<PrintDetailBulk> getAllegati(Folder application, JCONONPolicyType allegati, Session cmisSession, ApplicationModel applicationModel, boolean printDetail, boolean allAllegati) {
List<PrintDetailBulk> result = new ArrayList<PrintDetailBulk>();
Criteria criteria = CriteriaFactory.createCriteria(allegati.queryName());
criteria.addColumn(PropertyIds.OBJECT_ID);
criteria.add(Restrictions.inFolder(application.getId()));
ItemIterable<QueryResult> queryResults = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
if (queryResults.getTotalNumItems() > 0) {
for (QueryResult queryResult : queryResults.getPage(Integer.MAX_VALUE)) {
Document riga = (Document) cmisSession.getObject((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
if (Optional.ofNullable(riga).map(document -> document.<List<String>>getPropertyValue(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)).filter(listProperty -> listProperty.contains(JCONONPolicyType.JCONON_ATTACHMENT_FROM_RDP.value())).isPresent())
continue;
if (!allAllegati && Optional.ofNullable(riga).map(Document::getDocumentType).map(DocumentType::getId).filter(type -> Arrays.asList(JCONONDocumentType.JCONON_ATTACHMENT_DOCUMENTO_RICONOSCIMENTO.value(), JCONONDocumentType.JCONON_ATTACHMENT_DIC_SOST.value()).contains(type)).isPresent())
continue;
String link = applicationModel.getContextURL() + "/search/content?nodeRef=" + riga.getId() + "&fileName=" + riga.getContentStreamFileName() + // FIX EXCEL CHARACTER
"&dummy=dummy";
String type = applicationModel.getMessage(riga.getType().getId());
if (type.equals(riga.getType().getId()))
type = riga.getType().getDisplayName();
List<Pair<String, String>> detail;
Pair<String, String> pairName = new Pair<String, String>(riga.getProperty(PropertyIds.NAME).getDisplayName(), riga.getProperty(PropertyIds.NAME).getValueAsString());
if (printDetail) {
detail = getFields(riga, applicationModel);
if (!detail.contains(pairName))
detail.add(pairName);
result.add(new PrintDetailBulk(null, type, link, detail, null));
} else {
result.add(new PrintDetailBulk(null, type, link, riga.getProperty(PropertyIds.NAME).getValueAsString(), null));
}
}
}
return result;
}
use of it.cnr.si.cool.jconon.model.ApplicationModel in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getCurriculumStrutturatoReportModel.
public byte[] getCurriculumStrutturatoReportModel(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());
} 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_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));
}
String labelSottoscritto = i18nService.getLabel("application.text.sottoscritto.lower." + application.getPropertyValue(JCONONPropertyIds.APPLICATION_SESSO.value()), locale);
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 {
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 + "CurriculumStrutturato.jrxml", jasperCompileManager());
JasperPrint jasperPrint = jasperFillManager().fill(jasperReport, parameters);
ByteArrayOutputStream os = new ByteArrayOutputStream();
JRDocxExporter export = new JRDocxExporter();
export.setExporterInput(new SimpleExporterInput(jasperPrint));
export.setExporterOutput(new SimpleOutputStreamExporterOutput(os));
SimpleDocxReportConfiguration config = new SimpleDocxReportConfiguration();
// Set desired configuration
config.setFlexibleRowHeight(false);
config.setFramesAsNestedTables(false);
export.setConfiguration(config);
export.exportReport();
return os.toByteArray();
} catch (Exception e) {
throw new CMISApplicationException("Error in JASPER", e);
}
}
use of it.cnr.si.cool.jconon.model.ApplicationModel in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getFields.
@SuppressWarnings("unchecked")
private List<Pair<String, String>> getFields(CmisObject riga, ApplicationModel applicationModel) {
BulkInfo bulkInfo = bulkInfoService.find(riga.getType().getId());
List<Pair<String, String>> results = new ArrayList<Pair<String, String>>();
if (bulkInfo == null) {
for (Property<?> property : riga.getProperties()) {
if (!property.getDefinition().isInherited() && !property.getDefinition().getId().startsWith("cm:owner")) {
results.add(new Pair<String, String>(property.getDisplayName(), property.getValueAsString()));
}
}
results.add(new Pair<String, String>(riga.getProperty(PropertyIds.NAME).getDisplayName(), riga.getProperty(PropertyIds.NAME).getValueAsString()));
} else {
for (FieldProperty fieldProperty : bulkInfo.getForm("default")) {
String value;
Object objValue = riga.getPropertyValue(fieldProperty.getProperty());
if (riga.getProperty(fieldProperty.getProperty()) != null) {
PropertyDefinition<?> propertyDefinition = riga.getProperty(fieldProperty.getProperty()).getDefinition();
Cardinality cardinality = propertyDefinition.getCardinality();
if ((cardinality.equals(Cardinality.SINGLE) && objValue != null) || (cardinality.equals(Cardinality.MULTI) && objValue != null && !((List<Object>) objValue).isEmpty())) {
// != null
if (cardinality.equals(Cardinality.MULTI)) {
value = StringUtils.collectionToDelimitedString(((Collection<?>) objValue), ", ");
} else {
if (propertyDefinition instanceof PropertyDateTimeDefinition) {
value = new SimpleDateFormat("dd/MM/yyyy", Locale.ITALY).format(((GregorianCalendar) objValue).getTime());
} else if (propertyDefinition instanceof PropertyDecimalDefinition) {
value = new NumberStyleFormatter("").print((BigDecimal) objValue, Locale.ITALY);
} else if (propertyDefinition instanceof PropertyBooleanDefinition) {
if (!Boolean.valueOf(objValue.toString()))
continue;
value = "";
} else {
value = objValue.toString();
}
}
String message = displayValue(fieldProperty, value, applicationModel);
if (Optional.ofNullable(fieldProperty).flatMap(fieldProperty1 -> Optional.ofNullable(fieldProperty1.getAttribute("widget"))).map(s -> !s.equals("ui.sedi")).orElse(Boolean.TRUE)) {
results.add(new Pair<String, String>(applicationModel.getMessage(getLabel(fieldProperty, applicationModel)), message));
}
}
}
}
}
return results;
}
Aggregations