Search in sources :

Example 1 with PropertyDecimalDefinition

use of org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition 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;
}
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) PropertyDecimalDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition) FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) PropertyDateTimeDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDateTimeDefinition) NumberStyleFormatter(org.springframework.format.number.NumberStyleFormatter) BulkInfo(it.cnr.bulkinfo.BulkInfo) PropertyBooleanDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyBooleanDefinition) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) Pair(it.cnr.cool.util.Pair)

Example 2 with PropertyDecimalDefinition

use of org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition in project copper-cms by PogeyanOSS.

the class JSONConverter method convert.

/**
 * Converts a property type definition.
 */
public static JSONObject convert(final PropertyDefinition<?> propertyDefinition, final DateTimeFormat dateTimeFormat) {
    if (propertyDefinition == null) {
        return null;
    }
    JSONObject result = new JSONObject();
    // type specific
    if (propertyDefinition instanceof PropertyStringDefinition) {
        setIfNotNull(JSON_PROPERTY_TYPE_MAX_LENGTH, ((PropertyStringDefinition) propertyDefinition).getMaxLength(), result);
    } else if (propertyDefinition instanceof PropertyIdDefinition) {
    // nothing to do
    } else if (propertyDefinition instanceof PropertyIntegerDefinition) {
        setIfNotNull(JSON_PROPERTY_TYPE_MIN_VALUE, ((PropertyIntegerDefinition) propertyDefinition).getMinValue(), result);
        setIfNotNull(JSON_PROPERTY_TYPE_MAX_VALUE, ((PropertyIntegerDefinition) propertyDefinition).getMaxValue(), result);
    } else if (propertyDefinition instanceof PropertyDecimalDefinition) {
        setIfNotNull(JSON_PROPERTY_TYPE_MIN_VALUE, ((PropertyDecimalDefinition) propertyDefinition).getMinValue(), result);
        setIfNotNull(JSON_PROPERTY_TYPE_MAX_VALUE, ((PropertyDecimalDefinition) propertyDefinition).getMaxValue(), result);
        DecimalPrecision precision = ((PropertyDecimalDefinition) propertyDefinition).getPrecision();
        if (precision != null) {
            result.put(JSON_PROPERTY_TYPE_PRECISION, String.valueOf(precision.value().intValue()));
        }
    } else if (propertyDefinition instanceof PropertyBooleanDefinition) {
    // nothing to do
    } else if (propertyDefinition instanceof PropertyDateTimeDefinition) {
        DateTimeResolution resolution = ((PropertyDateTimeDefinition) propertyDefinition).getDateTimeResolution();
        if (resolution != null) {
            result.put(JSON_PROPERTY_TYPE_RESOLUTION, resolution.value());
        }
    } else if (propertyDefinition instanceof PropertyHtmlDefinition) {
    // nothing to do
    } else if (propertyDefinition instanceof PropertyUriDefinition) {
    // nothing to do
    } else {
        assert false;
    }
    // default value
    if (propertyDefinition.getDefaultValue() != null) {
        if (propertyDefinition.getCardinality() == Cardinality.SINGLE) {
            if (!propertyDefinition.getDefaultValue().isEmpty()) {
                result.put(JSON_PROPERTY_TYPE_DEAULT_VALUE, getJSONValue(propertyDefinition.getDefaultValue().get(0), dateTimeFormat));
            }
        } else {
            JSONArray values = new JSONArray();
            for (Object value : propertyDefinition.getDefaultValue()) {
                values.add(getJSONValue(value, dateTimeFormat));
            }
            result.put(JSON_PROPERTY_TYPE_DEAULT_VALUE, values);
        }
    }
    // choices
    if (isNotEmpty(propertyDefinition.getChoices())) {
        result.put(JSON_PROPERTY_TYPE_CHOICE, convertChoices(propertyDefinition.getChoices(), propertyDefinition.getCardinality(), dateTimeFormat));
    }
    // generic
    result.put(JSON_PROPERTY_TYPE_ID, propertyDefinition.getId());
    result.put(JSON_PROPERTY_TYPE_LOCALNAME, propertyDefinition.getLocalName());
    setIfNotNull(JSON_PROPERTY_TYPE_LOCALNAMESPACE, propertyDefinition.getLocalNamespace(), result);
    setIfNotNull(JSON_PROPERTY_TYPE_DISPLAYNAME, propertyDefinition.getDisplayName(), result);
    setIfNotNull(JSON_PROPERTY_TYPE_QUERYNAME, propertyDefinition.getQueryName(), result);
    setIfNotNull(JSON_PROPERTY_TYPE_DESCRIPTION, propertyDefinition.getDescription(), result);
    result.put(JSON_PROPERTY_TYPE_PROPERTY_TYPE, getJSONEnumValue(propertyDefinition.getPropertyType()));
    result.put(JSON_PROPERTY_TYPE_CARDINALITY, getJSONEnumValue(propertyDefinition.getCardinality()));
    result.put(JSON_PROPERTY_TYPE_UPDATABILITY, getJSONEnumValue(propertyDefinition.getUpdatability()));
    setIfNotNull(JSON_PROPERTY_TYPE_INHERITED, propertyDefinition.isInherited(), result);
    result.put(JSON_PROPERTY_TYPE_REQUIRED, propertyDefinition.isRequired());
    result.put(JSON_PROPERTY_TYPE_QUERYABLE, propertyDefinition.isQueryable());
    result.put(JSON_PROPERTY_TYPE_ORDERABLE, propertyDefinition.isOrderable());
    setIfNotNull(JSON_PROPERTY_TYPE_OPENCHOICE, propertyDefinition.isOpenChoice(), result);
    convertExtension(propertyDefinition, result);
    return result;
}
Also used : PropertyDecimalDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) DecimalPrecision(org.apache.chemistry.opencmis.commons.enums.DecimalPrecision) PropertyHtmlDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyHtmlDefinition) PropertyIdDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyIdDefinition) PropertyDateTimeDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDateTimeDefinition) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) PropertyIntegerDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyIntegerDefinition) PropertyBooleanDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyBooleanDefinition) PropertyUriDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyUriDefinition) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) DateTimeResolution(org.apache.chemistry.opencmis.commons.enums.DateTimeResolution) PropertyStringDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyStringDefinition)

