use of it.cnr.bulkinfo.BulkInfo 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.bulkinfo.BulkInfo in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method validateAspects.
protected List<JSONErrorPair> validateAspects(Map<String, Object> map, Folder call, Folder application, Session cmisSession) {
List<JSONErrorPair> listError = new ArrayList<JSONErrorPair>();
List<String> listAspect = getDichiarazioniList(call, application);
for (String aspect : listAspect) {
BulkInfo bulkInfoAspect = bulkInfoService.find(aspect);
FieldProperty flag = null;
if (bulkInfoAspect != null) {
for (FieldProperty fieldProperty : bulkInfoAspect.getForm(aspect)) {
if (fieldProperty.isRadioGroupType() || fieldProperty.isCheckboxType()) {
flag = fieldProperty;
break;
}
}
for (FieldProperty fieldProperty : bulkInfoAspect.getForm(aspect)) {
if (flag != null) {
if (!fieldProperty.equals(flag) && fieldProperty.getAttributes().get("class").contains(flag.getName() + '_' + map.get(flag.getProperty())) && !fieldProperty.isNullable() && !Optional.ofNullable(fieldProperty.getAttributes().get("class")).map(s -> s.contains("double_show")).orElse(Boolean.FALSE)) {
addError(listError, map, fieldProperty.getProperty(), cmisSession.getTypeDefinition(aspect).getPropertyDefinitions().get(fieldProperty.getProperty()).getDisplayName());
} else {
if (fieldProperty.equals(flag) && !fieldProperty.isNullable()) {
addError(listError, map, fieldProperty.getProperty(), cmisSession.getTypeDefinition(aspect).getPropertyDefinitions().get(fieldProperty.getProperty()).getDisplayName());
}
}
} else {
if (!fieldProperty.isNullable()) {
addError(listError, map, fieldProperty.getProperty(), cmisSession.getTypeDefinition(aspect).getPropertyDefinitions().get(fieldProperty.getProperty()).getDisplayName());
}
}
}
}
}
return listError;
}
use of it.cnr.bulkinfo.BulkInfo in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method validateBaseTableMap.
protected List<JSONErrorPair> validateBaseTableMap(Map<String, Object> map, Folder call, Folder application, Session cmisSession) {
List<JSONErrorPair> listError = new ArrayList<JSONErrorPair>();
listError.addAll(validateAspects(map, call, application, cmisSession));
List<String> listSezioniDomanda = getSezioniDomandaList(call);
BulkInfo bulkInfo = bulkInfoService.find(JCONONFolderType.JCONON_APPLICATION.value().replace(":", "_"));
for (String sezione : listSezioniDomanda) {
for (FieldProperty fieldProperty : bulkInfo.getForm(sezione)) {
if (Optional.ofNullable(fieldProperty.getProperty()).isPresent() && Optional.ofNullable(fieldProperty.getAttribute("visible")).filter(x -> x.equalsIgnoreCase("true")).isPresent()) {
// TAB DATI ANAGRAFICI - Controlli particolari
if (fieldProperty.getProperty().equals(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value())) {
addError(listError, map, fieldProperty.getProperty());
if (map.get(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value()) != null) {
if ((Boolean) map.get(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value())) {
addError(listError, map, JCONONPropertyIds.APPLICATION_CODICE_FISCALE.value());
Object codiceFiscale = map.get(JCONONPropertyIds.APPLICATION_CODICE_FISCALE.value());
if (codiceFiscale != null) {
// controllo formale della validita' del codice fiscale
controllaCodiceFiscale(map, application);
}
} else
addError(listError, map, JCONONPropertyIds.APPLICATION_NAZIONE_CITTADINANZA.value());
}
} else if (fieldProperty.getProperty().equals(JCONONPropertyIds.APPLICATION_CODICE_FISCALE.value()) || fieldProperty.getProperty().equals(JCONONPropertyIds.APPLICATION_NAZIONE_CITTADINANZA.value())) {
LOGGER.debug("field " + fieldProperty.getProperty());
} else if (fieldProperty.getProperty().equals(JCONONPropertyIds.APPLICATION_CAP_RESIDENZA.value())) {
if (map.get(JCONONPropertyIds.APPLICATION_NAZIONE_RESIDENZA.value()) != null && ((String) map.get(JCONONPropertyIds.APPLICATION_NAZIONE_RESIDENZA.value())).toUpperCase().equals("ITALIA"))
addError(listError, map, JCONONPropertyIds.APPLICATION_CAP_RESIDENZA.value());
} else if (fieldProperty.getProperty().equals(JCONONPropertyIds.APPLICATION_CAP_COMUNICAZIONI.value())) {
if (map.get(JCONONPropertyIds.APPLICATION_NAZIONE_COMUNICAZIONI.value()) != null && ((String) map.get(JCONONPropertyIds.APPLICATION_NAZIONE_COMUNICAZIONI.value())).toUpperCase().equals("ITALIA"))
addError(listError, map, JCONONPropertyIds.APPLICATION_CAP_COMUNICAZIONI.value());
} else if (fieldProperty.getProperty().equals(JCONONPropertyIds.APPLICATION_EMAIL_COMUNICAZIONI.value())) {
if (application == null || application.getPropertyValue(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value()) == null || application.getPropertyValue(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value()).equals(Boolean.FALSE))
addError(listError, map, JCONONPropertyIds.APPLICATION_EMAIL_COMUNICAZIONI.value());
} else if (fieldProperty.getProperty().equals(JCONONPropertyIds.APPLICATION_EMAIL_PEC_COMUNICAZIONI.value())) {
if (application == null || application.getPropertyValue(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value()) == null || application.getPropertyValue(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value()).equals(Boolean.TRUE))
addError(listError, map, JCONONPropertyIds.APPLICATION_EMAIL_PEC_COMUNICAZIONI.value());
} else
addError(listError, map, fieldProperty.getProperty(), application.getType().getPropertyDefinitions().get(fieldProperty.getProperty()).getDisplayName());
if ((fieldProperty.isRadioGroupType() || fieldProperty.isCheckboxType()) && !fieldProperty.getProperty().equals(JCONONPropertyIds.APPLICATION_SESSO.value()) && map.get(fieldProperty.getProperty()) != null) {
Collection<FieldProperty> radioForm = bulkInfo.getForm(fieldProperty.getProperty() + ((Boolean) map.get(fieldProperty.getProperty()) ? "_true" : "_false").replace(":", "_"));
if (radioForm != null && !radioForm.isEmpty()) {
for (FieldProperty radioFieldProperty : bulkInfo.getForm(fieldProperty.getProperty() + ((Boolean) map.get(fieldProperty.getProperty()) ? "_true" : "_false").replace(":", "_"))) {
if (!radioFieldProperty.isNullable())
addError(listError, map, radioFieldProperty.getProperty(), application.getType().getPropertyDefinitions().get(radioFieldProperty.getProperty()).getDisplayName());
}
}
}
}
}
}
List<String> properties = call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_FIELD_NOT_REQUIRED.value());
if (properties != null) {
for (String property : properties) {
for (Iterator<JSONErrorPair> iterator = listError.iterator(); iterator.hasNext(); ) {
JSONErrorPair error = iterator.next();
if (error.getFirst().startsWith(property))
iterator.remove();
}
}
}
return listError;
}
use of it.cnr.bulkinfo.BulkInfo 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.bulkinfo.BulkInfo 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