root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / fmap / dal / store / wfs / WFSStoreProvider.java @ 112
History | View | Annotate | Download (24.9 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* 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 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.dal.store.wfs; |
29 |
|
30 |
import java.awt.geom.AffineTransform; |
31 |
import java.io.File; |
32 |
import java.io.IOException; |
33 |
import java.util.ArrayList; |
34 |
import java.util.Iterator; |
35 |
import java.util.List; |
36 |
|
37 |
import org.cresques.cts.ICoordTrans; |
38 |
import org.cresques.cts.IProjection; |
39 |
import org.gvsig.fmap.crs.CRSFactory; |
40 |
import org.gvsig.fmap.dal.DALLocator; |
41 |
import org.gvsig.fmap.dal.DataManager; |
42 |
import org.gvsig.fmap.dal.DataServerExplorer; |
43 |
import org.gvsig.fmap.dal.DataStoreParameters; |
44 |
import org.gvsig.fmap.dal.DataTypes; |
45 |
import org.gvsig.fmap.dal.exception.ConnectionServerException; |
46 |
import org.gvsig.fmap.dal.exception.DataException; |
47 |
import org.gvsig.fmap.dal.exception.InitializeException; |
48 |
import org.gvsig.fmap.dal.exception.OpenException; |
49 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
50 |
import org.gvsig.fmap.dal.exception.ReadException; |
51 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
52 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
53 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
54 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
55 |
import org.gvsig.fmap.dal.feature.FeatureType; |
56 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
57 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
58 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
59 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
60 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
61 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer; |
62 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorerParameters; |
63 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
64 |
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider; |
65 |
import org.gvsig.fmap.geom.Geometry; |
66 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
67 |
import org.gvsig.fmap.geom.GeometryLocator; |
68 |
import org.gvsig.fmap.geom.GeometryManager; |
69 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
70 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
71 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
72 |
import org.gvsig.fmap.geom.primitive.Envelope; |
73 |
import org.gvsig.gpe.lib.api.exceptions.WriterHandlerCreationException; |
74 |
import org.gvsig.metadata.MetadataLocator; |
75 |
import org.gvsig.metadata.MetadataManager; |
76 |
import org.gvsig.metadata.exceptions.MetadataException; |
77 |
import org.gvsig.remoteclient.ogc.OGCClientOperation; |
78 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
79 |
import org.gvsig.remoteclient.wfs.WFSClient; |
80 |
import org.gvsig.remoteclient.wfs.WFSFeature; |
81 |
import org.gvsig.remoteclient.wfs.WFSFeatureField; |
82 |
import org.gvsig.remoteclient.wfs.WFSStatus; |
83 |
import org.gvsig.remoteclient.wfs.exceptions.WFSException; |
84 |
import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding; |
85 |
import org.gvsig.remoteclient.wfs.request.WFSGetFeatureRequestInformation; |
86 |
import org.gvsig.remoteclient.wfs.request.WFSTransactionRequestInformation; |
87 |
import org.gvsig.tools.ToolsLocator; |
88 |
import org.gvsig.tools.dynobject.DynStruct; |
89 |
import org.gvsig.tools.evaluator.EvaluatorFieldValue; |
90 |
import org.gvsig.tools.evaluator.EvaluatorFieldValueMatch; |
91 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
92 |
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator; |
93 |
import org.gvsig.xmlschema.lib.api.XMLSchemaManager; |
94 |
import org.gvsig.xmlschema.lib.api.som.IXSGeometryTypeDefinition; |
95 |
import org.gvsig.xmlschema.lib.api.som.IXSTypeDefinition; |
96 |
import org.slf4j.Logger; |
97 |
import org.slf4j.LoggerFactory; |
98 |
|
99 |
|
100 |
/**
|
101 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
102 |
*/
|
103 |
public class WFSStoreProvider extends AbstractFeatureStoreProvider { |
104 |
private static final Logger logger = LoggerFactory.getLogger(WFSStoreProvider.class); |
105 |
public static String NAME = "WFSStore"; |
106 |
public static String DESCRIPTION = "WFS store to load WFS resources"; |
107 |
|
108 |
private static final MetadataManager metadataManager = MetadataLocator.getMetadataManager(); |
109 |
private static final String METADATA_DEFINITION_NAME = "WFSStore"; |
110 |
private static final String METADATA_DEFINITION_DESCRIPTION = "WFSStore metadata definition"; |
111 |
|
112 |
// private IProjection projection;
|
113 |
private long featureCount = -1; |
114 |
private boolean isKnownEnvelope = false; |
115 |
|
116 |
/**
|
117 |
* If the user has selected the filter by area option
|
118 |
*/
|
119 |
private boolean hasFilterByArea = false; |
120 |
|
121 |
/**
|
122 |
* GML provider used by delegation to read the GML files
|
123 |
*/
|
124 |
private GPEStoreProvider storeProviderDelegate = null; |
125 |
|
126 |
private static final DataManager dataManager = DALLocator.getDataManager(); |
127 |
private static final XMLSchemaManager xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager(); |
128 |
|
129 |
boolean isFilterByAreaSupported = true; |
130 |
|
131 |
//WFS Parameters
|
132 |
private WFSClient wfsClient;
|
133 |
private WFSStatus wfsStatus;
|
134 |
|
135 |
public WFSStoreProvider(DataStoreParameters params,
|
136 |
DataStoreProviderServices storeServices) |
137 |
throws InitializeException {
|
138 |
super(params, storeServices,
|
139 |
ToolsLocator.getDynObjectManager().createDynObject(metadataManager.getDefinition(METADATA_DEFINITION_NAME))); |
140 |
initParams(); |
141 |
try {
|
142 |
initFeatureType(); |
143 |
} catch (WFSException e) {
|
144 |
throw new InitializeException(e); |
145 |
} catch (ReadException e) {
|
146 |
throw new InitializeException(e); |
147 |
} |
148 |
} |
149 |
|
150 |
private void initParams() throws InitializeException{ |
151 |
try {
|
152 |
WFSStoreParameters wfsParameters = getWFSParameters(); |
153 |
try {
|
154 |
if (wfsParameters.getVersion() == null){ |
155 |
wfsClient = new WFSClient(wfsParameters.getUrl(), wfsParameters.getIgnoreCache());
|
156 |
wfsParameters.setVersion(wfsClient.getVersion()); |
157 |
}else{
|
158 |
wfsClient = new WFSClient(wfsParameters.getUrl(), wfsParameters.getVersion(), wfsParameters.getIgnoreCache());
|
159 |
} |
160 |
} catch (IOException e) { |
161 |
throw new InitializeException(e); |
162 |
} |
163 |
wfsStatus = new WFSStatus( wfsParameters.getFeatureType(),
|
164 |
wfsParameters.getFeatureNamespace()); |
165 |
wfsStatus.setNamespacePrefix(wfsParameters.getFeaturePrefix()); |
166 |
wfsStatus.setFields(wfsParameters.getFields()); |
167 |
|
168 |
//Select the filter by area
|
169 |
|
170 |
Geometry filterByAreaGeometry = wfsParameters.getFilterByAreaGeometry(); |
171 |
Envelope filterByAreaEnvelope = wfsParameters.getFilterByAreaEnvelope(); |
172 |
if (filterByAreaGeometry != null){ |
173 |
wfsStatus.setFilterByArea(filterByAreaGeometry, wfsParameters.getFilterByAreaAttribute(), |
174 |
wfsParameters.getFilterByAreaCrs(), wfsParameters.getFilterByAreaOperation()); |
175 |
} else if (filterByAreaEnvelope != null) { |
176 |
wfsStatus.setFilterByArea(filterByAreaEnvelope, wfsParameters.getFilterByAreaAttribute(), |
177 |
wfsParameters.getFilterByAreaCrs(), wfsParameters.getFilterByAreaOperation()); |
178 |
} |
179 |
this.hasFilterByArea = (wfsStatus.getFilterByArea() != null); |
180 |
|
181 |
//Select the filter by attribute
|
182 |
wfsStatus.setFilterByAttribute(wfsParameters.getFilterEncodingByAttribute()); |
183 |
|
184 |
String _srs = wfsParameters.getFilterByAreaCrs();
|
185 |
wfsStatus.setSrs(_srs); |
186 |
|
187 |
wfsStatus.setTimeout(wfsParameters.getTimeOut()); |
188 |
wfsStatus.setMaxFeatures(wfsParameters.getMaxFeatures()); |
189 |
wfsStatus.setUserName(wfsParameters.getUser()); |
190 |
wfsStatus.setPassword(wfsParameters.getPassword()); |
191 |
|
192 |
//Setting the envelope for the layer
|
193 |
wfsClient.getCapabilities(wfsStatus, false, null); |
194 |
|
195 |
Envelope envelope = calculateFullEnvelope(); |
196 |
if (envelope != null){ |
197 |
this.setDynValue("Envelope", envelope); |
198 |
isKnownEnvelope = true;
|
199 |
} |
200 |
} catch (WFSException e) {
|
201 |
throw new InitializeException("Impossible to retrieve the file", e); |
202 |
} |
203 |
} |
204 |
|
205 |
private WFSFeature getSelectedWFSFeature() throws ReadException, WFSException{ |
206 |
WFSStoreParameters wfsParameters = getWFSParameters(); |
207 |
|
208 |
return ((WFSServerExplorer)getExplorer()).getFeatureInfo(wfsParameters.getFeatureNamespace(),
|
209 |
wfsParameters.getFeatureType()); |
210 |
} |
211 |
|
212 |
private void initFeatureType() throws WFSException, ReadException{ |
213 |
WFSFeature feature = getSelectedWFSFeature(); |
214 |
|
215 |
if (feature == null){ |
216 |
//TODO read from GML
|
217 |
throw new WFSException("It is not possible to parse the schema"); |
218 |
} |
219 |
|
220 |
IProjection ipro = null;
|
221 |
try {
|
222 |
ipro = CRSFactory.getCRS(wfsStatus.getSrs()); |
223 |
this.setDynValue("CRS", ipro); |
224 |
} catch (Exception ex) { |
225 |
logger.info("Error: did not set CRS in store provider.", ex);
|
226 |
} |
227 |
|
228 |
EditableFeatureType featureType = getStoreServices().createFeatureType(); |
229 |
|
230 |
for (int i=0 ; i<feature.getFieldSize() ; i++){ |
231 |
WFSFeatureField featureField = feature.getFieldAt(i); |
232 |
int dataType = DataTypes.STRING;
|
233 |
String typeName = featureField.getType();
|
234 |
EditableFeatureAttributeDescriptor attributeDescriptor = null;
|
235 |
|
236 |
IXSTypeDefinition typeDefinition = null;
|
237 |
|
238 |
if (typeName != null){ |
239 |
typeDefinition = xmlSchemaManager.getTypeDefinition(typeName); |
240 |
} |
241 |
|
242 |
if (typeDefinition != null){ |
243 |
if (typeDefinition.getDataType() != null){ |
244 |
if (typeDefinition.getDataType().getType() == DataTypes.GEOMETRY){
|
245 |
dataType = typeDefinition.getDataType().getType(); |
246 |
} |
247 |
} |
248 |
attributeDescriptor = featureType.add(featureField.getName(), dataType); |
249 |
if (typeDefinition instanceof IXSGeometryTypeDefinition){ |
250 |
|
251 |
if (ipro != null) { |
252 |
attributeDescriptor.setSRS(ipro); |
253 |
} else {
|
254 |
if (feature.getSrs().size() > 0){ |
255 |
attributeDescriptor.setSRS(CRSFactory.getCRS((String)feature.getSrs().get(0))); |
256 |
} else {
|
257 |
logger.info("Unable to set CRS in feature type.");
|
258 |
} |
259 |
} |
260 |
|
261 |
|
262 |
attributeDescriptor.setGeometryType(((IXSGeometryTypeDefinition)typeDefinition).getGeometryType()); |
263 |
attributeDescriptor.setGeometrySubType(SUBTYPES.GEOM3D); |
264 |
featureType.setDefaultGeometryAttributeName(featureField.getName()); |
265 |
} |
266 |
}else{
|
267 |
attributeDescriptor = featureType.add(typeName, dataType); |
268 |
} |
269 |
// length, relevant for all (strings) except geometry
|
270 |
attributeDescriptor.setSize(128);
|
271 |
} |
272 |
featureType.setHasOID(true);
|
273 |
|
274 |
FeatureType defaultType = featureType.getNotEditableCopy(); |
275 |
List types = new ArrayList(1); |
276 |
types.add(defaultType); |
277 |
this.getStoreServices().setFeatureTypes(types, defaultType);
|
278 |
} |
279 |
|
280 |
private Envelope calculateFullEnvelope() {
|
281 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
282 |
|
283 |
try{
|
284 |
WFSFeature feature = getSelectedWFSFeature(); |
285 |
if (feature != null){ |
286 |
String _srs = wfsStatus.getSrs();
|
287 |
if (_srs != null) { |
288 |
|
289 |
BoundaryBox boundaryBox = feature.getBbox(_srs); |
290 |
//The projection is found
|
291 |
if (boundaryBox != null){ |
292 |
return geometryManager.createEnvelope(boundaryBox.getXmin(),
|
293 |
boundaryBox.getYmin(), boundaryBox.getXmax(), boundaryBox.getYmax(), SUBTYPES.GEOM2D); |
294 |
} |
295 |
//Check if there is a latlon envelope
|
296 |
boundaryBox = feature.getLatLonBbox(); |
297 |
if (boundaryBox != null){ |
298 |
Envelope envelope = geometryManager.createEnvelope(boundaryBox.getXmin(), |
299 |
boundaryBox.getYmin(), boundaryBox.getXmax(), boundaryBox.getYmax(), SUBTYPES.GEOM2D); |
300 |
if (!"EPSG:4326".equals(_srs)){ |
301 |
IProjection sourceProjection = CRSFactory.getCRS("EPSG:4326");
|
302 |
IProjection destinationProjection = CRSFactory.getCRS(_srs); |
303 |
if (destinationProjection != null){ |
304 |
ICoordTrans coordTrans = sourceProjection.getCT(destinationProjection); |
305 |
return envelope.convert(coordTrans);
|
306 |
} |
307 |
} |
308 |
} |
309 |
}else{
|
310 |
//If there is not a SRS is thrown a request for the first 500 features
|
311 |
int odlMaxFeatures = wfsStatus.getMaxFeatures();
|
312 |
wfsStatus.setMaxFeatures(500);
|
313 |
createSet(null, null); |
314 |
return storeProviderDelegate.getEnvelope();
|
315 |
} |
316 |
} |
317 |
}catch(CreateEnvelopeException e){
|
318 |
logger.error("Impossible to create an envelope", e);
|
319 |
} catch (ReadException e) {
|
320 |
logger.error("Impossible to create an envelope", e);
|
321 |
} catch (WFSException e) {
|
322 |
logger.error("Impossible to create an envelope", e);
|
323 |
} catch (DataException e) {
|
324 |
logger.error("Impossible to create an envelope", e);
|
325 |
} |
326 |
return null; |
327 |
} |
328 |
|
329 |
private WFSStoreParameters getWFSParameters() {
|
330 |
return (WFSStoreParameters) getParameters();
|
331 |
} |
332 |
|
333 |
/* (non-Javadoc)
|
334 |
* @see org.gvsig.fmap.dal.store.gpe.GPEStoreProvider#open()
|
335 |
*/
|
336 |
public void open() throws OpenException { |
337 |
try {
|
338 |
List featureTypes = this.getFeatureStore().getFeatureTypes(); |
339 |
for (int i=0 ; i<featureTypes.size() ; i++){ |
340 |
FeatureType featureType = (FeatureType)featureTypes.get(i); |
341 |
} |
342 |
} catch (DataException e) {
|
343 |
throw new OpenException("Reading the geometry type", e); |
344 |
} |
345 |
} |
346 |
|
347 |
protected static void registerMetadataDefinition() throws MetadataException { |
348 |
if (metadataManager.getDefinition(METADATA_DEFINITION_NAME) == null) { |
349 |
DynStruct metadataDefinition = metadataManager.addDefinition( |
350 |
METADATA_DEFINITION_NAME, METADATA_DEFINITION_DESCRIPTION); |
351 |
|
352 |
metadataDefinition.addDynFieldObject("Envelope").setClassOfValue(Envelope.class).setMandatory(false); |
353 |
metadataDefinition.addDynFieldObject("CRS").setClassOfValue(IProjection.class).setMandatory(true); |
354 |
|
355 |
metadataDefinition.extend(metadataManager |
356 |
.getDefinition(FeatureStore.METADATA_DEFINITION_NAME)); |
357 |
} |
358 |
} |
359 |
|
360 |
/* (non-Javadoc)
|
361 |
* @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#getExplorer()
|
362 |
*/
|
363 |
public DataServerExplorer getExplorer() throws ReadException { |
364 |
DataManager manager = DALLocator.getDataManager(); |
365 |
WFSServerExplorerParameters params; |
366 |
try {
|
367 |
params = (WFSServerExplorerParameters) manager |
368 |
.createServerExplorerParameters(WFSServerExplorer.NAME); |
369 |
params.setUrl(wfsClient.getHost()); |
370 |
return manager.openServerExplorer(WFSServerExplorer.NAME,params);
|
371 |
} catch (Exception e) { |
372 |
throw new ReadException(this.getName(), e); |
373 |
} |
374 |
} |
375 |
|
376 |
public String getProviderName() { |
377 |
return NAME;
|
378 |
} |
379 |
|
380 |
public FeatureSetProvider createSet(FeatureQuery query)
|
381 |
throws DataException {
|
382 |
return createSet(query, null); |
383 |
} |
384 |
|
385 |
public FeatureSetProvider createSet(FeatureQuery query,
|
386 |
FeatureType featureType) throws DataException {
|
387 |
if ((featureCount == -1) || |
388 |
(storeProviderDelegate == null) ||
|
389 |
(featureCount >= wfsStatus.getMaxFeatures())){ |
390 |
|
391 |
File file = executeSpatialQuery();
|
392 |
|
393 |
storeProviderDelegate = createProvider(file); |
394 |
} |
395 |
|
396 |
return storeProviderDelegate.createSet(query, featureType);
|
397 |
} |
398 |
|
399 |
/**
|
400 |
* It creates the provider that is used to retrieve features from a file.
|
401 |
* @param file
|
402 |
* the file that contains the downloaded file
|
403 |
* @return
|
404 |
* @throws InitializeException
|
405 |
* @throws ProviderNotRegisteredException
|
406 |
*/
|
407 |
private GPEStoreProvider createProvider(File file) throws InitializeException, ProviderNotRegisteredException{ |
408 |
return new GPEStoreProvider(createStoreParameters(file), getStoreServices()); |
409 |
} |
410 |
|
411 |
private DataStoreParameters createStoreParameters(File file) throws InitializeException, ProviderNotRegisteredException{ |
412 |
DataStoreParameters parameters = dataManager.createStoreParameters(GPEStoreProvider.NAME); |
413 |
|
414 |
parameters.setDynValue("File", file.getAbsolutePath());
|
415 |
parameters.setDynValue("Envelope", this.getDynValue("Envelope")); |
416 |
parameters.setDynValue("useAxisOrderYX", this.getWFSParameters().getUseAxisOrderYX()); |
417 |
return parameters;
|
418 |
} |
419 |
|
420 |
|
421 |
private File executeSpatialQuery() throws DataException{ |
422 |
try {
|
423 |
Envelope filterByAreaEnvelope = getWFSParameters().getFilterByAreaEnvelope(); |
424 |
Geometry filterByAreaGeometry = getWFSParameters().getFilterByAreaGeometry(); |
425 |
if (filterByAreaEnvelope!=null){ |
426 |
String crs = getWFSParameters().getFilterByAreaCrs();
|
427 |
String the_geom = getWFSParameters().getFilterByAreaAttribute();
|
428 |
int operator = getWFSParameters().getFilterByAreaOperation();
|
429 |
|
430 |
if (this.getWFSParameters().getUseAxisOrderYX()){ |
431 |
Envelope envelope = null;
|
432 |
try {
|
433 |
envelope = (Envelope)filterByAreaEnvelope.clone(); |
434 |
} catch (CloneNotSupportedException e) { |
435 |
//Do nothing
|
436 |
} |
437 |
double x = envelope.getLowerCorner().getX();
|
438 |
envelope.getLowerCorner().setX(envelope.getLowerCorner().getY()); |
439 |
envelope.getLowerCorner().setY(x); |
440 |
|
441 |
x = envelope.getUpperCorner().getX(); |
442 |
envelope.getUpperCorner().setX(envelope.getUpperCorner().getY()); |
443 |
envelope.getUpperCorner().setY(x); |
444 |
filterByAreaEnvelope = envelope; |
445 |
} |
446 |
wfsStatus.setFilterByArea(filterByAreaEnvelope, the_geom, crs,operator); |
447 |
} else if (filterByAreaGeometry!=null){ |
448 |
String crs = getWFSParameters().getFilterByAreaCrs();
|
449 |
String the_geom = getWFSParameters().getFilterByAreaAttribute();
|
450 |
int operator = getWFSParameters().getFilterByAreaOperation();
|
451 |
|
452 |
if (this.getWFSParameters().getUseAxisOrderYX()){ |
453 |
Geometry geom = filterByAreaGeometry.cloneGeometry(); |
454 |
AffineTransform at = new AffineTransform(0,1,1,0,0,1); |
455 |
geom.transform(at); |
456 |
filterByAreaGeometry = geom; |
457 |
} |
458 |
wfsStatus.setFilterByArea(filterByAreaGeometry, the_geom, crs,operator); |
459 |
|
460 |
} |
461 |
wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST); |
462 |
//If it is not possible to calculate the
|
463 |
wfsStatus.setResultType(WFSStatus.RESULTYPE_RESULTS); |
464 |
return wfsClient.getFeature(wfsStatus, getWFSParameters().getIgnoreCache(), null); |
465 |
} catch (WFSException e) {
|
466 |
throw new InitializeException("Impossible to retrieve the file", e); |
467 |
} |
468 |
} |
469 |
|
470 |
public Object getSourceId() { |
471 |
StringBuffer sourceID = new StringBuffer(getWFSParameters().getUrl()); |
472 |
sourceID.append("_" + getWFSParameters().getFeatureType());
|
473 |
int hash = sourceID.hashCode();
|
474 |
if (sourceID.length() > 60){ |
475 |
return sourceID.substring(0, 60) + "_" + hash; |
476 |
}else{
|
477 |
return sourceID.toString() + "_" + hash; |
478 |
} |
479 |
} |
480 |
|
481 |
public Object createNewOID() { |
482 |
try {
|
483 |
return String.valueOf(getFeatureCount()+1); |
484 |
} catch (DataException e) {
|
485 |
return String.valueOf(Math.random()); |
486 |
} |
487 |
} |
488 |
|
489 |
public long getFeatureCount() throws DataException { |
490 |
if (featureCount == -1){ |
491 |
wfsStatus.setResultType(WFSStatus.RESULTYPE_HITS); |
492 |
try {
|
493 |
//The filter encoding is better supported using POST
|
494 |
if (hasFilterByArea){
|
495 |
wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST); |
496 |
}else{
|
497 |
wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_GET); |
498 |
} |
499 |
File file = wfsClient.getFeature(wfsStatus, getWFSParameters().getIgnoreCache(), null); |
500 |
featureCount = ((WFSGetFeatureRequestInformation)wfsClient.getLastWfsRequestInformation()).getNumberOfFeatures(); |
501 |
//If the service doesn't support RESULTTYPE_HITS, parse the file and get the FeatureCount
|
502 |
if (featureCount == -1){ |
503 |
storeProviderDelegate = createProvider(file); |
504 |
featureCount = storeProviderDelegate.getFeatureCount(); |
505 |
} |
506 |
} catch (WFSException e) {
|
507 |
throw new ConnectionServerException("Error calculating the feature count", e); |
508 |
} |
509 |
} |
510 |
return featureCount;
|
511 |
} |
512 |
|
513 |
public int getOIDType() { |
514 |
return DataTypes.STRING;
|
515 |
} |
516 |
|
517 |
public ResourceProvider getResource() {
|
518 |
return storeProviderDelegate.getResource();
|
519 |
} |
520 |
|
521 |
protected FeatureProvider internalGetFeatureProviderByReference(
|
522 |
FeatureReferenceProviderServices reference, FeatureType featureType) |
523 |
throws DataException {
|
524 |
return storeProviderDelegate.internalGetFeatureProviderByReference(reference, featureType);
|
525 |
} |
526 |
|
527 |
public String getFullName() { |
528 |
return getWFSParameters().getUrl() + "_" + getWFSParameters().getFeatureType(); |
529 |
} |
530 |
|
531 |
public String getName() { |
532 |
return getWFSParameters().getFeatureType();
|
533 |
} |
534 |
|
535 |
public boolean isKnownEnvelope(){ |
536 |
return isKnownEnvelope;
|
537 |
} |
538 |
|
539 |
public boolean hasRetrievedFeaturesLimit(){ |
540 |
return true; |
541 |
} |
542 |
|
543 |
public int getRetrievedFeaturesLimit(){ |
544 |
//WFS 1.0.0 can not know where is the limit
|
545 |
if (getWFSParameters().getVersion().equals("1.0.0")){ |
546 |
return 0; |
547 |
}else{
|
548 |
return wfsClient.getServiceInformation().getMaxFeatures();
|
549 |
} |
550 |
} |
551 |
|
552 |
public void performChanges(Iterator deleteds, Iterator inserteds, |
553 |
Iterator updateds, Iterator featureTypesChanged) |
554 |
throws DataException {
|
555 |
wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST); |
556 |
WFSTTransactionBuilder transactionBuilder = new WFSTTransactionBuilder(wfsStatus, wfsClient);
|
557 |
|
558 |
//Create the Query
|
559 |
try {
|
560 |
//Add new features
|
561 |
while (inserteds.hasNext()){
|
562 |
transactionBuilder.addInsertFeature((FeatureProvider)inserteds.next()); |
563 |
} |
564 |
//Add deleted features
|
565 |
while (deleteds.hasNext()){
|
566 |
transactionBuilder.addDeleteFeature( |
567 |
internalGetFeatureProviderByReference((FeatureReferenceProviderServices)deleteds.next(), null).getOID().toString());;
|
568 |
} |
569 |
//Add updated features
|
570 |
while (updateds.hasNext()){
|
571 |
transactionBuilder.addUpdateFeature((FeatureProvider)updateds.next()); |
572 |
} |
573 |
} catch (WriterHandlerCreationException e) {
|
574 |
throw new WFSTTRansactionException(e); |
575 |
} catch (GeometryOperationNotSupportedException e) {
|
576 |
throw new WFSTTRansactionException(e); |
577 |
} catch (GeometryOperationException e) {
|
578 |
throw new WFSTTRansactionException(e); |
579 |
} |
580 |
|
581 |
//Send the query to the server
|
582 |
try {
|
583 |
wfsClient.transaction(wfsStatus, true, null); |
584 |
WFSTransactionRequestInformation transactionRequestInformation = (WFSTransactionRequestInformation)wfsClient.getLastWfsRequestInformation(); |
585 |
if (transactionRequestInformation.getStatus() == WFSTransactionRequestInformation.STATUS_FAILED){
|
586 |
throw new WFSTTRansactionException(transactionRequestInformation.getMessage()); |
587 |
} |
588 |
} catch (WFSException e) {
|
589 |
throw new WFSTTRansactionException(e); |
590 |
} |
591 |
} |
592 |
|
593 |
public boolean allowWrite() { |
594 |
return wfsClient.getServiceInformation().isOperationSupported("Transaction"); |
595 |
} |
596 |
|
597 |
public Envelope getEnvelope() throws DataException { |
598 |
return (Envelope) this.getDynValue("Envelope"); |
599 |
} |
600 |
|
601 |
public FeatureProvider createFeatureProvider(FeatureType type)
|
602 |
throws DataException {
|
603 |
return super.createFeatureProvider(type); |
604 |
} |
605 |
|
606 |
|
607 |
} |
608 |
|