Search in sources :

Example 1 with PrintDetailBulk

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);
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream) BulkInfo(it.cnr.bulkinfo.BulkInfo) Pair(it.cnr.cool.util.Pair) JsonDataSource(net.sf.jasperreports.engine.data.JsonDataSource) JRGzipVirtualizer(net.sf.jasperreports.engine.fill.JRGzipVirtualizer) ClassPathResource(org.springframework.core.io.ClassPathResource) JSONException(org.json.JSONException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) WriterException(com.google.zxing.WriterException) ParseException(java.text.ParseException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) ACLType(it.cnr.cool.cmis.model.ACLType) Type(java.lang.reflect.Type) BigInteger(java.math.BigInteger) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) PrintDetailBulk(it.cnr.si.cool.jconon.model.PrintDetailBulk)

Example 2 with PrintDetailBulk

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;
}
Also used : OperationContextImpl(org.apache.chemistry.opencmis.client.runtime.OperationContextImpl) Criteria(it.cnr.si.opencmis.criteria.Criteria) BigInteger(java.math.BigInteger) List(java.util.List) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) PrintDetailBulk(it.cnr.si.cool.jconon.model.PrintDetailBulk)

Example 3 with PrintDetailBulk

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;
}
Also used : FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) FieldPropertySet(it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet) PrintDetailBulk(it.cnr.si.cool.jconon.model.PrintDetailBulk) FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty)

