Package org.apache.chemistry.opencmis.commons.impl.dataobjects

Examples of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl


        }

        Map<String, PropertyData<?>> propMap = properties.getProperties();
        Map<String, PropertyData<?>> propMapNew = setDefaultProperties(typeDef, propMap);
        if (propMapNew != propMap) {
            properties = new PropertiesImpl(propMapNew.values());
        }

        TypeValidator.validateProperties(typeDef, properties, true);

        // validate ACL
View Full Code Here


       // set default properties
       Map<String, PropertyData<?>> propMap = properties.getProperties();
       Map<String, PropertyData<?>> propMapNew = setDefaultProperties(typeDef, propMap);
       if (propMapNew != propMap) {
           properties = new PropertiesImpl(propMapNew.values());
       }

       TypeValidator.validateProperties(typeDef, properties, true);

       // validate ACL
View Full Code Here

    public static Properties convertProperties(Map<String, Object> json) {
        if (json == null) {
            return null;
        }

        PropertiesImpl result = new PropertiesImpl();

        for (Object jsonProperty : json.values()) {
            Map<String, Object> jsonPropertyMap = getMap(jsonProperty);
            if (jsonPropertyMap != null) {
                AbstractPropertyData<?> property = null;

                String id = getString(jsonPropertyMap, JSON_PROPERTY_ID);
                if (id == null) {
                    throw new CmisRuntimeException("Invalid property!");
                }

                PropertyType propertyType = null;
                try {
                    propertyType = PropertyType.fromValue(getString(jsonPropertyMap, JSON_PROPERTY_DATATYPE));
                } catch (Exception e) {
                    throw new CmisRuntimeException("Invalid property: " + id);
                }

                Object value = jsonPropertyMap.get(JSON_PROPERTY_VALUE);
                List<Object> values = null;
                if (value instanceof List) {
                    values = (List<Object>) value;
                } else if (value != null) {
                    values = Collections.singletonList(value);
                }

                switch (propertyType) {
                case STRING:
                    property = new PropertyStringImpl();
                    {
                        List<String> propertyValues = null;
                        if (values != null) {
                            propertyValues = new ArrayList<String>();
                            for (Object obj : values) {
                                if (obj instanceof String) {
                                    propertyValues.add(obj.toString());
                                } else {
                                    throw new CmisRuntimeException("Invalid property value: " + obj);
                                }
                            }
                        }
                        ((PropertyStringImpl) property).setValues(propertyValues);
                    }
                    break;
                case ID:
                    property = new PropertyIdImpl();
                    {
                        List<String> propertyValues = null;
                        if (values != null) {
                            propertyValues = new ArrayList<String>();
                            for (Object obj : values) {
                                if (obj instanceof String) {
                                    propertyValues.add(obj.toString());
                                } else {
                                    throw new CmisRuntimeException("Invalid property value: " + obj);
                                }
                            }
                        }
                        ((PropertyIdImpl) property).setValues(propertyValues);
                    }
                    break;
                case BOOLEAN:
                    property = new PropertyBooleanImpl();
                    {
                        List<Boolean> propertyValues = null;
                        if (values != null) {
                            propertyValues = new ArrayList<Boolean>();
                            for (Object obj : values) {
                                if (obj instanceof Boolean) {
                                    propertyValues.add((Boolean) obj);
                                } else {
                                    throw new CmisRuntimeException("Invalid property value: " + obj);
                                }
                            }
                        }
                        ((PropertyBooleanImpl) property).setValues(propertyValues);
                    }
                    break;
                case INTEGER:
                    property = new PropertyIntegerImpl();
                    {
                        List<BigInteger> propertyValues = null;
                        if (values != null) {
                            propertyValues = new ArrayList<BigInteger>();
                            for (Object obj : values) {
                                if (obj instanceof BigInteger) {
                                    propertyValues.add((BigInteger) obj);
                                } else {
                                    throw new CmisRuntimeException("Invalid property value: " + obj);
                                }
                            }
                        }
                        ((PropertyIntegerImpl) property).setValues(propertyValues);
                    }
                    break;
                case DECIMAL:
                    property = new PropertyDecimalImpl();
                    {
                        List<BigDecimal> propertyValues = null;
                        if (values != null) {
                            propertyValues = new ArrayList<BigDecimal>();
                            for (Object obj : values) {
                                if (obj instanceof BigDecimal) {
                                    propertyValues.add((BigDecimal) obj);
                                } else if (obj instanceof BigInteger) {
                                    propertyValues.add(new BigDecimal((BigInteger) obj));
                                } else {
                                    throw new CmisRuntimeException("Invalid property value: " + obj);
                                }
                            }
                        }
                        ((PropertyDecimalImpl) property).setValues(propertyValues);
                    }
                    break;
                case DATETIME:
                    property = new PropertyDateTimeImpl();
                    {
                        List<GregorianCalendar> propertyValues = null;
                        if (values != null) {
                            propertyValues = new ArrayList<GregorianCalendar>();
                            for (Object obj : values) {
                                if (obj instanceof Number) {
                                    GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
                                    cal.setTimeInMillis(((Number) obj).longValue());
                                    propertyValues.add(cal);
                                } else {
                                    throw new CmisRuntimeException("Invalid property value: " + obj);
                                }
                            }
                        }
                        ((PropertyDateTimeImpl) property).setValues(propertyValues);
                    }
                    break;
                case HTML:
                    property = new PropertyHtmlImpl();
                    {
                        List<String> propertyValues = null;
                        if (values != null) {
                            propertyValues = new ArrayList<String>();
                            for (Object obj : values) {
                                if (obj instanceof String) {
                                    propertyValues.add(obj.toString());
                                } else {
                                    throw new CmisRuntimeException("Invalid property value: " + obj);
                                }
                            }
                        }
                        ((PropertyHtmlImpl) property).setValues(propertyValues);
                    }
                    break;
                case URI:
                    property = new PropertyUriImpl();
                    {
                        List<String> propertyValues = null;
                        if (values != null) {
                            propertyValues = new ArrayList<String>();
                            for (Object obj : values) {
                                if (obj instanceof String) {
                                    propertyValues.add(obj.toString());
                                } else {
                                    throw new CmisRuntimeException("Invalid property value: " + obj);
                                }
                            }
                        }
                        ((PropertyUriImpl) property).setValues(propertyValues);
                    }
                    break;
                }

                property.setId(id);
                property.setDisplayName(getString(jsonPropertyMap, JSON_PROPERTY_DISPLAYNAME));
                property.setQueryName(getString(jsonPropertyMap, JSON_PROPERTY_QUERYNAME));
                property.setLocalName(getString(jsonPropertyMap, JSON_PROPERTY_LOCALNAME));

                convertExtension(jsonPropertyMap, property, PROPERTY_KEYS);

                result.addProperty(property);
            }
        }

        // TODO: properties extensions
View Full Code Here

    public static Properties convert(CmisPropertiesType properties) {
        if (properties == null) {
            return null;
        }

        PropertiesImpl result = new PropertiesImpl();

        for (CmisProperty property : properties.getProperty()) {
            result.addProperty(convert(property));
        }

        // handle extensions
        convertExtension(properties, result);
View Full Code Here

            PropertyInteger pi = objFactory.createPropertyIntegerData(funcEntry.getValue(), BigInteger.valueOf(100));
            // fixed dummy value
            mappedProperties.put(funcEntry.getKey(), pi);
        }

        Properties props = new PropertiesImpl(mappedProperties.values());
        return props;
    }
