svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / DefaultEditableFeature.java @ 46434
History | View | Annotate | Download (22.1 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | 41805 | jjdelcerro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 40559 | jjdelcerro | * GNU General Public License for more details.
|
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | 41805 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature.impl; |
25 | |||
26 | 44669 | jjdelcerro | import java.math.BigDecimal; |
27 | 45425 | jjdelcerro | import java.time.LocalDate; |
28 | 44655 | jjdelcerro | import java.time.LocalDateTime; |
29 | 45425 | jjdelcerro | import java.time.LocalTime; |
30 | 44655 | jjdelcerro | import java.time.format.DateTimeFormatter; |
31 | import java.time.temporal.TemporalAccessor; |
||
32 | 40435 | jjdelcerro | import java.util.Date; |
33 | 45039 | fdiaz | import java.util.Set; |
34 | 45102 | omartinez | import java.util.function.Predicate; |
35 | 44655 | jjdelcerro | import javax.json.JsonNumber; |
36 | import javax.json.JsonObject; |
||
37 | 45425 | jjdelcerro | import javax.json.JsonString; |
38 | import javax.json.JsonValue; |
||
39 | 46246 | jjdelcerro | import org.gvsig.fmap.dal.DataTypeUtils; |
40 | 44655 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
41 | 45739 | jjdelcerro | import org.gvsig.fmap.dal.exception.DataException; |
42 | 40435 | jjdelcerro | |
43 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
44 | 44779 | omartinez | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
45 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.Feature; |
46 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
47 | 44815 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
48 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
49 | import org.gvsig.fmap.geom.Geometry; |
||
50 | 44655 | jjdelcerro | import org.gvsig.fmap.geom.GeometryUtils; |
51 | 40435 | jjdelcerro | import org.gvsig.timesupport.Instant; |
52 | import org.gvsig.timesupport.Interval; |
||
53 | 44829 | omartinez | import org.gvsig.fmap.dal.feature.FeatureExtraColumns; |
54 | 45039 | fdiaz | import org.gvsig.fmap.geom.type.GeometryType; |
55 | import org.slf4j.Logger; |
||
56 | import org.slf4j.LoggerFactory; |
||
57 | 40435 | jjdelcerro | |
58 | public class DefaultEditableFeature extends DefaultFeature implements |
||
59 | 41805 | jjdelcerro | EditableFeature { |
60 | 40435 | jjdelcerro | |
61 | 45039 | fdiaz | private static final Logger LOG = LoggerFactory.getLogger(DefaultEditableFeature.class); |
62 | |||
63 | 41805 | jjdelcerro | private DefaultFeature source;
|
64 | 45599 | fdiaz | // private boolean inserted;
|
65 | 45807 | omartinez | private boolean modified; |
66 | 40435 | jjdelcerro | |
67 | 41805 | jjdelcerro | protected DefaultEditableFeature(DefaultFeature feature) {
|
68 | super(feature);
|
||
69 | this.source = feature;
|
||
70 | 45599 | fdiaz | // this.inserted = this.source!=null;
|
71 | 45807 | omartinez | this.modified = false; |
72 | 41805 | jjdelcerro | } |
73 | 40435 | jjdelcerro | |
74 | 41805 | jjdelcerro | protected DefaultEditableFeature(DefaultEditableFeature feature) {
|
75 | super(feature);
|
||
76 | this.source = (DefaultFeature) feature.getSource();
|
||
77 | 45599 | fdiaz | // this.inserted = this.source!=null;
|
78 | 45807 | omartinez | this.modified = feature.modified;
|
79 | 41805 | jjdelcerro | } |
80 | 40435 | jjdelcerro | |
81 | 41805 | jjdelcerro | public DefaultEditableFeature(DefaultFeatureStore store, FeatureProvider data) {
|
82 | // Se trata de un editable feature sobre una ya existente
|
||
83 | super(store, data);
|
||
84 | this.source = null; |
||
85 | 45599 | fdiaz | // this.inserted = this.source!=null;
|
86 | 45807 | omartinez | this.modified = false; |
87 | 41805 | jjdelcerro | } |
88 | 40435 | jjdelcerro | |
89 | 44829 | omartinez | @Override
|
90 | 41805 | jjdelcerro | public Feature getSource() {
|
91 | return this.source; |
||
92 | } |
||
93 | 40435 | jjdelcerro | |
94 | 44829 | omartinez | @Override
|
95 | 45425 | jjdelcerro | public boolean isUpdatable() { |
96 | 45599 | fdiaz | return super.isInserted(); |
97 | 45425 | jjdelcerro | } |
98 | |||
99 | @Override
|
||
100 | public void setUpdatable(boolean updatable) { |
||
101 | 45599 | fdiaz | super.setInserted(updatable);
|
102 | 45425 | jjdelcerro | } |
103 | |||
104 | @Override
|
||
105 | 41805 | jjdelcerro | public EditableFeature getEditable() {
|
106 | return this; |
||
107 | } |
||
108 | 40435 | jjdelcerro | |
109 | 44829 | omartinez | @Override
|
110 | 41805 | jjdelcerro | public Feature getCopy() {
|
111 | return new DefaultEditableFeature(this); |
||
112 | } |
||
113 | 40435 | jjdelcerro | |
114 | 44829 | omartinez | @Override
|
115 | 41805 | jjdelcerro | public Feature getNotEditableCopy() {
|
116 | return new DefaultFeature(this); |
||
117 | } |
||
118 | 40435 | jjdelcerro | |
119 | 44829 | omartinez | @Override
|
120 | 41805 | jjdelcerro | public void setDefaultGeometry(Geometry geometry) { |
121 | FeatureAttributeDescriptor attribute = this.getType()
|
||
122 | .getAttributeDescriptor( |
||
123 | this.getType().getDefaultGeometryAttributeIndex());
|
||
124 | 45807 | omartinez | modified = true;
|
125 | 41805 | jjdelcerro | this.set(attribute, geometry);
|
126 | } |
||
127 | 40435 | jjdelcerro | |
128 | 44390 | jjdelcerro | public void __setitem__(String name, Object value) { |
129 | this.set(name, value);
|
||
130 | } |
||
131 | |||
132 | @Override
|
||
133 | 41805 | jjdelcerro | public void set(String name, Object value) { |
134 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
135 | if ( attribute == null ) { |
||
136 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
137 | } |
||
138 | 45807 | omartinez | modified = true;
|
139 | 41805 | jjdelcerro | this.set(attribute, value);
|
140 | } |
||
141 | 40435 | jjdelcerro | |
142 | 44829 | omartinez | @Override
|
143 | 41805 | jjdelcerro | public void set(int index, Object value) { |
144 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
145 | 45807 | omartinez | modified = true;
|
146 | 41805 | jjdelcerro | this.set(attribute, value);
|
147 | } |
||
148 | 40435 | jjdelcerro | |
149 | 44829 | omartinez | @Override
|
150 | 41805 | jjdelcerro | public void setArray(String name, Object[] value) { |
151 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
152 | if ( attribute == null ) { |
||
153 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
154 | } |
||
155 | 45807 | omartinez | modified = true;
|
156 | 41805 | jjdelcerro | this.set(attribute, value);
|
157 | } |
||
158 | 40435 | jjdelcerro | |
159 | 44829 | omartinez | @Override
|
160 | 41805 | jjdelcerro | public void setArray(int index, Object[] value) { |
161 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
162 | 45807 | omartinez | modified = true;
|
163 | 41805 | jjdelcerro | this.set(attribute, value);
|
164 | } |
||
165 | 45807 | omartinez | |
166 | 44829 | omartinez | @Override
|
167 | 41805 | jjdelcerro | public void setBoolean(String name, boolean value) { |
168 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
169 | if ( attribute == null ) { |
||
170 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
171 | } |
||
172 | 45807 | omartinez | modified = true;
|
173 | 41805 | jjdelcerro | this.set(attribute, Boolean.valueOf(value)); |
174 | } |
||
175 | 40435 | jjdelcerro | |
176 | 44829 | omartinez | @Override
|
177 | 41805 | jjdelcerro | public void setBoolean(int index, boolean value) { |
178 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
179 | 45807 | omartinez | modified = true;
|
180 | 45039 | fdiaz | this.set(attribute, value);
|
181 | 41805 | jjdelcerro | } |
182 | 40435 | jjdelcerro | |
183 | 44829 | omartinez | @Override
|
184 | 41805 | jjdelcerro | public void setByte(String name, byte value) { |
185 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
186 | if ( attribute == null ) { |
||
187 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
188 | } |
||
189 | 45807 | omartinez | modified = true;
|
190 | 45039 | fdiaz | this.set(attribute, value);
|
191 | 41805 | jjdelcerro | } |
192 | 40435 | jjdelcerro | |
193 | 44829 | omartinez | @Override
|
194 | 41805 | jjdelcerro | public void setByte(int index, byte value) { |
195 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
196 | 45807 | omartinez | modified = true;
|
197 | 45039 | fdiaz | this.set(attribute, value);
|
198 | 41805 | jjdelcerro | } |
199 | 40435 | jjdelcerro | |
200 | 44829 | omartinez | @Override
|
201 | 41805 | jjdelcerro | public void setDate(String name, Date value) { |
202 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
203 | if ( attribute == null ) { |
||
204 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
205 | } |
||
206 | 45807 | omartinez | modified = true;
|
207 | 41805 | jjdelcerro | this.set(attribute, value);
|
208 | } |
||
209 | 40435 | jjdelcerro | |
210 | 44829 | omartinez | @Override
|
211 | 41805 | jjdelcerro | public void setDate(int index, Date value) { |
212 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
213 | 45807 | omartinez | modified = true;
|
214 | 41805 | jjdelcerro | this.set(attribute, value);
|
215 | } |
||
216 | 40435 | jjdelcerro | |
217 | 44829 | omartinez | @Override
|
218 | 41805 | jjdelcerro | public void setDouble(String name, double value) { |
219 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
220 | if ( attribute == null ) { |
||
221 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
222 | } |
||
223 | 45807 | omartinez | modified = true;
|
224 | 45039 | fdiaz | this.set(attribute, value);
|
225 | 41805 | jjdelcerro | } |
226 | 40435 | jjdelcerro | |
227 | 44829 | omartinez | @Override
|
228 | 41805 | jjdelcerro | public void setDouble(int index, double value) { |
229 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
230 | 45807 | omartinez | modified = true;
|
231 | 45039 | fdiaz | this.set(attribute, value);
|
232 | 41805 | jjdelcerro | } |
233 | 40435 | jjdelcerro | |
234 | 44669 | jjdelcerro | @Override
|
235 | public void setDecimal(String name, BigDecimal value) { |
||
236 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
237 | if ( attribute == null ) { |
||
238 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
239 | } |
||
240 | 45807 | omartinez | modified = true;
|
241 | 44669 | jjdelcerro | this.set(attribute, value);
|
242 | } |
||
243 | |||
244 | 44829 | omartinez | @Override
|
245 | 44669 | jjdelcerro | public void setDecimal(int index, BigDecimal value) { |
246 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
247 | 45807 | omartinez | modified = true;
|
248 | 44669 | jjdelcerro | this.set(attribute, value);
|
249 | } |
||
250 | |||
251 | 44829 | omartinez | @Override
|
252 | 41805 | jjdelcerro | public void setFeature(String name, Feature value) { |
253 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
254 | if ( attribute == null ) { |
||
255 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
256 | } |
||
257 | 45807 | omartinez | modified = true;
|
258 | 41805 | jjdelcerro | this.set(attribute, value);
|
259 | } |
||
260 | 40435 | jjdelcerro | |
261 | 44829 | omartinez | @Override
|
262 | 41805 | jjdelcerro | public void setFeature(int index, Feature value) { |
263 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
264 | 45807 | omartinez | modified = true;
|
265 | 41805 | jjdelcerro | this.set(attribute, value);
|
266 | } |
||
267 | 40435 | jjdelcerro | |
268 | 44829 | omartinez | @Override
|
269 | 41805 | jjdelcerro | public void setFloat(String name, float value) { |
270 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
271 | if ( attribute == null ) { |
||
272 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
273 | } |
||
274 | 45807 | omartinez | modified = true;
|
275 | 45039 | fdiaz | this.set(attribute, value);
|
276 | 41805 | jjdelcerro | } |
277 | 40435 | jjdelcerro | |
278 | 44829 | omartinez | @Override
|
279 | 41805 | jjdelcerro | public void setFloat(int index, float value) { |
280 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
281 | 45807 | omartinez | modified = true;
|
282 | 45039 | fdiaz | this.set(attribute, value);
|
283 | 41805 | jjdelcerro | } |
284 | 40435 | jjdelcerro | |
285 | 44829 | omartinez | @Override
|
286 | 41805 | jjdelcerro | public void setGeometry(String name, Geometry value) { |
287 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
288 | if ( attribute == null ) { |
||
289 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
290 | } |
||
291 | 45807 | omartinez | modified = true;
|
292 | 41805 | jjdelcerro | this.set(attribute, value);
|
293 | } |
||
294 | 40435 | jjdelcerro | |
295 | 44829 | omartinez | @Override
|
296 | 41805 | jjdelcerro | public void setGeometry(int index, Geometry value) { |
297 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
298 | 45807 | omartinez | modified = true;
|
299 | 41805 | jjdelcerro | this.set(attribute, value);
|
300 | } |
||
301 | 40435 | jjdelcerro | |
302 | 44829 | omartinez | @Override
|
303 | 41805 | jjdelcerro | public void setInt(String name, int value) { |
304 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
305 | if ( attribute == null ) { |
||
306 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
307 | } |
||
308 | 45807 | omartinez | modified = true;
|
309 | 45039 | fdiaz | this.set(attribute, value);
|
310 | 41805 | jjdelcerro | } |
311 | 40435 | jjdelcerro | |
312 | 44829 | omartinez | @Override
|
313 | 41805 | jjdelcerro | public void setInt(int index, int value) { |
314 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
315 | 45807 | omartinez | modified = true;
|
316 | 45039 | fdiaz | this.set(attribute, value);
|
317 | 41805 | jjdelcerro | } |
318 | 40435 | jjdelcerro | |
319 | 44829 | omartinez | @Override
|
320 | 41805 | jjdelcerro | public void setLong(String name, long value) { |
321 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
322 | if ( attribute == null ) { |
||
323 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
324 | } |
||
325 | 45807 | omartinez | modified = true;
|
326 | 45039 | fdiaz | this.set(attribute, value);
|
327 | 41805 | jjdelcerro | } |
328 | 40435 | jjdelcerro | |
329 | 44829 | omartinez | @Override
|
330 | 41805 | jjdelcerro | public void setLong(int index, long value) { |
331 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
332 | 45807 | omartinez | modified = true;
|
333 | 45039 | fdiaz | this.set(attribute, value);
|
334 | 41805 | jjdelcerro | } |
335 | 40435 | jjdelcerro | |
336 | 44829 | omartinez | @Override
|
337 | 41805 | jjdelcerro | public void setString(String name, String value) { |
338 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
339 | if ( attribute == null ) { |
||
340 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
341 | } |
||
342 | 45807 | omartinez | modified = true;
|
343 | 41805 | jjdelcerro | this.set(attribute, value);
|
344 | } |
||
345 | 40435 | jjdelcerro | |
346 | 44829 | omartinez | @Override
|
347 | 41805 | jjdelcerro | public void setString(int index, String value) { |
348 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
349 | 45807 | omartinez | modified = true;
|
350 | 41805 | jjdelcerro | this.set(attribute, value);
|
351 | } |
||
352 | 40435 | jjdelcerro | |
353 | 44829 | omartinez | @Override
|
354 | 44655 | jjdelcerro | public void copyFrom(JsonObject values) { |
355 | 45102 | omartinez | this.copyFrom(values, null); |
356 | } |
||
357 | |||
358 | 46024 | jjdelcerro | // private boolean notCopyAttribute(FeatureAttributeDescriptor attr,Predicate<FeatureAttributeDescriptor> filter) {
|
359 | // // helper function to use in copyFrom
|
||
360 | // if (attr==null ) {
|
||
361 | // return true;
|
||
362 | // }
|
||
363 | // if (attr.isAutomatic() || attr.isComputed() ) {
|
||
364 | // return true;
|
||
365 | // }
|
||
366 | // if( this.isInserted() && attr.isReadOnly()) {
|
||
367 | // return true;
|
||
368 | // }
|
||
369 | // if( filter!=null && !filter.test(attr) ) {
|
||
370 | // return true;
|
||
371 | // }
|
||
372 | // return false;
|
||
373 | // }
|
||
374 | 45916 | jjdelcerro | |
375 | 45102 | omartinez | @Override
|
376 | public void copyFrom(JsonObject values, Predicate<FeatureAttributeDescriptor> filter) { |
||
377 | // iterate over the attributes and copy one by one
|
||
378 | 45916 | jjdelcerro | if( values == null ) { |
379 | throw new IllegalArgumentException("'values' argument can't be null"); |
||
380 | } |
||
381 | 45778 | fdiaz | boolean geometryCopied = false; |
382 | 44655 | jjdelcerro | for (FeatureAttributeDescriptor attr : this.getType()) { |
383 | 46024 | jjdelcerro | if( !canSetValue(attr, filter) ) {
|
384 | 45769 | jjdelcerro | continue;
|
385 | } |
||
386 | 44655 | jjdelcerro | String attrname = attr.getName();
|
387 | if( !values.containsKey(attrname) ) {
|
||
388 | continue;
|
||
389 | } |
||
390 | Object value;
|
||
391 | 45425 | jjdelcerro | JsonValue jsonValue = values.get(attrname); |
392 | 46434 | fdiaz | if(jsonValue == null){ |
393 | value = null;
|
||
394 | } else {
|
||
395 | try {
|
||
396 | switch( jsonValue.getValueType() ) {
|
||
397 | case STRING:
|
||
398 | String s = ((JsonString)jsonValue).getString();
|
||
399 | switch(attr.getType()) {
|
||
400 | case DataTypes.GEOMETRY:
|
||
401 | value = GeometryUtils.createFrom(s); |
||
402 | geometryCopied = true;
|
||
403 | break;
|
||
404 | case DataTypes.TIMESTAMP:
|
||
405 | try {
|
||
406 | TemporalAccessor x = DateTimeFormatter.ISO_DATE_TIME.parse(s); |
||
407 | LocalDateTime date = LocalDateTime.from(x); |
||
408 | value = java.sql.Timestamp.valueOf(date); |
||
409 | } catch(Exception ex) { |
||
410 | value = s; |
||
411 | } |
||
412 | break;
|
||
413 | case DataTypes.DATE:
|
||
414 | try {
|
||
415 | TemporalAccessor x = DateTimeFormatter.ISO_DATE.parse(s); |
||
416 | LocalDate date = LocalDate.from(x); |
||
417 | value = java.sql.Date.valueOf(date); |
||
418 | } catch(Exception ex) { |
||
419 | value = s; |
||
420 | } |
||
421 | break;
|
||
422 | case DataTypes.TIME:
|
||
423 | try {
|
||
424 | TemporalAccessor x = DateTimeFormatter.ISO_TIME.parse(s); |
||
425 | LocalTime date = LocalTime.from(x); |
||
426 | value = java.sql.Time.valueOf(date); |
||
427 | } catch(Exception ex) { |
||
428 | value = s; |
||
429 | } |
||
430 | break;
|
||
431 | case DataTypes.BYTEARRAY:
|
||
432 | value = DataTypeUtils.coerce(DataTypes.BYTEARRAY, s, null);
|
||
433 | break;
|
||
434 | case DataTypes.STRING:
|
||
435 | default:
|
||
436 | 45425 | jjdelcerro | value = s; |
437 | 46434 | fdiaz | break;
|
438 | } |
||
439 | break;
|
||
440 | case NUMBER:
|
||
441 | JsonNumber n = (JsonNumber) jsonValue; |
||
442 | switch(attr.getType()) {
|
||
443 | case DataTypes.DECIMAL:
|
||
444 | value = n.bigDecimalValue(); |
||
445 | break;
|
||
446 | case DataTypes.BYTE:
|
||
447 | value = n.bigDecimalValue(); |
||
448 | break;
|
||
449 | case DataTypes.FLOAT:
|
||
450 | case DataTypes.DOUBLE:
|
||
451 | value = n.doubleValue(); |
||
452 | break;
|
||
453 | case DataTypes.INT:
|
||
454 | value = n.intValue(); |
||
455 | break;
|
||
456 | case DataTypes.LONG:
|
||
457 | value = n.longValue(); |
||
458 | break;
|
||
459 | default:
|
||
460 | value = n.toString(); |
||
461 | break;
|
||
462 | } |
||
463 | break;
|
||
464 | case TRUE:
|
||
465 | value = true;
|
||
466 | break;
|
||
467 | case FALSE:
|
||
468 | value = false;
|
||
469 | break;
|
||
470 | case NULL:
|
||
471 | value = null;
|
||
472 | break;
|
||
473 | default:
|
||
474 | value = values.getString(attrname); |
||
475 | break;
|
||
476 | } |
||
477 | } catch(Exception ex) { |
||
478 | continue;
|
||
479 | 44655 | jjdelcerro | } |
480 | } |
||
481 | if (value == null && !attr.allowNull()) { |
||
482 | continue;
|
||
483 | } |
||
484 | try {
|
||
485 | set(attr.getIndex(), value); |
||
486 | } catch(Throwable th) { |
||
487 | // Ignore
|
||
488 | } |
||
489 | } |
||
490 | 45778 | fdiaz | FeatureAttributeDescriptor attr = this.getType().getDefaultGeometryAttribute();
|
491 | if (attr!=null && !geometryCopied) { |
||
492 | if( filter==null || filter.test(attr) ) { |
||
493 | GeometryType geomType = this.getType().getDefaultGeometryAttribute().getGeomType();
|
||
494 | Set<String> keys = values.keySet(); |
||
495 | for (String key : keys) { |
||
496 | try {
|
||
497 | String wkt = values.getString(key);
|
||
498 | Geometry geometry = GeometryUtils.createFrom(wkt); |
||
499 | if (GeometryUtils.isSubtype(geomType.getType(), geometry.getType()) || GeometryUtils.canAggregate(geomType.getType(), geometry.getType())) {
|
||
500 | this.setDefaultGeometry(geometry);
|
||
501 | break;
|
||
502 | } |
||
503 | } catch (Throwable tr) { |
||
504 | LOG.trace("Can't get geometry from field {}.", new Object[]{key}); |
||
505 | }; |
||
506 | } |
||
507 | 45039 | fdiaz | } |
508 | } |
||
509 | 44655 | jjdelcerro | } |
510 | |||
511 | 44829 | omartinez | @Override
|
512 | 41805 | jjdelcerro | public void copyFrom(Feature source) { |
513 | 45102 | omartinez | this.copyFrom(source, null); |
514 | } |
||
515 | |||
516 | @Override
|
||
517 | public void copyFrom(Feature source, Predicate<FeatureAttributeDescriptor> filter) { |
||
518 | 44815 | jjdelcerro | // iterate over the attributes and copy one by one
|
519 | 45916 | jjdelcerro | if( source == null ) { |
520 | throw new IllegalArgumentException("'source' argument can't be null"); |
||
521 | } |
||
522 | 44815 | jjdelcerro | FeatureType sourceType = source.getType(); |
523 | 46415 | jjdelcerro | for (FeatureAttributeDescriptor attrTarget : this.getType()) { |
524 | if( !canSetValue(attrTarget, filter) ) {
|
||
525 | 45769 | jjdelcerro | continue;
|
526 | } |
||
527 | 46415 | jjdelcerro | String attrname = attrTarget.getName();
|
528 | 46089 | omartinez | if( sourceType.getAttributeDescriptorFromAll(attrname)==null ) { |
529 | 44815 | jjdelcerro | continue;
|
530 | } |
||
531 | 46415 | jjdelcerro | FeatureAttributeDescriptor attrSource = sourceType.getAttributeDescriptor(attrname); |
532 | 46410 | jjdelcerro | Object value;
|
533 | 46415 | jjdelcerro | if( attrSource.hasDataProfile() ) {
|
534 | 46410 | jjdelcerro | value = source.getFromProfile(attrname); |
535 | if( value == null ) { |
||
536 | value = source.get(attrname); |
||
537 | } |
||
538 | } else {
|
||
539 | value = source.get(attrname); |
||
540 | } |
||
541 | 46415 | jjdelcerro | if (value == null && !attrTarget.allowNull()) { |
542 | 44610 | jjdelcerro | continue;
|
543 | } |
||
544 | try {
|
||
545 | 46415 | jjdelcerro | set(attrTarget.getIndex(), value); |
546 | 44610 | jjdelcerro | } catch(Throwable th) { |
547 | 45039 | fdiaz | LOG.trace("The exception thrown is: ", th);
|
548 | 44610 | jjdelcerro | } |
549 | 41805 | jjdelcerro | } |
550 | 45102 | omartinez | |
551 | 41805 | jjdelcerro | } |
552 | 45102 | omartinez | |
553 | 40435 | jjdelcerro | |
554 | 45102 | omartinez | |
555 | 44829 | omartinez | @Override
|
556 | 41805 | jjdelcerro | public void setInstant(String name, Instant value) { |
557 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
558 | if ( attribute == null ) { |
||
559 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
560 | } |
||
561 | 45807 | omartinez | modified = true;
|
562 | 41805 | jjdelcerro | this.set(attribute, value);
|
563 | } |
||
564 | 40435 | jjdelcerro | |
565 | 44829 | omartinez | @Override
|
566 | 41805 | jjdelcerro | public void setInstant(int index, Instant value) { |
567 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
568 | 45807 | omartinez | modified = true;
|
569 | 41805 | jjdelcerro | this.set(attribute, value);
|
570 | } |
||
571 | 40435 | jjdelcerro | |
572 | 44829 | omartinez | @Override
|
573 | 41805 | jjdelcerro | public void setInterval(String name, Interval value) { |
574 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
575 | if ( attribute == null ) { |
||
576 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
577 | } |
||
578 | 45807 | omartinez | modified = true;
|
579 | 41805 | jjdelcerro | this.set(attribute, value);
|
580 | } |
||
581 | 40435 | jjdelcerro | |
582 | 44829 | omartinez | @Override
|
583 | 41805 | jjdelcerro | public void setInterval(int index, Interval value) { |
584 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
585 | 45807 | omartinez | modified = true;
|
586 | 41805 | jjdelcerro | this.set(attribute, value);
|
587 | } |
||
588 | 44779 | omartinez | |
589 | @Override
|
||
590 | public Object getExtraValue(String name) { |
||
591 | Object value;
|
||
592 | 44829 | omartinez | FeatureExtraColumns columns = this.getType().getExtraColumns();
|
593 | 44779 | omartinez | int index = columns.getIndexOf(name);
|
594 | if (index >= 0) { |
||
595 | EditableFeatureAttributeDescriptor attrdesc = columns.get(index); |
||
596 | value = attrdesc.getFeatureAttributeEmulator().get(this);
|
||
597 | return value;
|
||
598 | } |
||
599 | value = this.data.getExtraValue(name);
|
||
600 | return value;
|
||
601 | } |
||
602 | 45739 | jjdelcerro | |
603 | @Override
|
||
604 | public void validate(int check) throws DataException { |
||
605 | ((DefaultFeatureType) this.data.getType()).validateFeature(this, check); |
||
606 | } |
||
607 | |||
608 | 45807 | omartinez | public boolean isModified() { |
609 | return modified;
|
||
610 | } |
||
611 | |||
612 | 40435 | jjdelcerro | } |