use of it.cnr.cool.util.Pair 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 it.cnr.cool.util.Pair in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method formNameMessage.
private String formNameMessage(FieldProperty fieldProperty, BulkInfo bulkInfo, PrintDetailBulk detail, ApplicationModel applicationModel, Folder application, String labelKey) {
String message = "";
if (fieldProperty.getAttribute("formName") != null) {
List<Object> params = new ArrayList<Object>();
FieldPropertySet printForm1 = bulkInfo.getPrintForms().get(fieldProperty.getAttribute("formName"));
if (printForm1 != null && printForm1.getKey() != null && printForm1.getKey().equals("false")) {
if (labelKey != null)
detail.addField(new Pair<String, String>(null, applicationModel.getMessage(labelKey)));
printField(printForm1, applicationModel, application, detail, bulkInfo);
} else {
for (FieldProperty paramFieldProperty : bulkInfo.getPrintForm(fieldProperty.getAttribute("formName"))) {
Object param = applicationModel.getProperties().get(paramFieldProperty.getAttribute("property"));
if (param == null)
param = application.getPropertyValue(paramFieldProperty.getAttribute("property"));
if (param == null)
param = "";
params.add(param);
}
message = message.concat(applicationModel.getMessage(labelKey, params.toArray()));
}
} else {
message = message.concat(applicationModel.getMessage(labelKey));
}
return message;
}
use of it.cnr.cool.util.Pair in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getSezioni.
private Map<String, List<Pair<String, String>>> getSezioni(List<String> propertyValue, Session cmisSession) {
Map<String, List<Pair<String, String>>> sezioni = new LinkedHashMap<String, List<Pair<String, String>>>();
for (String type : propertyValue) {
BulkInfo bulkInfo = bulkInfoService.find(type);
String sezione = bulkInfo.getShortDescription();
if (sezione == null || sezione.length() == 0)
sezione = cmisSession.getTypeDefinition(type).getDisplayName();
String sottoSezione = bulkInfo.getLongDescription();
String queryName = bulkInfo.getCmisQueryName();
if (sezioni.containsKey(sezione)) {
sezioni.get(sezione).add(new Pair<String, String>(sottoSezione, queryName));
} else {
List<Pair<String, String>> lista = new ArrayList<Pair<String, String>>();
lista.add(new Pair<String, String>(Optional.ofNullable(sottoSezione).orElse(sezione), queryName));
sezioni.put(sezione, lista);
}
}
return sezioni;
}
use of it.cnr.cool.util.Pair in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method printField.
@SuppressWarnings("unchecked")
private void printField(FieldPropertySet printForm, ApplicationModel applicationModel, Folder application, PrintDetailBulk detail, BulkInfo bulkInfo) {
for (FieldProperty printFieldProperty : printForm.getFieldProperties()) {
if (printFieldProperty.getAttribute("formName") != null) {
Object objValue = application.getPropertyValue(printFieldProperty.getAttribute("formName"));
FieldPropertySet printFormDetail = bulkInfo.getPrintForms().get(printFieldProperty.getAttribute("formName"));
for (FieldProperty printFieldPropertyDetail : printFormDetail.getFieldProperties()) {
if (printFieldPropertyDetail.getAttribute("key") != null && printFieldPropertyDetail.getAttribute("key").equals(String.valueOf(objValue))) {
detail.addField(new Pair<String, String>(null, applicationModel.getMessage(printFieldPropertyDetail.getAttribute("label"))));
}
}
final Optional<String> dichiarazioniEmptyMessage = getDichiarazioniEmptyMessage();
if (dichiarazioniEmptyMessage.isPresent() && Optional.ofNullable(detail.getFields()).orElse(Collections.emptyList()).isEmpty()) {
detail.addField(new Pair<String, String>(null, dichiarazioniEmptyMessage.get()));
}
continue;
}
String message = null;
String label = printFieldProperty.getAttribute("label");
if (label == null) {
String labelJSON = printFieldProperty.getAttribute("jsonlabel");
if (labelJSON != null) {
JSONObject jsonLabel = new JSONObject(labelJSON);
message = applicationModel.getMessage(jsonLabel.getString("key"));
if (message == null || message.equalsIgnoreCase(jsonLabel.getString("key")))
message = jsonLabel.getString("default");
} else {
FieldProperty subProperty = printFieldProperty.getSubProperty("jsonlabel");
label = subProperty.getAttribute("key");
message = applicationModel.getMessage(label);
if (message == null || message.equalsIgnoreCase(subProperty.getAttribute("key")))
message = subProperty.getAttribute("default");
}
} else {
message = applicationModel.getMessage(label);
}
String value;
Object objValue = application.getPropertyValue(printFieldProperty.getProperty());
if (objValue == null && printFieldProperty.getProperty() != null) {
final Optional<String> dichiarazioniEmptyMessage = getDichiarazioniEmptyMessage();
if (dichiarazioniEmptyMessage.isPresent() && Optional.ofNullable(detail.getFields()).orElse(Collections.emptyList()).isEmpty()) {
detail.addField(new Pair<String, String>(null, dichiarazioniEmptyMessage.get()));
}
continue;
} else if (printFieldProperty.getProperty() == null) {
detail.addField(new Pair<String, String>(null, message));
} else {
if (application.getProperty(printFieldProperty.getProperty()).isMultiValued()) {
List<Object> values = (List<Object>) objValue;
if (values.isEmpty()) {
final Optional<String> dichiarazioniEmptyMessage = getDichiarazioniEmptyMessage();
if (dichiarazioniEmptyMessage.isPresent() && Optional.ofNullable(detail.getFields()).orElse(Collections.emptyList()).isEmpty()) {
detail.addField(new Pair<String, String>(null, dichiarazioniEmptyMessage.get()));
}
return;
}
if (values.size() > 1) {
for (int k = 0; k < values.size(); k++) {
detail.addField(new Pair<String, String>(k == 0 ? (message + "<br>") : "", String.valueOf(values.get(k))));
}
} else {
value = StringUtils.collectionToDelimitedString(((Collection<?>) objValue), ", ");
detail.addField(new Pair<String, String>(message, value));
}
} else {
if (printFieldProperty.getAttribute("widget") != null) {
if (printFieldProperty.getAttribute("widget").contains("ui.datepicker")) {
value = StringUtil.DATEFORMAT.format(((Calendar) objValue).getTime());
} else if (printFieldProperty.getAttribute("widget").contains("ui.datetimepicker")) {
value = StringUtil.DATETIMEFORMAT.format(((Calendar) objValue).getTime());
} else {
if (objValue instanceof Boolean) {
if (printFieldProperty.getAttribute("generated") != null)
value = Boolean.valueOf(String.valueOf(objValue)) ? "" : "No";
else
value = "";
} else {
value = String.valueOf(objValue);
}
}
} else {
value = String.valueOf(objValue);
}
if (Optional.ofNullable(label).isPresent()) {
final String finalLabel = label.concat("_").concat(value);
final Optional<String> message1 = Optional.ofNullable(applicationModel.getMessage(finalLabel));
if (message1.isPresent() && !message1.get().equals(finalLabel)) {
message = message1.get();
value = "";
}
}
detail.addField(new Pair<String, String>(message, value));
}
}
}
}
use of it.cnr.cool.util.Pair in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method downloadPrintApplication.
public Pair<String, byte[]> downloadPrintApplication(Session cmisSession, String nodeRef, final String contextURL, final Locale locale) {
LOGGER.info("Download print application width id: " + nodeRef);
Folder application = (Folder) cmisSession.getObject(nodeRef);
application.refresh();
return Optional.ofNullable(findRicevutaApplicationId(cmisSession, application)).map(objectId -> (Document) cmisSession.getObject(objectId)).map(document -> {
try {
return new Pair<String, byte[]>(document.getName(), IOUtils.toByteArray(document.getContentStream().getStream()));
} catch (IOException e) {
throw new ClientMessageException("Print not found of application " + nodeRef, e);
}
}).orElseThrow(() -> new ClientMessageException("Print not found of application " + nodeRef));
}
Aggregations