use of it.cnr.si.cool.jconon.model.PrintDetailBulk 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.si.cool.jconon.model.PrintDetailBulk in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getProdotti.
private List<PrintDetailBulk> getProdotti(List<String> propertyValue, Folder application, JCONONPolicyType peopleProduct, Session cmisSession, ApplicationModel applicationModel, boolean printDetail) {
List<PrintDetailBulk> result = new ArrayList<PrintDetailBulk>();
OperationContext ocRel = new OperationContextImpl(cmisSession.getDefaultContext());
ocRel.setIncludeRelationships(IncludeRelationships.SOURCE);
Map<String, List<Pair<String, String>>> sezioni = getSezioni(propertyValue, cmisSession);
for (String key : sezioni.keySet()) {
for (Pair<String, String> pair : sezioni.get(key)) {
Criteria criteria = CriteriaFactory.createCriteria(pair.getSecond());
Criteria criteriaAspect = criteria.createCriteria(peopleProduct.queryName(), "people");
Criteria criteriaCommon = criteria.createCriteria("cvpeople:commonMetadata", "common");
criteriaAspect.addJoinCriterion(Restrictions.eqProperty(criteria.prefix(PropertyIds.OBJECT_ID), criteriaAspect.prefix(PropertyIds.OBJECT_ID)));
criteriaCommon.addJoinCriterion(Restrictions.eqProperty(criteria.prefix(PropertyIds.OBJECT_ID), criteriaCommon.prefix(PropertyIds.OBJECT_ID)));
criteria.addColumn(PropertyIds.OBJECT_ID);
criteriaCommon.addOrder(Order.desc("common.cvpeople:anno"));
criteria.add(Restrictions.inFolder(application.getId()));
criteria.addOrder(Order.desc(PropertyIds.NAME));
ItemIterable<QueryResult> queryResults = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
if (queryResults.getTotalNumItems() > 0) {
for (QueryResult queryResult : queryResults.getPage(Integer.MAX_VALUE)) {
List<PrintDetailBulk> rels = new ArrayList<PrintDetailBulk>();
CmisObject riga = cmisSession.getObject((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue(), ocRel);
if (!riga.getType().getQueryName().equalsIgnoreCase(pair.getSecond()))
continue;
if (riga.getRelationships() != null && !riga.getRelationships().isEmpty()) {
for (Relationship relationship : riga.getRelationships()) {
if (relationship.getType().getId().equals(JCONONRelationshipType.JCONON_ATTACHMENT_IN_PRODOTTO.value())) {
CmisObject target = cmisSession.getObject(relationship.getTarget());
String link = applicationModel.getContextURL() + "/search/content?nodeRef=" + target.getId();
if (printDetail)
rels.add(new PrintDetailBulk(null, "Allegati", link, getFields(target, applicationModel), null));
else {
rels.add(new PrintDetailBulk(null, "Allegati", link, target.getProperty(PropertyIds.NAME).getValueAsString(), null));
}
}
}
}
if (printDetail) {
result.add(new PrintDetailBulk(key, pair.getFirst(), null, getFields(riga, applicationModel), rels));
} else {
String link = null;
if (((BigInteger) riga.getPropertyValue(PropertyIds.CONTENT_STREAM_LENGTH)).compareTo(BigInteger.ZERO) > 0) {
link = applicationModel.getContextURL() + "/search/content?nodeRef=" + riga.getId() + "&fileName=" + riga.getName() + ".pdf";
}
String title = riga.getPropertyValue("cvpeople:id_tipo_txt");
title += " - " + riga.getPropertyValue("cvpeople:titolo");
PrintDetailBulk detail = new PrintDetailBulk(key, pair.getFirst(), link, title, rels);
detail.setPeriodo(String.valueOf(riga.getProperty("cvpeople:anno").getFirstValue()));
if (riga.getProperty("cvpeople:numeroCitazioni") != null && riga.getProperty("cvpeople:numeroCitazioni").getValues().size() != 0)
detail.setNroCitazioni(((BigInteger) riga.getProperty("cvpeople:numeroCitazioni").getValue()).intValue());
if (riga.getProperty("cvpeople:ifRivistaValore") != null && riga.getProperty("cvpeople:ifRivistaValore").getValues().size() != 0) {
try {
detail.setIfValore(riga.getProperty("cvpeople:ifRivistaValore").getValueAsString());
} catch (NumberFormatException _ex) {
LOGGER.error("Estrazione scheda di valutazione NumberFormatException for " + riga.getProperty("cvpeople:ifRivistaValore").getValueAsString() + " objectId:" + riga.getId());
}
}
if (riga.getProperty("cvpeople:altroRuoloSvolto") != null && riga.getProperty("cvpeople:altroRuoloSvolto").getValues().size() != 0) {
detail.setRuolo(riga.getProperty("cvpeople:altroRuoloSvolto").getValueAsString());
}
if (riga.getProperty("cvpeople:ruoloSvolto") != null && riga.getProperty("cvpeople:ruoloSvolto").getValues().size() != 0) {
for (Object ruoloSvolto : riga.getProperty("cvpeople:ruoloSvolto").getValues()) {
if (!ruoloSvolto.equals("Altro")) {
if (detail.getRuolo() != null) {
detail.setRuolo(String.valueOf(ruoloSvolto).replace("_", " ") + "," + detail.getRuolo());
} else {
detail.setRuolo(String.valueOf(ruoloSvolto).replace("_", " "));
}
}
}
}
if (riga.getProperty("cvpeople:altroIfRivistaFonte") != null && riga.getProperty("cvpeople:altroIfRivistaFonte").getValues().size() != 0) {
detail.setIfFonte(riga.getProperty("cvpeople:altroIfRivistaFonte").getValueAsString());
}
if (riga.getProperty("cvpeople:SjrQuartile") != null && riga.getProperty("cvpeople:SjrQuartile").getValues().size() != 0) {
detail.setQuartile(riga.getProperty("cvpeople:SjrQuartile").getValueAsString());
}
if (riga.getProperty("cvpeople:ifRivistaFonte") != null && riga.getProperty("cvpeople:ifRivistaFonte").getValues().size() != 0) {
for (Object ifRivistaFonte : riga.getProperty("cvpeople:ifRivistaFonte").getValues()) {
if (!ifRivistaFonte.equals("Altro")) {
if (detail.getIfFonte() != null) {
detail.setIfFonte(String.valueOf(ifRivistaFonte).replace("_", " ") + "," + detail.getIfFonte());
} else {
detail.setIfFonte(String.valueOf(ifRivistaFonte).replace("_", " "));
}
}
}
}
result.add(detail);
}
}
}
}
}
return result;
}
use of it.cnr.si.cool.jconon.model.PrintDetailBulk in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getDichiarazioni.
/**
* 1. Prendiamo tutte le associazioni della domanda (application)
* 2. Per ogni associazione prendiamo il corrispondente PrintForm dal BulkInfo
* (passato come parametro)
* 3. Per ogni fieldProperty del PrintForm si costruisce una riga(?) dell'output
*
* @param bulkInfo
* @param application
* @param callProperty
* @return
*/
protected List<PrintDetailBulk> getDichiarazioni(BulkInfo bulkInfo, Folder application, JCONONPropertyIds callProperty, ApplicationModel applicationModel, Dichiarazioni dichiarazione) {
List<PrintDetailBulk> result = new ArrayList<PrintDetailBulk>();
// Recupero il bando
// chi e' il parent?
Folder call = application.getParents().get(0);
List<String> associations = call.getPropertyValue(callProperty.value());
boolean isCittadinoItaliano = (boolean) Optional.ofNullable(application.getProperty(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value())).map(Property::getValue).orElse(Boolean.TRUE);
if (isCittadinoItaliano) {
associations.remove(P_JCONON_APPLICATION_ASPECT_GODIMENTO_DIRITTI);
} else {
associations.remove(P_JCONON_APPLICATION_ASPECT_ISCRIZIONE_LISTE_ELETTORALI);
}
for (int i = 0; i < associations.size(); i++) {
String association = associations.get(i);
FieldProperty fieldProperty = null;
FieldPropertySet printForm = bulkInfoService.find(association).getPrintForms().get(association);
if (printForm != null) {
Property<?> property = application.getProperty(printForm.getKey());
if (property != null) {
fieldProperty = printForm.getFieldProperty(property.getValueAsString());
}
PrintDetailBulk detail = new PrintDetailBulk();
detail.setTitle(getTitle(i, dichiarazione));
if (printForm.getKey() == null) {
printField(printForm, applicationModel, application, detail, bulkInfo);
} else {
String labelKey = fieldProperty != null ? fieldProperty.getAttribute("label") : null;
if (application.getPropertyValue(printForm.getKey()) == null || fieldProperty == null || labelKey == null) {
final Optional<String> dichiarazioniEmptyMessage = getDichiarazioniEmptyMessage();
if (!dichiarazioniEmptyMessage.isPresent()) {
continue;
} else {
detail.addField(new Pair<String, String>(null, dichiarazioniEmptyMessage.get()));
}
} else {
detail.addField(new Pair<String, String>(null, formNameMessage(fieldProperty, bulkInfo, detail, applicationModel, application, labelKey)));
}
}
if (detail.getFields() != null && !detail.getFields().isEmpty())
result.add(detail);
}
}
return result;
}
use of it.cnr.si.cool.jconon.model.PrintDetailBulk 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.PrintDetailBulk in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getCurriculum.
private List<PrintDetailBulk> getCurriculum(List<String> propertyValue, Folder application, Session cmisSession, ApplicationModel applicationModel, boolean printDetail) {
List<PrintDetailBulk> result = new ArrayList<PrintDetailBulk>();
Map<String, List<Pair<String, String>>> sezioni = getSezioni(propertyValue, cmisSession);
for (String key : sezioni.keySet()) {
for (Pair<String, String> pair : sezioni.get(key)) {
Criteria criteria = CriteriaFactory.createCriteria(pair.getSecond());
criteria.addColumn(PropertyIds.OBJECT_ID);
criteria.add(Restrictions.inFolder(application.getId()));
addOrderCurriculum(cmisSession, pair.getSecond(), criteria);
ItemIterable<QueryResult> queryResults = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
if (queryResults.getTotalNumItems() > 0) {
for (QueryResult queryResult : queryResults.getPage(Integer.MAX_VALUE)) {
CmisObject riga = cmisSession.getObject((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
if (!riga.getType().getQueryName().equalsIgnoreCase(pair.getSecond()))
continue;
if (printDetail) {
result.add(new PrintDetailBulk(key, pair.getFirst(), null, getFields(riga, applicationModel), null));
} else {
String link = null;
if (Optional.ofNullable(riga.<BigInteger>getPropertyValue(PropertyIds.CONTENT_STREAM_LENGTH)).orElse(BigInteger.ZERO).compareTo(BigInteger.ZERO) > 0) {
link = applicationModel.getContextURL() + "/search/content?nodeRef=" + riga.getId() + "&fileName=" + riga.getName() + ".pdf";
}
String ruolo = riga.getPropertyValue("cvelement:altroRuoloProgetto");
if (ruolo == null)
ruolo = riga.getPropertyValue("cvelement:ruoloProgetto");
if (ruolo == null)
ruolo = riga.getPropertyValue("cvelement:altroRuoloIncarico");
if (ruolo == null)
ruolo = riga.getPropertyValue("cvelement:ruoloIncarico");
if (ruolo != null) {
ruolo = ruolo.replace("_", " ");
ruolo += " - ";
} else {
ruolo = "";
}
String title = riga.getPropertyValue("cvelement:denominazioneIncarico");
if (title == null)
title = riga.getPropertyValue("cvelement:denominazioneIstituto");
if (title == null)
title = riga.getPropertyValue("cvelement:titoloProgetto");
if (title == null)
title = riga.getPropertyValue("cvelement:denominazioneStruttura");
if (title == null)
title = riga.getPropertyValue("cvelement:rivista");
if (title == null)
title = riga.getPropertyValue("cvelement:tipologiaOrganismo");
if (title == null)
title = riga.getPropertyValue("cvelement:titoloEvento");
if (title == null)
title = riga.getPropertyValue("cvelement:descrizionePremio");
if (title == null)
title = riga.getPropertyValue("cvelement:commonAltroEnteCodice");
if (riga.getPropertyValue("cvelement:attivitaSvolta") != null)
title += " - " + riga.getPropertyValue("cvelement:attivitaSvolta");
if (riga.getPropertyValue("cvelement:descrizionePartecipazione") != null)
title += " - " + riga.getPropertyValue("cvelement:descrizionePartecipazione");
PrintDetailBulk detail = new PrintDetailBulk(null, pair.getFirst(), link, ruolo + title, null);
String periodo = "";
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
if (riga.getPropertyValue("cvelement:periodAttivitaDal") != null)
periodo += "Dal " + dateFormat.format(((Calendar) riga.getPropertyValue("cvelement:periodAttivitaDal")).getTime());
if (riga.getPropertyValue("cvelement:periodAttivitaAl") != null)
periodo += " Al " + dateFormat.format(((Calendar) riga.getPropertyValue("cvelement:periodAttivitaAl")).getTime());
if (riga.getPropertyValue("cvelement:attivitainCorso") != null)
periodo += " attivita in corso";
if (riga.getPropertyValue("cvelement:oreComplessive") != null)
periodo += " Ore complessive " + ((BigDecimal) (riga.getPropertyValue("cvelement:oreComplessive"))).setScale(0, BigDecimal.ROUND_DOWN);
detail.setPeriodo(periodo);
result.add(detail);
}
}
}
}
}
return result;
}
Aggregations