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