Search in sources :

Example 1 with PropertyIntegerImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl in project iaf by ibissource.

the class ObjectServiceImpl method processProperties.

private Properties processProperties(Element cmisElement) throws SenderException {
    PropertiesImpl properties = new PropertiesImpl();
    Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
    Iterator<Node> propertyIterator = XmlUtils.getChildTags(propertiesElement, "property").iterator();
    while (propertyIterator.hasNext()) {
        Element propertyElement = (Element) propertyIterator.next();
        String property = XmlUtils.getStringValue(propertyElement);
        String nameAttr = propertyElement.getAttribute("name");
        String typeAttr = propertyElement.getAttribute("type");
        if (StringUtils.isEmpty(typeAttr) || typeAttr.equalsIgnoreCase("string")) {
            if (nameAttr.startsWith("cmis:")) {
                properties.addProperty(new PropertyIdImpl(nameAttr, property));
            } else {
                properties.addProperty(new PropertyStringImpl(nameAttr, property));
            }
        } else if (typeAttr.equalsIgnoreCase("integer")) {
            properties.addProperty(new PropertyIntegerImpl(nameAttr, new BigInteger(property)));
        } else if (typeAttr.equalsIgnoreCase("boolean")) {
            properties.addProperty(new PropertyBooleanImpl(nameAttr, Boolean.parseBoolean(property)));
        } else if (typeAttr.equalsIgnoreCase("datetime")) {
            String formatStringAttr = propertyElement.getAttribute("formatString");
            if (StringUtils.isEmpty(formatStringAttr)) {
                formatStringAttr = CmisSender.FORMATSTRING_BY_DEFAULT;
            }
            DateFormat df = new SimpleDateFormat(formatStringAttr);
            Date date;
            try {
                date = df.parse(property);
            } catch (ParseException e) {
                throw new SenderException("exception parsing date [" + property + "] using formatString [" + formatStringAttr + "]", e);
            }
            GregorianCalendar gregorian = new GregorianCalendar();
            gregorian.setTime(date);
            properties.addProperty(new PropertyDateTimeImpl(nameAttr, gregorian));
        } else {
            log.warn("unparsable type [" + typeAttr + "] for property [" + property + "]");
        }
        log.debug("set property name [" + nameAttr + "] value [" + property + "]");
    }
    return properties;
}
Also used : PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) PropertyDateTimeImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) GregorianCalendar(java.util.GregorianCalendar) PropertyBooleanImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl) Date(java.util.Date) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) PropertyIntegerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) BigInteger(java.math.BigInteger) ParseException(java.text.ParseException) SenderException(nl.nn.adapterframework.core.SenderException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with PropertyIntegerImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl in project iaf by ibissource.

the class CmisUtils method processProperties.

public static Properties processProperties(Element cmisElement) {
    PropertiesImpl properties = new PropertiesImpl();
    Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
    Iterator<Node> propertyIterator = XmlUtils.getChildTags(propertiesElement, "property").iterator();
    while (propertyIterator.hasNext()) {
        Element propertyElement = (Element) propertyIterator.next();
        String propertyValue = XmlUtils.getStringValue(propertyElement);
        String nameAttr = propertyElement.getAttribute("name");
        String typeAttr = propertyElement.getAttribute("type");
        PropertyType propertyType = PropertyType.STRING;
        if (StringUtils.isNotEmpty(typeAttr)) {
            propertyType = PropertyType.fromValue(typeAttr);
        }
        if (StringUtils.isEmpty(typeAttr) && nameAttr.startsWith("cmis:")) {
            propertyType = PropertyType.ID;
        }
        boolean isNull = Boolean.parseBoolean(propertyElement.getAttribute("isNull"));
        if (isNull)
            propertyValue = null;
        switch(propertyType) {
            case ID:
                properties.addProperty(new PropertyIdImpl(addStandardDefinitions(new PropertyIdDefinitionImpl(), propertyElement, propertyType), propertyValue));
                break;
            case STRING:
                properties.addProperty(new PropertyStringImpl(addStandardDefinitions(new PropertyStringDefinitionImpl(), propertyElement, propertyType), propertyValue));
                break;
            case INTEGER:
                BigInteger bigInt = null;
                if (StringUtils.isNotEmpty(propertyValue)) {
                    bigInt = new BigInteger(propertyValue);
                }
                properties.addProperty(new PropertyIntegerImpl(addStandardDefinitions(new PropertyIntegerDefinitionImpl(), propertyElement, propertyType), bigInt));
                break;
            case DATETIME:
                GregorianCalendar gregorian = null;
                if (StringUtils.isNotEmpty(propertyValue)) {
                    String formatStringAttr = propertyElement.getAttribute("formatString");
                    String timezoneAttr = propertyElement.getAttribute("timezone");
                    if (StringUtils.isEmpty(formatStringAttr)) {
                        formatStringAttr = CmisUtils.FORMATSTRING_BY_DEFAULT;
                    }
                    DateFormat df = new SimpleDateFormat(formatStringAttr);
                    try {
                        Date date = df.parse(propertyValue);
                        gregorian = new GregorianCalendar();
                        gregorian.setTime(date);
                        if (StringUtils.isNotEmpty(timezoneAttr)) {
                            gregorian.setTimeZone(TimeZone.getTimeZone(timezoneAttr));
                        }
                    } catch (ParseException e) {
                        log.warn("exception parsing date [" + propertyValue + "] using formatString [" + formatStringAttr + "]", e);
                    }
                }
                properties.addProperty(new PropertyDateTimeImpl(addStandardDefinitions(new PropertyDateTimeDefinitionImpl(), propertyElement, propertyType), gregorian));
                break;
            case BOOLEAN:
                Boolean bool = null;
                if (StringUtils.isNotEmpty(propertyValue)) {
                    bool = Boolean.parseBoolean(propertyValue);
                }
                properties.addProperty(new PropertyBooleanImpl(addStandardDefinitions(new PropertyBooleanDefinitionImpl(), propertyElement, propertyType), bool));
                break;
            case DECIMAL:
                BigDecimal decimal = null;
                if (StringUtils.isNotEmpty(propertyValue)) {
                    decimal = new BigDecimal(propertyValue);
                }
                properties.addProperty(new PropertyDecimalImpl(addStandardDefinitions(new PropertyDecimalDefinitionImpl(), propertyElement, propertyType), decimal));
                break;
            case URI:
                properties.addProperty(new PropertyUriImpl(addStandardDefinitions(new PropertyUriDefinitionImpl(), propertyElement, propertyType), propertyValue));
                break;
            case HTML:
                properties.addProperty(new PropertyHtmlImpl(addStandardDefinitions(new PropertyHtmlDefinitionImpl(), propertyElement, propertyType), propertyValue));
                break;
            default:
                log.warn("unparsable type [" + typeAttr + "] for property [" + propertyValue + "]");
                // Skip all and continue with the next property!
                continue;
        }
        log.debug("set property name [" + nameAttr + "] value [" + propertyValue + "]");
    }
    return properties;
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) PropertyDateTimeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyHtmlImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlImpl) PropertyIntegerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) PropertyBooleanDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl) PropertyUriImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriImpl) PropertyDecimalImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalImpl) PropertyBoolean(org.apache.chemistry.opencmis.commons.data.PropertyBoolean) PropertyStringDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl) PropertyIntegerDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) PropertyIdDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl) PropertyDateTimeImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl) GregorianCalendar(java.util.GregorianCalendar) PropertyHtmlDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl) Date(java.util.Date) PropertyBooleanImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl) BigDecimal(java.math.BigDecimal) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) PropertyUriDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) BigInteger(java.math.BigInteger) PropertyDecimalDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with PropertyIntegerImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl in project alfresco-repository by Alfresco.

