|
49 | 49 | import java.lang.annotation.Annotation; |
50 | 50 | import java.lang.reflect.Field; |
51 | 51 | import java.lang.reflect.Method; |
| 52 | +import java.lang.reflect.Modifier; |
52 | 53 | import java.lang.reflect.ParameterizedType; |
53 | 54 | import java.lang.reflect.Type; |
54 | 55 | import java.util.ArrayList; |
|
71 | 72 | import org.hisp.dhis.schema.Property; |
72 | 73 | import org.hisp.dhis.schema.SchemaService; |
73 | 74 | import org.hisp.dhis.system.util.ReflectionUtils; |
| 75 | +import org.hisp.dhis.translation.Translatable; |
74 | 76 | import org.springframework.util.ClassUtils; |
75 | 77 |
|
76 | 78 | /** |
@@ -117,6 +119,20 @@ public void introspect(Class<?> type, Map<String, Property> properties) { |
117 | 119 |
|
118 | 120 | if (persistedProperties.containsKey(fieldName)) { |
119 | 121 | initFromPersistedProperty(property, persistedProperties.get(fieldName)); |
| 122 | + } else { |
| 123 | + Method getter = property.getGetterMethod(); |
| 124 | + if (getter != null) { |
| 125 | + Class<?> declaringClass = getter.getDeclaringClass(); |
| 126 | + if (declaringClass.getName().startsWith("Base") |
| 127 | + && !property.isTransient() |
| 128 | + && (!getter.isAnnotationPresent(Translatable.class) |
| 129 | + || !persistedProperties.containsKey( |
| 130 | + getter.getAnnotation(Translatable.class).propertyName()))) { |
| 131 | + // this is assumed to be an inherited property that is not persisted, |
| 132 | + // so we skip it and do not add it |
| 133 | + continue; |
| 134 | + } |
| 135 | + } |
120 | 136 | } |
121 | 137 |
|
122 | 138 | initFromDescription(property); |
@@ -224,6 +240,7 @@ private static void initFromEnumConstants(Property property) { |
224 | 240 | private static void initFromPersistedProperty(Property property, Property persisted) { |
225 | 241 | property.setPersisted(true); |
226 | 242 | property.setWritable(true); |
| 243 | + property.setTransient(false); |
227 | 244 | property.setFieldName(persisted.getFieldName()); |
228 | 245 | property.setUnique(persisted.isUnique()); |
229 | 246 | property.setRequired(persisted.isRequired()); |
@@ -331,6 +348,7 @@ private static List<Property> collectProperties(Class<?> type) { |
331 | 348 |
|
332 | 349 | property.setName(name); |
333 | 350 | property.setFieldName(fieldName); |
| 351 | + property.setTransient(Modifier.isTransient(field.getModifiers())); |
334 | 352 | property.setSetterMethod(findSetterMethod(fieldName, type, field.getType())); |
335 | 353 | property.setGetterMethod(findGetterMethod(fieldName, type)); |
336 | 354 | property.setNamespace(trimToNull(jsonProperty.namespace())); |
|
0 commit comments