Search in sources :

Example 1 with Pair

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);
    }
}
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 Pair

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;
}
Also used : FieldPropertySet(it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet) FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) Pair(it.cnr.cool.util.Pair)

Example 3 with Pair

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;
}
Also used : BulkInfo(it.cnr.bulkinfo.BulkInfo) List(java.util.List) Pair(it.cnr.cool.util.Pair)

Example 4 with Pair

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));
            }
        }
    }
}
Also used : FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) FieldPropertySet(it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet) JSONObject(org.json.JSONObject) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) List(java.util.List) Pair(it.cnr.cool.util.Pair)

Example 5 with Pair

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));
}
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) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException)

Aggregations

Pair (it.cnr.cool.util.Pair)8 BulkInfo (it.cnr.bulkinfo.BulkInfo)6 FieldProperty (it.cnr.bulkinfo.BulkInfoImpl.FieldProperty)6 FieldPropertySet (it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet)6 WriterException (com.google.zxing.WriterException)5 ACLType (it.cnr.cool.cmis.model.ACLType)5 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)5 CMISApplicationException (it.cnr.cool.web.scripts.exception.CMISApplicationException)5 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)5 PrintDetailBulk (it.cnr.si.cool.jconon.model.PrintDetailBulk)5 com.google.gson (com.google.gson)4 BarcodeFormat (com.google.zxing.BarcodeFormat)4 MatrixToImageWriter (com.google.zxing.client.j2se.MatrixToImageWriter)4 BitMatrix (com.google.zxing.common.BitMatrix)4 Code39Writer (com.google.zxing.oned.Code39Writer)4 CoolPropertyIds (it.cnr.cool.cmis.model.CoolPropertyIds)4 ACLService (it.cnr.cool.cmis.service.ACLService)4 CMISService (it.cnr.cool.cmis.service.CMISService)4 NodeVersionService (it.cnr.cool.cmis.service.NodeVersionService)4 MailService (it.cnr.cool.mail.MailService)4