Aggregations

PropertyBooleanDefinition (org.apache.chemistry.opencmis.commons.definitions.PropertyBooleanDefinition)2 PropertyDateTimeDefinition (org.apache.chemistry.opencmis.commons.definitions.PropertyDateTimeDefinition)2 PropertyDecimalDefinition (org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition)2 com.google.gson (com.google.gson)1 BarcodeFormat (com.google.zxing.BarcodeFormat)1 WriterException (com.google.zxing.WriterException)1 MatrixToImageWriter (com.google.zxing.client.j2se.MatrixToImageWriter)1 BitMatrix (com.google.zxing.common.BitMatrix)1 Code39Writer (com.google.zxing.oned.Code39Writer)1 BulkInfo (it.cnr.bulkinfo.BulkInfo)1 FieldProperty (it.cnr.bulkinfo.BulkInfoImpl.FieldProperty)1 FieldPropertySet (it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet)1 ACLType (it.cnr.cool.cmis.model.ACLType)1 CoolPropertyIds (it.cnr.cool.cmis.model.CoolPropertyIds)1 ACLService (it.cnr.cool.cmis.service.ACLService)1 CMISService (it.cnr.cool.cmis.service.CMISService)1 NodeVersionService (it.cnr.cool.cmis.service.NodeVersionService)1 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)1 MailService (it.cnr.cool.mail.MailService)1 AttachmentBean (it.cnr.cool.mail.model.AttachmentBean)1