getFeature.getQuery().add(wfsQuery);
@Override public String getAttachmentFileName(Object value, Operation operation) { GetFeatureType request = (GetFeatureType) OwsUtils.parameter(operation.getParameters(), GetFeatureType.class); OgrFormat format = formats.get(request.getOutputFormat()); if (format == null) { throw new WFSException("Unknown output format " + request.getOutputFormat()); } else if (!format.singleFile || request.getQuery().size() > 1) { String outputFileName = ((QName) ((QueryType) request.getQuery().get(0)).getTypeName() .get(0)).getLocalPart(); return outputFileName + ".zip"; } else { return null; } }
/** * Ionic uses {@code urn:opengis:def:crs:ogc::83} instead of {@code EPSG:4269}. If that's the * case, the query srsName is replaced by the kown "EPSG:4269" code */ @Override public RequestComponents createGetFeatureRequest(WFSProtocol wfs, GetFeature query) throws IOException { RequestComponents req = super.createGetFeatureRequest(wfs, query); GetFeatureType getFeature = req.getServerRequest(); QueryType queryType = (QueryType) getFeature.getQuery().get(0); URI srsNameUri = queryType.getSrsName(); final String overrideSrs = "urn:opengis:def:crs:ogc::83"; if (srsNameUri != null && srsNameUri.toString().equalsIgnoreCase(overrideSrs)) { try { queryType.setSrsName(new URI("EPSG:4269")); } catch (URISyntaxException e) { throw new RuntimeException("shouln't happen: " + e.getMessage()); } Map<String, String> kvpParameters = req.getKvpParameters(); kvpParameters.put("SRSNAME", "EPSG:4269"); } return req; }
final QueryType query = (QueryType) request.getQuery().get(0); final String typeName = (String) query.getTypeName().get(0); map.put("TYPENAME", typeName);
/** * @see WFSGetFeatureOutputFormat#getMimeType(Object, Operation) */ public String getMimeType(Object value, Operation operation) throws ServiceException { GetFeatureType request = (GetFeatureType) OwsUtils.parameter(operation.getParameters(), GetFeatureType.class); OgrFormat format = formats.get(request.getOutputFormat()); if (format == null) { throw new WFSException("Unknown output format " + request.getOutputFormat()); } else if (format.singleFile && request.getQuery().size() <= 1) { if(format.mimeType != null) { return format.mimeType; } else { // use a default binary blob return "application/octet-stream"; } } else { return "application/zip"; } }
/** * @return a {@link GetFeatureParser} to stream the contents of the GML 3.1 response */ public Object parse(WFS_1_1_0_DataStore wfs, WFSResponse response) throws IOException { GetFeatureType request = (GetFeatureType) response.getOriginatingRequest(); QueryType queryType = (QueryType) request.getQuery().get(0); String prefixedTypeName = (String) queryType.getTypeName().get(0); SimpleFeatureType schema = wfs.getSchema(prefixedTypeName); List<String> propertyNames = queryType.getPropertyName(); if (propertyNames.size() > 0) { // the expected schema may contain less properties than the full schema. Let's say it to // the parser so it does not parse unnecessary attributes in case the WFS returns more // than requested String[] properties = propertyNames.toArray(new String[propertyNames.size()]); try { schema = DataUtilities.createSubType(schema, properties); } catch (SchemaException e) { throw (RuntimeException) new RuntimeException().initCause(e); } } QName featureName = wfs.getFeatureTypeName(prefixedTypeName); InputStream in = response.getInputStream(); GetFeatureParser featureReader = new XmlSimpleFeatureParser(in, schema, featureName, wfs.getAxisOrderForOutput()); return featureReader; } }
/** See https://osgeo-org.atlassian.net/browse/GEOS-1875 */ @SuppressWarnings("unchecked") @Test public void testUserProvidedNamespace() throws Exception { final String localPart = SystemTestData.MLINES.getLocalPart(); final String namespace = SystemTestData.MLINES.getNamespaceURI(); final String alternamePrefix = "ex"; final String alternameTypeName = alternamePrefix + ":" + localPart; Map<String, String> raw = new HashMap<String, String>(); raw.put("service", "WFS"); raw.put("version", "1.1.0"); raw.put("request", "GetFeature"); raw.put("typeName", alternameTypeName); raw.put("namespace", "xmlns(" + alternamePrefix + "=" + namespace + ")"); Map<String, Object> parsed = parseKvp(raw); GetFeatureType req = WfsFactory.eINSTANCE.createGetFeatureType(); Object read = reader.read(req, parsed, raw); GetFeatureType parsedReq = (GetFeatureType) read; QueryType query = (QueryType) parsedReq.getQuery().get(0); List<QName> typeNames = query.getTypeName(); assertEquals(1, typeNames.size()); assertEquals(SystemTestData.MLINES, typeNames.get(0)); }
/** See https://osgeo-org.atlassian.net/browse/GEOS-1875 */ @SuppressWarnings("unchecked") @Test public void testUserProvidedDefaultNamespace() throws Exception { final QName qName = SystemTestData.STREAMS; final String typeName = qName.getLocalPart(); final String defaultNamespace = qName.getNamespaceURI(); Map<String, String> raw = new HashMap<String, String>(); raw.put("service", "WFS"); raw.put("version", "1.1.0"); raw.put("request", "GetFeature"); raw.put("typeName", typeName); raw.put("namespace", "xmlns(" + defaultNamespace + ")"); Map<String, Object> parsed = parseKvp(raw); GetFeatureType req = WfsFactory.eINSTANCE.createGetFeatureType(); Object read = reader.read(req, parsed, raw); GetFeatureType parsedReq = (GetFeatureType) read; QueryType query = (QueryType) parsedReq.getQuery().get(0); List<QName> typeNames = query.getTypeName(); assertEquals(1, typeNames.size()); assertEquals(qName, typeNames.get(0)); }
/** * Turns a GetLogType objects into an almost equivalent GetFeatureType object s * that the superclass can do its work * @param featureCollection * @param request * @return */ private GetFeatureType toGetFeatureType(FeatureCollectionType featureCollection, GetLogType request) { FeatureCollection features = (FeatureCollection) featureCollection.getFeature().get(0); FeatureType featureType = features.getSchema(); GetFeatureType ftRequest = WfsFactory.eINSTANCE.createGetFeatureType(); QueryType query = WfsFactory.eINSTANCE.createQueryType(); query.setTypeName(Collections.singletonList(featureType.getTypeName())); ftRequest.getQuery().add(query); ftRequest.setBaseUrl(request.getBaseUrl()); ftRequest.setHandle(request.getHandle()); ftRequest.setMaxFeatures(request.getMaxFeatures()); ftRequest.setOutputFormat(request.getOutputFormat()); ftRequest.setResultType(ResultTypeType.RESULTS_LITERAL); return ftRequest; }
/** * Build a GetFeature operation to request the named types. * * @param names type names for which queries are present in the returned request * @return GetFeature operation to request the named types */ Operation request(QName... names) { Service service = getServiceDescriptor10(); GetFeatureType type = WfsFactory.eINSTANCE.createGetFeatureType(); type.setBaseUrl("http://localhost:8080/geoserver"); for (QName name : names) { QueryType queryType = WfsFactory.eINSTANCE.createQueryType(); queryType.setTypeName(Collections.singletonList(name)); type.getQuery().add(queryType); } Operation request = new Operation("wfs", service, null, new Object[] {type}); return request; }
@Test public void testWFSGetFeature() throws Exception { GetFeatureType gf = WfsFactory.eINSTANCE.createGetFeatureType(); org.opengis.filter.Filter f1 = parseFilter("BBOX(the_geom, 40, -90, 45, -60)"); org.opengis.filter.Filter f2 = parseFilter("BBOX(the_geom, 5988504.35,851278.90, 7585113.55,1950872.01)"); QueryType q = WfsFactory.eINSTANCE.createQueryType(); q.setTypeName(Arrays.asList(new QName("http://acme.org", "foo", "acme"))); q.setFilter(f1); gf.getQuery().add(q); q = WfsFactory.eINSTANCE.createQueryType(); q.setTypeName(Arrays.asList(new QName("http://acme.org", "bar", "acme"))); gf.getQuery().add(q);getClass(); q.setFilter(f2); Operation op = op("GetFeature", "WFS", "1.0.0", gf); callback.operationDispatched(new Request(), op); assertEquals("acme:foo", data.getResources().get(0)); assertEquals("acme:bar", data.getResources().get(1)); BoundingBox expected = new ReferencedEnvelope(53.73,40, -60,-95.1193,CRS.decode("EPSG:4326")); // xMin,yMin -95.1193,40 : xMax,yMax -60,53.73 BBoxAsserts.assertEqualsBbox(expected, data.getBbox(), 0.01); }
gfreq.getQuery().add(qt);
getFeature.getQuery().add(wfsQuery);
@Test public void testWFSGetFeature() throws Exception { GetFeatureType gf = WfsFactory.eINSTANCE.createGetFeatureType(); org.opengis.filter.Filter f1 = parseFilter("BBOX(the_geom, 40, -90, 45, -60)"); org.opengis.filter.Filter f2 = parseFilter("BBOX(the_geom, 5988504.35,851278.90, 7585113.55,1950872.01)"); QueryType q = WfsFactory.eINSTANCE.createQueryType(); q.setTypeName(Arrays.asList(new QName("http://acme.org", "foo", "acme"))); q.setFilter(f1); gf.getQuery().add(q); q = WfsFactory.eINSTANCE.createQueryType(); q.setTypeName(Arrays.asList(new QName("http://acme.org", "bar", "acme"))); gf.getQuery().add(q); getClass(); q.setFilter(f2); Operation op = op("GetFeature", "WFS", "1.0.0", gf); callback.operationDispatched(new Request(), op); assertEquals("acme:foo", data.getResources().get(0)); assertEquals("acme:bar", data.getResources().get(1)); BoundingBox expected = new ReferencedEnvelope(53.73, 40, -60, -95.1193, CRS.decode("EPSG:4326")); // xMin,yMin -95.1193,40 : xMax,yMax -60,53.73 BBoxAsserts.assertEqualsBbox(expected, data.getBbox(), 0.01); }
getFeature.getQuery().add(wfsQuery);
gfreq.getQuery().add(qt);
gfreq.getQuery().add(qt);
getFeature.getQuery().addAll(node.getChildValues(QueryType.class));
getFeature.getQuery().addAll(node.getChildValues(QueryType.class));
getFeature.getQuery().addAll(node.getChildValues(QueryType.class));