Changeset 30097
- Timestamp:
- 02/12/08 18:55:18 (9 months ago)
- Files:
-
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/AbstractProperty.java (modified) (2 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ComplexProperty.java (modified) (2 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ListProperty.java (modified) (2 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ScalarProperty.java (modified) (1 diff)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/ComplexMemberProperty.java (modified) (2 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/DynamicObjectAdapter.java (modified) (2 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/ObjectAdapter.java (modified) (2 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/primitives/DateProperty.java (modified) (2 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/test/java/org/nuxeo/ecm/core/api/TestPropertyModel.java (modified) (6 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestLocalAPI.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/AbstractProperty.java
r28924 r30097 86 86 87 87 public void init(Serializable value) throws PropertyException { 88 if (value == null) { // IGNORE null values - properties will be considered PHANTOMS 89 return; 90 } 88 91 internalSetValue(value); 89 92 clearFlags(IS_PHANTOM); … … 333 336 334 337 public Serializable getValue() throws PropertyException { 335 if (isPhantom() ) {336 return (Serializable)getField().getDefaultValue();338 if (isPhantom() || isRemoved()) { 339 return getDefaultValue(); 337 340 } 338 341 return internalGetValue(); 342 } 343 344 protected Serializable getDefaultValue() { 345 return (Serializable)getField().getDefaultValue(); 339 346 } 340 347 org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ComplexProperty.java
r28980 r30097 172 172 @SuppressWarnings("unchecked") 173 173 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; 176 176 } 177 177 Map<String, Serializable> map = (Map<String, Serializable>)value; … … 181 181 } 182 182 clearFlags(IS_PHANTOM); 183 } 184 185 @Override 186 protected Serializable getDefaultValue() { 187 return new HashMap<String, Serializable>(); 183 188 } 184 189 org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ListProperty.java
r28478 r30097 135 135 } 136 136 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 137 145 @Override 138 146 public Serializable internalGetValue() throws PropertyException { 139 147 if (children.isEmpty()) { 140 return n ull;148 return new ArrayList<String>(); 141 149 } 142 150 //noinspection CollectionDeclaredAsConcreteClass … … 171 179 @SuppressWarnings("unchecked") 172 180 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); 188 197 } 189 198 clearFlags(IS_PHANTOM); org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/ScalarProperty.java
r27627 r30097 154 154 } 155 155 156 @Override 157 public String toString() { 158 return getPath() + " = " + ((value == null) ? "[null]" : value); 159 } 156 160 } org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/ComplexMemberProperty.java
r28188 r30097 72 72 @Override 73 73 public void init(Serializable value) throws PropertyException { 74 if (value == null) { // IGNORE null values - properties will be considered PHANTOMS 75 return; 76 } 74 77 if (value instanceof Map) { 75 78 internalSetValue((Serializable)adapter.create((Map<String, Object>)value)); … … 111 114 112 115 @Override 116 protected Serializable getDefaultValue() { 117 try { 118 return adapter.getDefaultValue(); 119 } catch (PropertyNotFoundException e) { 120 return null; 121 } 122 } 123 124 @Override 113 125 public boolean isSameAs(Property property) throws PropertyException { 114 126 if (property == null) { org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/DynamicObjectAdapter.java
r28188 r30097 21 21 22 22 23 import java.io.Serializable; 23 24 import java.util.HashMap; 24 25 import java.util.Map; … … 146 147 } 147 148 149 public Serializable getDefaultValue() throws PropertyNotFoundException { 150 return null; 151 } 152 148 153 } org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/osm/ObjectAdapter.java
r27794 r30097 20 20 package org.nuxeo.ecm.core.api.model.impl.osm; 21 21 22 import java.io.Serializable; 22 23 import java.util.Map; 23 24 … … 43 44 ObjectAdapter getAdapter(String name) throws PropertyNotFoundException; 44 45 46 Serializable getDefaultValue() throws PropertyNotFoundException; 47 45 48 } org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/model/impl/primitives/DateProperty.java
r26502 r30097 26 26 import org.nuxeo.ecm.core.api.model.Property; 27 27 import org.nuxeo.ecm.core.api.model.PropertyConversionException; 28 import org.nuxeo.ecm.core.api.model.PropertyException;29 28 import org.nuxeo.ecm.core.api.model.impl.ScalarProperty; 30 29 import org.nuxeo.ecm.core.schema.types.Field; … … 43 42 } 44 43 45 @Override46 public void init(Serializable value) throws PropertyException {47 // TODO Auto-generated method stub48 super.init(value);49 }50 44 51 45 @Override org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/test/java/org/nuxeo/ecm/core/api/TestPropertyModel.java
r29597 r30097 142 142 map.put("book:price", price); 143 143 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>()); 146 150 if (authors == null) { 147 map.put("book:authors", n ull);151 map.put("book:authors", new ArrayList<HashMap<String,Serializable>>()); 148 152 } else { 149 153 ArrayList<HashMap<String,Serializable>> list = new ArrayList<HashMap<String,Serializable>>(); … … 155 159 return map; 156 160 } 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; 157 224 } 158 225 … … 255 322 // test raw values 256 323 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 258 329 259 330 // test resolve path … … 531 602 Object[] keywords1 = (Object[])dp.get("keywords").remove(); 532 603 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(); 535 606 536 607 assertEquals(dp2.getValue(), dp.getValue()); … … 544 615 // now check arrays 545 616 assertTrue(Arrays.equals(keywords1, keywords2)); 546 assert True(Arrays.equals(references1, references2));617 assertEquals(references1, references2); 547 618 } 548 619 … … 669 740 HashMap<String, Serializable> map = book.getMap(); 670 741 ((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); 671 745 672 746 dp.init(map); org.nuxeo.ecm.core/branches/1.4/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestLocalAPI.java
r29429 r30097 27 27 import org.nuxeo.ecm.core.api.impl.DocumentModelImpl; 28 28 import org.nuxeo.ecm.core.api.impl.VersionModelImpl; 29 import org.nuxeo.ecm.core.api.model.DocumentPart; 30 import org.nuxeo.ecm.core.api.model.Property; 29 31 import org.nuxeo.runtime.RuntimeService; 30 32 import org.nuxeo.runtime.api.Framework; … … 105 107 } 106 108 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 107 152 public void testOrdering() throws Exception { 108 153 DocumentModel root = getRootDocument();
