Search in sources :

Example 36 with PropertyConverter

use of org.structr.core.converter.PropertyConverter in project structr by structr.

the class PropertyTest method testInputConverterOnEntityProperty.

/**
 * Test of inputConverter method, of class EntityProperty.
 */
@Test
public void testInputConverterOnEntityProperty() {
    PropertyConverter result = TestSix.oneToOneTestThree.inputConverter(securityContext);
    assertTrue(result != null);
}
Also used : PropertyConverter(org.structr.core.converter.PropertyConverter) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 37 with PropertyConverter

use of org.structr.core.converter.PropertyConverter in project structr by structr.

the class PropertyTest method testDatabaseConverterOnEntityProperty.

/**
 * Test of databaseConverter method, of class EntityProperty.
 */
@Test
public void testDatabaseConverterOnEntityProperty() {
    PropertyConverter expResult = null;
    PropertyConverter result = TestSix.oneToOneTestThree.databaseConverter(securityContext, null);
    assertEquals(expResult, result);
}
Also used : PropertyConverter(org.structr.core.converter.PropertyConverter) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 38 with PropertyConverter

use of org.structr.core.converter.PropertyConverter in project structr by structr.

the class SchemaHelper method getPropertyInfo.

public static Map<String, Object> getPropertyInfo(final SecurityContext securityContext, final PropertyKey property) {
    final Map<String, Object> map = new LinkedHashMap();
    map.put("dbName", property.dbName());
    map.put("jsonName", property.jsonName());
    map.put("className", property.getClass().getName());
    final Class declaringClass = property.getDeclaringClass();
    if (declaringClass != null) {
        map.put("declaringClass", declaringClass.getSimpleName());
    }
    map.put("defaultValue", property.defaultValue());
    if (property instanceof StringProperty) {
        map.put("contentType", ((StringProperty) property).contentType());
    }
    map.put("format", property.format());
    map.put("readOnly", property.isReadOnly());
    map.put("system", property.isSystemInternal());
    map.put("indexed", property.isIndexed());
    map.put("indexedWhenEmpty", property.isIndexedWhenEmpty());
    map.put("compound", property.isCompound());
    map.put("unique", property.isUnique());
    map.put("notNull", property.isNotNull());
    map.put("dynamic", property.isDynamic());
    map.put("hint", property.hint());
    map.put("category", property.category());
    final Class<? extends GraphObject> relatedType = property.relatedType();
    if (relatedType != null) {
        map.put("relatedType", relatedType.getName());
        map.put("type", relatedType.getSimpleName());
        map.put("uiType", relatedType.getSimpleName() + (property.isCollection() ? "[]" : ""));
    } else {
        map.put("type", property.typeName());
        map.put("uiType", property.typeName() + (property.isCollection() ? "[]" : ""));
    }
    map.put("isCollection", property.isCollection());
    final PropertyConverter databaseConverter = property.databaseConverter(securityContext, null);
    final PropertyConverter inputConverter = property.inputConverter(securityContext);
    if (databaseConverter != null) {
        map.put("databaseConverter", databaseConverter.getClass().getName());
    }
    if (inputConverter != null) {
        map.put("inputConverter", inputConverter.getClass().getName());
    }
    // if (declaringClass != null && ("org.structr.dynamic".equals(declaringClass.getPackage().getName()))) {
    if (declaringClass != null && property instanceof RelationProperty) {
        Relation relation = ((RelationProperty) property).getRelation();
        if (relation != null) {
            map.put("relationshipType", relation.name());
        }
    }
    return map;
}
Also used : Relation(org.structr.core.entity.Relation) RelationProperty(org.structr.core.property.RelationProperty) PropertyConverter(org.structr.core.converter.PropertyConverter) StringProperty(org.structr.core.property.StringProperty) GraphObject(org.structr.core.GraphObject) LinkedHashMap(java.util.LinkedHashMap)

Example 39 with PropertyConverter

use of org.structr.core.converter.PropertyConverter in project structr by structr.

the class PropertyMap method cmisTypeToJavaType.

public static PropertyMap cmisTypeToJavaType(final SecurityContext securityContext, final Class type, final Properties properties) throws FrameworkException {
    final Map<String, PropertyData<?>> map = properties.getProperties();
    final ConfigurationProvider config = StructrApp.getConfiguration();
    final PropertyMap propertyMap = new PropertyMap();
    for (final Entry<String, PropertyData<?>> entry : map.entrySet()) {
        final PropertyData<?> propertyValue = entry.getValue();
        Object value = propertyValue.getFirstValue();
        String key = entry.getKey();
        // convert CMIS properties to Structr properties
        if (CMIS_PROPERTY_MAPPING.containsKey(key)) {
            key = CMIS_PROPERTY_MAPPING.get(key);
        }
        final PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, key);
        if (propertyKey != null) {
            final PropertyConverter converter = propertyKey.inputConverter(securityContext);
            if (converter != null) {
                value = converter.convert(value);
            }
            propertyMap.put(propertyKey, value);
        } else {
            throw new FrameworkException(500, "Invalid property key " + key + " for type " + type.getSimpleName() + " provided.");
        }
    }
    return propertyMap;
}
Also used : PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) FrameworkException(org.structr.common.error.FrameworkException) ConfigurationProvider(org.structr.schema.ConfigurationProvider) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject)

Example 40 with PropertyConverter

use of org.structr.core.converter.PropertyConverter in project structr by structr.

the class PropertyMap method databaseTypeToJavaType.

public static PropertyMap databaseTypeToJavaType(final SecurityContext securityContext, final GraphObject wrapped, final Map<String, Object> source) throws FrameworkException {
    final PropertyMap resultMap = new PropertyMap();
    final GraphObject entity = unwrap(wrapped);
    final Class entityType = entity.getClass();
    if (source != null) {
        for (Entry<String, Object> entry : source.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (key != null) {
                final PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(entityType, key);
                final PropertyConverter converter = propertyKey.databaseConverter(securityContext, entity);
                if (converter != null) {
                    try {
                        Object propertyValue = converter.revert(value);
                        resultMap.put(propertyKey, propertyValue);
                    } catch (ClassCastException cce) {
                        throw new FrameworkException(422, "Invalid JSON input for key " + propertyKey.jsonName() + ", expected a JSON " + propertyKey.typeName() + ".");
                    }
                } else {
                    resultMap.put(propertyKey, value);
                }
            }
        }
    }
    return resultMap;
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject)

Aggregations

PropertyConverter (org.structr.core.converter.PropertyConverter)44 GraphObject (org.structr.core.GraphObject)31 FrameworkException (org.structr.common.error.FrameworkException)28 PropertyKey (org.structr.core.property.PropertyKey)18 SecurityContext (org.structr.common.SecurityContext)11 PropertyMap (org.structr.core.property.PropertyMap)10 ConfigurationProvider (org.structr.schema.ConfigurationProvider)10 Map (java.util.Map)9 AbstractNode (org.structr.core.entity.AbstractNode)6 List (java.util.List)5 App (org.structr.core.app.App)5 StructrApp (org.structr.core.app.StructrApp)5 LinkedList (java.util.LinkedList)4 Test (org.junit.Test)4 StructrTest (org.structr.common.StructrTest)4 Query (org.structr.core.app.Query)4 LinkedHashMap (java.util.LinkedHashMap)3 GraphObjectMap (org.structr.core.GraphObjectMap)3 LinkedHashSet (java.util.LinkedHashSet)2 Entry (java.util.Map.Entry)2