View Full Code Here

        TypeDefinition typeDef = typeCache.getTypeDefinition(typeId);
        if (typeDef == null) {
            throw new CmisInvalidArgumentException("Invalid type: " + typeId);
        }

        PropertiesImpl result = new PropertiesImpl();

        int i = 0;
        for (String propertyId : propertyIds) {
            PropertyDefinition<?> propDef = typeDef.getPropertyDefinitions().get(propertyId);
            if (propDef == null) {
                throw new CmisInvalidArgumentException(propertyId + " is unknown!");
            }

            PropertyData<?> propertyData = null;

            if (singleValuePropertyMap != null && singleValuePropertyMap.containsKey(i)) {
                propertyData = createPropertyData(propDef, singleValuePropertyMap.get(i));
            } else if (multiValuePropertyMap != null && multiValuePropertyMap.containsKey(i)) {
                propertyData = createPropertyData(propDef, controlParser.getValues(Constants.CONTROL_PROP_VALUE, i));
            } else {
                propertyData = createPropertyData(propDef, null);
            }

            result.addProperty(propertyData);

            i++;
        }

        return result;
View Full Code Here

        try {
            ObjectDataImpl result = new ObjectDataImpl();
            ObjectInfoImpl objectInfo = new ObjectInfoImpl();

            PropertiesImpl properties = new PropertiesImpl();
            filter = filter == null ? null : new HashSet<String>(filter);
            compileProperties(properties, filter, objectInfo);
            result.setProperties(properties);
            if (filter != null && !filter.isEmpty()) {
                log.debug("Unknown filter properties: " + filter.toString());
View Full Code Here

        // file name
        String name = source.getName();

        // get properties
        PropertiesImpl sourceProperties = new PropertiesImpl();
        readCustomProperties(source, sourceProperties, null, new ObjectInfoImpl());

        // get the type id
        String typeId = getIdProperty(sourceProperties, PropertyIds.OBJECT_TYPE_ID);
        if (typeId == null) {
            typeId = TypeManager.DOCUMENT_TYPE_ID;
        }

        // copy properties
        PropertiesImpl newProperties = new PropertiesImpl();
        for (PropertyData<?> prop : sourceProperties.getProperties().values()) {
            if ((prop.getId().equals(PropertyIds.OBJECT_TYPE_ID)) || (prop.getId().equals(PropertyIds.CREATED_BY))
                    || (prop.getId().equals(PropertyIds.CREATION_DATE))
                    || (prop.getId().equals(PropertyIds.LAST_MODIFIED_BY))) {
                continue;
            }

            newProperties.addProperty(prop);
        }

        // replace properties
        if (properties != null) {
            // find new name
            String newName = getStringProperty(properties, PropertyIds.NAME);
            if (newName != null) {
                if (!isValidName(newName)) {
                    throw new CmisNameConstraintViolationException("Name is not valid!");
                }
                name = newName;
            }

            // get the property definitions
            TypeDefinition type = fTypes.getType(typeId);
            if (type == null) {
                throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
            }

            // replace with new values
            for (PropertyData<?> prop : properties.getProperties().values()) {
                PropertyDefinition<?> propType = type.getPropertyDefinitions().get(prop.getId());

                // do we know that property?
                if (propType == null) {
                    throw new CmisConstraintException("Property '" + prop.getId() + "' is unknown!");
                }

                // can it be set?
                if ((propType.getUpdatability() != Updatability.READWRITE)) {
                    throw new CmisConstraintException("Property '" + prop.getId() + "' cannot be updated!");
                }

                // empty properties are invalid
                if (isEmptyProperty(prop)) {
                    throw new CmisConstraintException("Property '" + prop.getId() + "' must not be empty!");
                }

                newProperties.addProperty(prop);
            }
        }

        addPropertyId(newProperties, typeId, null, PropertyIds.OBJECT_TYPE_ID, typeId);
        addPropertyString(newProperties, typeId, null, PropertyIds.CREATED_BY, context.getUsername());
View Full Code Here

        if (isRename && !isValidName(newName)) {
            throw new CmisNameConstraintViolationException("Name is not valid!");
        }

        // get old properties
        PropertiesImpl oldProperties = new PropertiesImpl();
        readCustomProperties(file, oldProperties, null, new ObjectInfoImpl());

        // get the type id
        String typeId = getIdProperty(oldProperties, PropertyIds.OBJECT_TYPE_ID);
        if (typeId == null) {
View Full Code Here

            objectInfo.setWorkingCopyOriginalId(null);
        }

        // let's do it
        try {
            PropertiesImpl result = new PropertiesImpl();

            // id
            String id = fileToId(file);
            addPropertyId(result, typeId, filter, PropertyIds.OBJECT_ID, id);
            objectInfo.setId(id);
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.