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