the class CMISConnector method getProperty.

@SuppressWarnings("unchecked")
private AbstractPropertyData<?> getProperty(PropertyType propType, PropertyDefinitionWrapper propDef, Serializable value) {
    AbstractPropertyData<?> result = null;
    switch(propType) {
        case BOOLEAN:
            result = new PropertyBooleanImpl();
            if (value instanceof List) {
                ((PropertyBooleanImpl) result).setValues((List<Boolean>) value);
            } else {
                ((PropertyBooleanImpl) result).setValue((Boolean) value);
            }
            break;
        case DATETIME:
            result = new PropertyDateTimeImpl();
            if (value instanceof List) {
                ((PropertyDateTimeImpl) result).setValues((List<GregorianCalendar>) DefaultTypeConverter.INSTANCE.convert(GregorianCalendar.class, (List<?>) value));
            } else {
                ((PropertyDateTimeImpl) result).setValue(DefaultTypeConverter.INSTANCE.convert(GregorianCalendar.class, value));
            }
            break;
        case DECIMAL:
            result = new PropertyDecimalImpl();
            if (value instanceof List) {
                ((PropertyDecimalImpl) result).setValues((List<BigDecimal>) DefaultTypeConverter.INSTANCE.convert(BigDecimal.class, (List<?>) value));
            } else {
                ((PropertyDecimalImpl) result).setValue(DefaultTypeConverter.INSTANCE.convert(BigDecimal.class, value));
            }
            break;
        case HTML:
            result = new PropertyHtmlImpl();
            if (value instanceof List) {
                ((PropertyHtmlImpl) result).setValues((List<String>) value);
            } else {
                ((PropertyHtmlImpl) result).setValue((String) value);
            }
            break;
        case ID:
            result = new PropertyIdImpl();
            if (value instanceof List) {
                ((PropertyIdImpl) result).setValues((List<String>) value);
            } else {
                if (value instanceof NodeRef) {
                    ((PropertyIdImpl) result).setValue(constructObjectId((NodeRef) value, null));
                } else {
                    ((PropertyIdImpl) result).setValue((String) value);
                }
            }
            break;
        case INTEGER:
            result = new PropertyIntegerImpl();
            if (value instanceof List) {
                ((PropertyIntegerImpl) result).setValues((List<BigInteger>) DefaultTypeConverter.INSTANCE.convert(BigInteger.class, (List<?>) value));
            } else {
                ((PropertyIntegerImpl) result).setValue(DefaultTypeConverter.INSTANCE.convert(BigInteger.class, value));
            }
            break;
        case STRING:
            result = new PropertyStringImpl();
            if (value instanceof List) {
                ((PropertyStringImpl) result).setValues((List<String>) value);
            } else {
                // Filter for AtomPub and Web services bindings only. Browser/json binding already encodes.
                if (AlfrescoCmisServiceCall.get() != null && (CallContext.BINDING_ATOMPUB.equals(AlfrescoCmisServiceCall.get().getBinding()) || CallContext.BINDING_WEBSERVICES.equals(AlfrescoCmisServiceCall.get().getBinding()))) {
                    ((PropertyStringImpl) result).setValue(filterXmlRestrictedCharacters((String) value));
                } else {
                    ((PropertyStringImpl) result).setValue((String) value);
                }
            }
            break;
        case URI:
            result = new PropertyUriImpl();
            if (value instanceof List) {
                ((PropertyUriImpl) result).setValues((List<String>) value);
            } else {
                ((PropertyUriImpl) result).setValue((String) value);
            }
            break;
        default:
            throw new RuntimeException("Unknown datatype! Spec change?");
    }
    if (propDef != null) {
        result.setId(propDef.getPropertyDefinition().getId());
        result.setQueryName(propDef.getPropertyDefinition().getQueryName());
        result.setDisplayName(propDef.getPropertyDefinition().getDisplayName());
        result.setLocalName(propDef.getPropertyDefinition().getLocalName());
    }
    return result;
}
Also used : PropertyDateTimeImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl) GregorianCalendar(java.util.GregorianCalendar) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) PropertyBooleanImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl) BigDecimal(java.math.BigDecimal) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) PropertyHtmlImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyIntegerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) PropertyUriImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriImpl) PropertyDecimalImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalImpl) BigInteger(java.math.BigInteger) Collections.singletonList(java.util.Collections.singletonList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with PropertyIntegerImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl in project alfresco-repository by Alfresco.

the class CMISTest method setProperiesToObject.

private void setProperiesToObject(CmisService cmisService, String repositoryId, String objectIdStr, String propertyStr, BigInteger bigIntValue) throws CmisConstraintException {
    Properties properties = cmisService.getProperties(repositoryId, objectIdStr, null, null);
    PropertyIntegerImpl pd = (PropertyIntegerImpl) properties.getProperties().get(propertyStr);
    pd.setValue(bigIntValue);
    Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
    propsList.add(pd);
    Properties newProps = new PropertiesImpl(propsList);
    cmisService.updateProperties(repositoryId, new Holder<String>(objectIdStr), null, newProps, null);
}
Also used : PropertyIntegerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) ArrayList(java.util.ArrayList) Properties(org.apache.chemistry.opencmis.commons.data.Properties)

Aggregations

PropertyIntegerImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl)4 BigInteger (java.math.BigInteger)3 GregorianCalendar (java.util.GregorianCalendar)3 PropertiesImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl)3 PropertyBooleanImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl)3 PropertyDateTimeImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl)3 PropertyIdImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl)3 PropertyStringImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl)3 BigDecimal (java.math.BigDecimal)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)2 PropertyDecimalImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalImpl)2 PropertyHtmlImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlImpl)2 PropertyUriImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriImpl)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2