HSAdmin Backend Domains, E-Mail, Datenbanken
Purodha
2013-01-05 9b3192c230a9d37ecb7d72a0c911d1f707460813
moduleprops now generally working for referredProps, too. Annotations for testing added to Customer. Added qualified field type.
2 files modified
61 ■■■■ changed files
hsarback/src/de/hsadmin/mods/cust/Customer.java 9 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/remote/ModulePropertiesRemote.java 52 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/cust/Customer.java
@@ -81,13 +81,14 @@
    private Set<Contact> contacts;
    @OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
    //@AnnFieldIO(referredProps = "customer")
    //@AnnFieldIO(referredProps = "customer.CustomersTariffl")
    //@AnnFieldIO(referredProps = "customer.CustomersTariff.domainDiscountUntil")
    //@AnnFieldIO(referredProps = "customer")//gut
    //@AnnFieldIO(referredProps = "customer.CustomersTariff.domainDiscountUntil")//Das ist Kappes!
    //@AnnFieldIO(referredProps = "customer.billData.domainDiscountUntil.year")//falsch!
    @AnnFieldIO(referredProps = "customer.billData.domainDiscountUntil.cdate")//gut
    private BankAccount bankAccount;
    @OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
    //@AnnFieldIO(referredProps = "domainDiscountUntil")
    @AnnFieldIO(referredProps = "domainDiscountUntil")
    private CustomersTariff billData;
    @OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "customer")
hsarback/src/de/hsadmin/remote/ModulePropertiesRemote.java
@@ -51,11 +51,13 @@
                                propertyProperties.put("rw", rw.name());
                                String[] referredProps = fieldIO.referredProps();
                                propertyProperties.put("referredProps", referredProps);                            
                                Class<?> declaringClass = f.getDeclaringClass();
                //                Class<?> declaringClass = f.getDeclaringClass();
                //                         declaringClass = f.getDeclaringClass();
                                for(String s : referredProps){                    
                                    String fullPropertyName = fieldName+"."+s;            
                                    propertiesList.add(createReferredPropertyInfo(fullPropertyName, declaringClass, fullPropertyName));
                                    propertiesList.add(createReferredPropertyInfo(fullPropertyName, f, s));
                                }
                                AddCommonPropertyInfo(propertyProperties, f);
                                propertiesList.add(propertyProperties);
                            }
                        }                                            
@@ -73,18 +75,42 @@
        }
    }
    private Map<String, Object> createReferredPropertyInfo(String fieldName, Class<?> declaringClass,
            String propertyName) throws SecurityException, NoSuchFieldException {
        int indexOfDot = propertyName.indexOf('.');
        if (indexOfDot>=0) {
            String prefix = propertyName.substring(0, indexOfDot);
            String remainingPart = propertyName.substring(indexOfDot + 1);
            return createReferredPropertyInfo(fieldName, declaringClass.getDeclaredField(prefix).getDeclaringClass(), remainingPart);
        } else {
            Map<String, Object> result = new HashMap<String, Object>();
            result.put("property", fieldName);
            return result;
    private Map<String, Object> createReferredPropertyInfo(String propertyName, Field sourceField,
            String annotated) throws SecurityException {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("property", propertyName);
//        String trace = "" ;
        Field field = sourceField;
        String remainingPart = annotated;
        int indexOfDot = 0;
        while (indexOfDot>=0) {
            indexOfDot = remainingPart.indexOf('.');
            Class<?> fieldType = field.getType();
            String prefix = (indexOfDot>=0 ? remainingPart.substring(0, indexOfDot) : remainingPart);
            try {
                field = fieldType.getDeclaredField(prefix);
            } catch (Exception NoSuchFieldException) {
                Field[] flds = fieldType.getDeclaredFields();
                String trace = indexOfDot
                        + " SF=" + field.getName()
                        +" T=" + fieldType.getName()
                        + " (" + flds.length +" fields):";
                for (Field f : flds ){
                    trace = trace + " " + f.getName();
                }
                trace = trace + " [" + prefix + " missing]" ;
                result.put("BOOM", trace);
                return result;
            }
//            trace = trace + " TF=" + field.getName();
            remainingPart = remainingPart.substring(indexOfDot + 1);
        }
        AddCommonPropertyInfo(result, field);
        return result;
    }
    private void AddCommonPropertyInfo(Map<String, Object> propertyInfo, Field sourceField) {
            propertyInfo.put("type", sourceField.getType().getName());
    }
    @Override