Changeset 29650

Show
Ignore:
Timestamp:
01/26/08 11:01:28 (10 months ago)
Author:
bstefanescu
Message:

property list fix NXP-1994

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/AbstractProperty.java

    r28926 r29650  
    8686 
    8787    public void init(Serializable value) throws PropertyException { 
     88        if (value == null) { // IGNORE null values - properties will be considered PHANTOMS 
     89            return; 
     90        } 
    8891        internalSetValue(value); 
    8992        clearFlags(IS_PHANTOM); 
     
    333336 
    334337    public Serializable getValue() throws PropertyException { 
    335         if (isPhantom()) { 
    336             return (Serializable)getField().getDefaultValue(); 
     338        if (isPhantom() || isRemoved()) { 
     339            return getDefaultValue(); 
    337340        } 
    338341        return internalGetValue(); 
     342    } 
     343 
     344    protected Serializable getDefaultValue() { 
     345        return (Serializable)getField().getDefaultValue(); 
    339346    } 
    340347 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ComplexProperty.java

    r28983 r29650  
    172172    @SuppressWarnings("unchecked") 
    173173    public void init(Serializable value) throws PropertyException { 
    174         if (value == null) { 
    175             return; //TODO ignore null values? 
     174        if (value == null) { // IGNORE null values - properties will be considered PHANTOMS 
     175            return; 
    176176        } 
    177177        Map<String, Serializable> map = (Map<String, Serializable>)value; 
     
    181181        } 
    182182        clearFlags(IS_PHANTOM); 
     183    } 
     184 
     185    @Override 
     186    protected Serializable getDefaultValue() { 
     187        return new HashMap<String, Serializable>(); 
    183188    } 
    184189 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ListProperty.java

    r28479 r29650  
    135135    } 
    136136 
     137    protected Serializable getDefaultValue() { 
     138        Serializable value = (Serializable)getField().getDefaultValue(); 
     139        if (value == null) { 
     140            value = new ArrayList<Serializable>(); 
     141        } 
     142        return value; 
     143    } 
     144 
    137145    @Override 
    138146    public Serializable internalGetValue() throws PropertyException { 
    139147        if (children.isEmpty()) { 
    140             return null
     148            return new ArrayList<String>()
    141149        } 
    142150        //noinspection CollectionDeclaredAsConcreteClass 
     
    171179    @SuppressWarnings("unchecked") 
    172180    public void init(Serializable value)  throws PropertyException { 
    173         if (value != null) { 
    174             List<Serializable> list = null; 
    175             if (value.getClass().isArray()) { // accept also arrays 
    176                 list = (List<Serializable>)PrimitiveArrays.toList(value); 
    177             } else { 
    178                 list = (List<Serializable>)value; 
    179             } 
    180             children.clear(); // do not use clear() method since it is marking the list as dirty 
    181             Field lfield = getType().getField(); 
    182             for (Serializable obj : list) { 
    183                 Property property = getRoot().createProperty(this, lfield, 
    184                         isValidating() ? IS_VALIDATING : 0); 
    185                 property.init(obj); 
    186                 children.add(property); 
    187             } 
     181        if (value == null) { // IGNORE null values - properties will be considered PHANTOMS 
     182            return; 
     183        } 
     184        List<Serializable> list = null; 
     185        if (value.getClass().isArray()) { // accept also arrays 
     186            list = (List<Serializable>)PrimitiveArrays.toList(value); 
     187        } else { 
     188            list = (List<Serializable>)value; 
     189        } 
     190        children.clear(); // do not use clear() method since it is marking the list as dirty 
     191        Field lfield = getType().getField(); 
     192        for (Serializable obj : list) { 
     193            Property property = getRoot().createProperty(this, lfield, 
     194                    isValidating() ? IS_VALIDATING : 0); 
     195            property.init(obj); 
     196            children.add(property); 
    188197        } 
    189198        clearFlags(IS_PHANTOM); 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ScalarProperty.java

    r27627 r29650  
    154154    } 
    155155 
     156    @Override 
     157    public String toString() { 
     158        return getPath() + " = " + ((value == null) ? "[null]" : value); 
     159    } 
    156160} 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/ComplexMemberProperty.java

    r28190 r29650  
    7272    @Override 
    7373    public void init(Serializable value) throws PropertyException { 
     74        if (value == null) { // IGNORE null values - properties will be considered PHANTOMS 
     75            return; 
     76        } 
    7477        if (value instanceof Map) { 
    7578            internalSetValue((Serializable)adapter.create((Map<String, Object>)value)); 
     
    111114 
    112115    @Override 
     116    protected Serializable getDefaultValue() { 
     117        try { 
     118            return adapter.getDefaultValue(); 
     119        } catch (PropertyNotFoundException e) { 
     120            return null; 
     121        } 
     122    } 
     123 
     124    @Override 
    113125    public boolean isSameAs(Property property) throws PropertyException { 
    114126        if (property == null) { 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/DynamicObjectAdapter.java

    r28190 r29650  
    2121 
    2222 
     23import java.io.Serializable; 
    2324import java.util.HashMap; 
    2425import java.util.Map; 
     
    146147    } 
    147148 
     149    public Serializable getDefaultValue() throws PropertyNotFoundException { 
     150        return null; 
     151    } 
     152 
    148153} 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/ObjectAdapter.java

    r27794 r29650  
    2020package org.nuxeo.ecm.core.api.model.impl.osm; 
    2121 
     22import java.io.Serializable; 
    2223import java.util.Map; 
    2324 
     
    4344    ObjectAdapter getAdapter(String name) throws PropertyNotFoundException; 
    4445 
     46    Serializable getDefaultValue() throws PropertyNotFoundException; 
     47 
    4548} 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/primitives/DateProperty.java

    r26502 r29650  
    2626import org.nuxeo.ecm.core.api.model.Property; 
    2727import org.nuxeo.ecm.core.api.model.PropertyConversionException; 
    28 import org.nuxeo.ecm.core.api.model.PropertyException; 
    2928import org.nuxeo.ecm.core.api.model.impl.ScalarProperty; 
    3029import org.nuxeo.ecm.core.schema.types.Field; 
     
    4342    } 
    4443 
    45     @Override 
    46     public void init(Serializable value) throws PropertyException { 
    47         // TODO Auto-generated method stub 
    48         super.init(value); 
    49     } 
    5044 
    5145    @Override 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/test/java/org/nuxeo/ecm/core/api/TestPropertyModel.java

    r29598 r29650  
    142142            map.put("book:price", price); 
    143143            map.put("book:keywords", keywords); 
    144             map.put("book:references", references); 
    145             map.put("book:file", file != null ? file.getMap() : null); 
     144            if (references == null) { 
     145                map.put("book:references", new ArrayList<Serializable>()); 
     146            } else { 
     147                map.put("book:references", references); 
     148            } 
     149            map.put("book:file", file != null ? file.getMap() : new HashMap<String,Serializable>()); 
    146150            if (authors == null) { 
    147                 map.put("book:authors", null); 
     151                map.put("book:authors", new ArrayList<HashMap<String,Serializable>>()); 
    148152            } else { 
    149153                ArrayList<HashMap<String,Serializable>> list = new ArrayList<HashMap<String,Serializable>>(); 
     
    155159            return map; 
    156160        } 
     161    } 
     162 
     163    protected void clearMap(Map<String, Serializable> map) { 
     164        Iterator<Map.Entry<String, Serializable>> it = map.entrySet().iterator(); 
     165        while (it.hasNext()) { 
     166            Map.Entry<String, Serializable> entry = it.next(); 
     167            Serializable v = entry.getValue(); 
     168            if (v == null) { 
     169                it.remove(); 
     170            } else if (v instanceof Map) { 
     171                clearMap((Map<String, Serializable>)v); 
     172            } else if (v instanceof List) { 
     173                for (Serializable el : (List<Serializable>)v) { 
     174                    if (el instanceof Map) { 
     175                        clearMap((Map<String, Serializable>)el); 
     176                    } 
     177                } 
     178            } 
     179        } 
     180    } 
     181 
     182    protected boolean valueEquals(Object o1, Object o2) { 
     183        if (o1 == null && o2 == null) { 
     184            return true; 
     185        } 
     186        if (o1 == null) { 
     187            return o2 == null; 
     188        } 
     189        if (o2 == null) { 
     190            return o1 == null; 
     191        } 
     192        if (o1 instanceof Map) { 
     193            if (!(o2 instanceof Map)) { 
     194                return false; 
     195            } 
     196            Map<String,Serializable> map1 = (Map<String,Serializable>)o1; 
     197            Map<String,Serializable> map2 = (Map<String,Serializable>)o2; 
     198            if (map1.size() != map2.size()) { 
     199                return false; 
     200            } 
     201            for (String key : map1.keySet()) { 
     202                if (!valueEquals(map1.get(key), map2.get(key))) { 
     203                    return false; 
     204                } 
     205            } 
     206        } else if (o1 instanceof List) { 
     207            if (!(o2 instanceof List)) { 
     208                return false; 
     209            } 
     210            List<Serializable> list1 = (List<Serializable>)o1; 
     211            List<Serializable> list2 = (List<Serializable>)o2; 
     212            if (list1.size() != list2.size()) { 
     213                return false; 
     214            } 
     215            for (int i=0; i<list1.size(); i++) { 
     216                if (!valueEquals(list1.get(i), list2.get(i))) { 
     217                    return false; 
     218                } 
     219            } 
     220        } else if (!o1.equals(o2)) { 
     221            return false; 
     222        } 
     223        return true; 
    157224    } 
    158225 
     
    255322        // test raw values 
    256323        Map<String, Serializable> expected = new Book().getMap(); 
    257         assertEquals(expected,  dp.getValue()); 
     324//        assertEquals(expected,  dp.getValue()); 
     325//        System.out.println(expected); 
     326//        System.out.println(dp.getValue()); 
     327        assertTrue(valueEquals(expected,  dp.getValue())); 
     328 
    258329 
    259330        // test resolve path 
     
    531602        Object[] keywords1 = (Object[])dp.get("keywords").remove(); 
    532603        Object[] keywords2 = (Object[])dp2.get("keywords").remove(); 
    533         Object[] references1 = (Object[])dp.get("references").remove(); 
    534         Object[] references2 = (Object[])dp2.get("references").remove(); 
     604        ArrayList<?> references1 = (ArrayList<?>)dp.get("references").remove(); 
     605        ArrayList<?> references2 = (ArrayList<?>)dp2.get("references").remove(); 
    535606 
    536607        assertEquals(dp2.getValue(), dp.getValue()); 
     
    544615        // now check arrays 
    545616        assertTrue(Arrays.equals(keywords1, keywords2)); 
    546         assertTrue(Arrays.equals(references1, references2)); 
     617        assertEquals(references1, references2); 
    547618    } 
    548619 
     
    669740        HashMap<String, Serializable> map = book.getMap(); 
    670741        ((Map)((Map)map.get("book:file")).get("fileName")).remove("name"); // remove name so that it will be a phantom 
     742 
     743        // remove null values - since they are related to phantom props 
     744        clearMap(map); 
    671745 
    672746        dp.init(map); 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestLocalAPI.java

    r29428 r29650  
    2727import org.nuxeo.ecm.core.api.impl.DocumentModelImpl; 
    2828import org.nuxeo.ecm.core.api.impl.VersionModelImpl; 
     29import org.nuxeo.ecm.core.api.model.DocumentPart; 
     30import org.nuxeo.ecm.core.api.model.Property; 
    2931import org.nuxeo.runtime.RuntimeService; 
    3032import org.nuxeo.runtime.api.Framework; 
     
    105107    } 
    106108 
     109    public void testPropertyModel() throws Exception { 
     110        DocumentModel root = getRootDocument(); 
     111        DocumentModel doc = new DocumentModelImpl(root.getPathAsString(), 
     112                "theDoc", "MyDocType"); 
     113 
     114        doc = remote.createDocument(doc); 
     115 
     116        DocumentPart dp = doc.getPart("MySchema"); 
     117        Property p = dp.get("long"); 
     118 
     119        assertTrue(p.isPhantom()); 
     120        assertEquals(null, p.getValue()); 
     121        p.setValue(12); 
     122        assertEquals(new Long(12), p.getValue()); 
     123        remote.saveDocument(doc); 
     124 
     125        dp = doc.getPart("MySchema"); 
     126        p = dp.get("long"); 
     127        assertFalse(p.isPhantom()); 
     128        assertEquals(new Long(12), p.getValue()); 
     129        p.setValue(null); 
     130        assertFalse(p.isPhantom()); 
     131        assertEquals(null, p.getValue()); 
     132 
     133        remote.saveDocument(doc); 
     134 
     135        dp = doc.getPart("MySchema"); 
     136        p = dp.get("long"); 
     137//        assertTrue(p.isPhantom()); 
     138        assertEquals(null, p.getValue()); 
     139        p.setValue(new Long(13)); 
     140        p.remove(); 
     141        assertTrue(p.isRemoved()); 
     142        assertEquals(null, p.getValue()); 
     143 
     144        remote.saveDocument(doc); 
     145 
     146        dp = doc.getPart("MySchema"); 
     147        p = dp.get("long"); 
     148        assertTrue(p.isPhantom()); 
     149        assertEquals(null, p.getValue()); 
     150    } 
     151 
    107152    public void testOrdering() throws Exception { 
    108153        DocumentModel root = getRootDocument(); 
  • org.nuxeo.ecm.platform/trunk/nuxeo-platform-directory-ldap/src/test/java/org/nuxeo/ecm/directory/ldap/TestLDAPSession.java

    r29584 r29650  
    6565            assertNull(entry.getProperty(USER_SCHEMANAME, "password")); 
    6666            assertNull(entry.getProperty(USER_SCHEMANAME, "userPassword")); 
    67             assertNull(entry.getProperty(USER_SCHEMANAME, "employeeType")); 
     67            List val = (List)entry.getProperty(USER_SCHEMANAME, "employeeType"); 
     68            assertTrue(val.isEmpty()); 
    6869 
    6970            if (USE_EXTERNAL_TEST_LDAP_SERVER) { 
  • org.nuxeo.ecm.platform/trunk/nuxeo-platform-directory-sql/src/test/java/org/nuxeo/ecm/directory/sql/TestSQLDirectory.java

    r28612 r29650  
    336336            List<String> members = (List<String>) group1.getProperty("group", 
    337337                    "members"); 
    338             assertNull(members); 
     338            assertTrue(members.isEmpty()); 
    339339        } finally { 
    340340            session.close(); 
  • org.nuxeo.ecm.platform/trunk/nuxeo-platform-io-core/src/test/java/org/nuxeo/ecm/core/LocalRepositoryLocator.java

    r28612 r29650  
    2828public class LocalRepositoryLocator implements ServiceLocator { 
    2929 
     30    private static final long serialVersionUID = 6771513926490100253L; 
     31 
    3032    public void dispose() { 
    3133        // TODO Auto-generated method stub