Example 4 with PrintDetailBulk

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;
}
Also used : Color(java.awt.Color) Order(it.cnr.si.opencmis.criteria.Order) ApplicationService(it.cnr.si.cool.jconon.service.application.ApplicationService) Autowired(org.springframework.beans.factory.annotation.Autowired) GroupService(it.cnr.cool.security.service.GroupService) PrintDetailBulk(it.cnr.si.cool.jconon.model.PrintDetailBulk) PDType1Font(org.apache.pdfbox.pdmodel.font.PDType1Font) org.apache.poi.ss.usermodel(org.apache.poi.ss.usermodel) BigDecimal(java.math.BigDecimal) JSONException(org.json.JSONException) CriteriaFactory(it.cnr.si.opencmis.criteria.CriteriaFactory) SimpleXlsReportConfiguration(net.sf.jasperreports.export.SimpleXlsReportConfiguration) NumberStyleFormatter(org.springframework.format.number.NumberStyleFormatter) CoolPropertyIds(it.cnr.cool.cmis.model.CoolPropertyIds) BigInteger(java.math.BigInteger) HttpStatus(org.apache.commons.httpclient.HttpStatus) PrintParameterModel(it.cnr.si.cool.jconon.model.PrintParameterModel) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) CompetitionFolderService(it.cnr.si.cool.jconon.service.cache.CompetitionFolderService) CMISAuthority(it.cnr.cool.security.service.impl.alfresco.CMISAuthority) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) org.apache.chemistry.opencmis.commons.enums(org.apache.chemistry.opencmis.commons.enums) StandardCharsets(java.nio.charset.StandardCharsets) PropertyDecimalDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) MailService(it.cnr.cool.mail.MailService) IOUtils(org.apache.commons.io.IOUtils) Stream(java.util.stream.Stream) OperationContextImpl(org.apache.chemistry.opencmis.client.runtime.OperationContextImpl) PDPage(org.apache.pdfbox.pdmodel.PDPage) BarcodeFormat(com.google.zxing.BarcodeFormat) FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) JsonDataSource(net.sf.jasperreports.engine.data.JsonDataSource) JRXlsExporter(net.sf.jasperreports.engine.export.JRXlsExporter) JRPdfExporter(net.sf.jasperreports.engine.export.JRPdfExporter) CMISService(it.cnr.cool.cmis.service.CMISService) java.util(java.util) MimeTypes(it.cnr.cool.util.MimeTypes) InputStreamResource(net.sf.jasperreports.repo.InputStreamResource) SimpleDateFormat(java.text.SimpleDateFormat) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput) NumberFormat(java.text.NumberFormat) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream) PDFont(org.apache.pdfbox.pdmodel.font.PDFont) Value(org.springframework.beans.factory.annotation.Value) GroupsEnum(it.cnr.cool.security.GroupsEnum) Resource(net.sf.jasperreports.repo.Resource) Service(org.springframework.stereotype.Service) AttachmentBean(it.cnr.cool.mail.model.AttachmentBean) StatoDomanda(it.cnr.si.cool.jconon.service.application.ApplicationService.StatoDomanda) StreamSupport(java.util.stream.StreamSupport) Restrictions(it.cnr.si.opencmis.criteria.restrictions.Restrictions) RepositoryService(net.sf.jasperreports.repo.RepositoryService) PropertyDateTimeDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDateTimeDefinition) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) org.apache.chemistry.opencmis.client.api(org.apache.chemistry.opencmis.client.api) org.apache.poi.hssf.usermodel(org.apache.poi.hssf.usermodel) it.cnr.si.cool.jconon.cmis.model(it.cnr.si.cool.jconon.cmis.model) Pair(it.cnr.cool.util.Pair) com.google.gson(com.google.gson) UserService(it.cnr.cool.security.service.UserService) ReportResource(net.sf.jasperreports.repo.ReportResource) LoggerFactory(org.slf4j.LoggerFactory) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) WriterException(com.google.zxing.WriterException) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JcononGroups(it.cnr.si.cool.jconon.util.JcononGroups) JSONObject(org.json.JSONObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JRGzipVirtualizer(net.sf.jasperreports.engine.fill.JRGzipVirtualizer) ParseException(java.text.ParseException) DateFormat(java.text.DateFormat) PDFTextStripper(org.apache.pdfbox.text.PDFTextStripper) JRDocxExporter(net.sf.jasperreports.engine.export.ooxml.JRDocxExporter) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) ACLService(it.cnr.cool.cmis.service.ACLService) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) QrCodeUtil(it.cnr.si.cool.jconon.util.QrCodeUtil) StringUtil(it.cnr.cool.util.StringUtil) ACLType(it.cnr.cool.cmis.model.ACLType) Collectors(java.util.stream.Collectors) List(java.util.List) PropertyBooleanDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyBooleanDefinition) Type(java.lang.reflect.Type) PropertyIds(org.apache.chemistry.opencmis.commons.PropertyIds) BitMatrix(com.google.zxing.common.BitMatrix) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) MatrixToImageWriter(com.google.zxing.client.j2se.MatrixToImageWriter) CMISPropertyIds(it.cnr.si.cool.jconon.util.CMISPropertyIds) ClassPathResource(org.springframework.core.io.ClassPathResource) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ApplicationModel(it.cnr.si.cool.jconon.model.ApplicationModel) NodeVersionService(it.cnr.cool.cmis.service.NodeVersionService) Criteria(it.cnr.si.opencmis.criteria.Criteria) JPEGFactory(org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory) AppendMode(org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode) Util(it.cnr.cool.rest.util.Util) net.sf.jasperreports.engine(net.sf.jasperreports.engine) CacheRepository(it.cnr.si.cool.jconon.repository.CacheRepository) Logger(org.slf4j.Logger) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession) BulkInfo(it.cnr.bulkinfo.BulkInfo) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) Code39Writer(com.google.zxing.oned.Code39Writer) ApplicationContext(org.springframework.context.ApplicationContext) JRPdfExporterParameter(net.sf.jasperreports.engine.export.JRPdfExporterParameter) PDRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) EmailMessage(it.cnr.cool.mail.model.EmailMessage) java.io(java.io) FieldPropertySet(it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet) BulkInfoCoolService(it.cnr.cool.service.BulkInfoCoolService) SimpleDocxReportConfiguration(net.sf.jasperreports.export.SimpleDocxReportConfiguration) Bean(org.springframework.context.annotation.Bean) I18nService(it.cnr.cool.service.I18nService) StringUtils(org.springframework.util.StringUtils) Criteria(it.cnr.si.opencmis.criteria.Criteria) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) PrintDetailBulk(it.cnr.si.cool.jconon.model.PrintDetailBulk) Pair(it.cnr.cool.util.Pair)

Example 5 with PrintDetailBulk

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;
}
Also used : Criteria(it.cnr.si.opencmis.criteria.Criteria) BigInteger(java.math.BigInteger) List(java.util.List) PrintDetailBulk(it.cnr.si.cool.jconon.model.PrintDetailBulk) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

PrintDetailBulk (it.cnr.si.cool.jconon.model.PrintDetailBulk)5 BigInteger (java.math.BigInteger)4 Criteria (it.cnr.si.opencmis.criteria.Criteria)3 List (java.util.List)3 WriterException (com.google.zxing.WriterException)2 BulkInfo (it.cnr.bulkinfo.BulkInfo)2 FieldProperty (it.cnr.bulkinfo.BulkInfoImpl.FieldProperty)2 FieldPropertySet (it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet)2 ACLType (it.cnr.cool.cmis.model.ACLType)2 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)2 Pair (it.cnr.cool.util.Pair)2 CMISApplicationException (it.cnr.cool.web.scripts.exception.CMISApplicationException)2 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 PDImageXObject (org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject)2 JSONObject (org.json.JSONObject)2 com.google.gson (com.google.gson)1 BarcodeFormat (com.google.zxing.BarcodeFormat)1 MatrixToImageWriter (com.google.zxing.client.j2se.MatrixToImageWriter)1 BitMatrix (com.google.zxing.common.BitMatrix)1