Skip to content

Commit

Permalink
[GEOS-8426] WFS 2.0 (CITE specific): a service exception should be th…
Browse files Browse the repository at this point in the history
…rown if the resourceId is not a match for the specified typenames - follow up for the matching case
  • Loading branch information
aaime committed Nov 24, 2017
1 parent 3ade7e0 commit 25b471f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public Object read(Object request, Map kvp, Map rawKvp) throws Exception {


Set<List> hTypeNames = new HashSet<>(); Set<List> hTypeNames = new HashSet<>();
for (int i = 0; i < featureId.size(); i++) { for (int i = 0; i < featureId.size(); i++) {
QName typeName = getTypeNameFromFeaturId((String) featureId.get(i)); QName typeName = getTypeNameFromFeatureId((String) featureId.get(i));
if(typeName != null) { if(typeName != null) {
hTypeNames.add(Arrays.asList(typeName)); hTypeNames.add(Arrays.asList(typeName));
} }
Expand Down Expand Up @@ -222,9 +222,9 @@ public Object read(Object request, Map kvp, Map rawKvp) throws Exception {
String fid = (String) i.next(); String fid = (String) i.next();
// check consistency between resourceId and typeName (per WFS 2.0 CITE tests) // check consistency between resourceId and typeName (per WFS 2.0 CITE tests)
if (getWFS().isCiteCompliant() && typeNames != null && !typeNames.isEmpty()) { if (getWFS().isCiteCompliant() && typeNames != null && !typeNames.isEmpty()) {
QName qName = getTypeNameFromFeaturId(fid); QName qName = getTypeNameFromFeatureId(fid);
if (qName != null) { if (qName != null) {
if (!typeNames.stream().flatMap(List::stream).anyMatch(q -> qName.equals(q))) { if (!typeNames.stream().flatMap(List::stream).anyMatch(q -> typeNameMatch(qName, q))) {
String locator = isFeatureId ? "FEATUREID" : "RESOURCEID"; String locator = isFeatureId ? "FEATUREID" : "RESOURCEID";
WFSException exception = new WFSException(eObject, "ResourceId is incosistent with typenames"); WFSException exception = new WFSException(eObject, "ResourceId is incosistent with typenames");
exception.setCode(ServiceException.INVALID_PARAMETER_VALUE); exception.setCode(ServiceException.INVALID_PARAMETER_VALUE);
Expand Down Expand Up @@ -343,8 +343,13 @@ else if( kvp.get("propertyName") != null && kvp.get("propertyName") instanceof S


return request; return request;
} }


QName getTypeNameFromFeaturId(String fid) throws Exception { public boolean typeNameMatch(QName maybeUnqualified, QName qualified) {
return maybeUnqualified.equals(qualified) || ((maybeUnqualified.getNamespaceURI() == null || maybeUnqualified
.getNamespaceURI().isEmpty()) && qualified.getLocalPart().equals(maybeUnqualified.getLocalPart()));
}

QName getTypeNameFromFeatureId(String fid) throws Exception {
int pos = fid.indexOf("."); int pos = fid.indexOf(".");


if (pos != -1) { if (pos != -1) {
Expand Down
25 changes: 24 additions & 1 deletion src/wfs/src/test/java/org/geoserver/wfs/v2_0/GetFeatureTest.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void testGetWithFeatureId() throws Exception {
@Test @Test
public void testGetWithResourceId() throws Exception { public void testGetWithResourceId() throws Exception {
Document doc = Document doc =
getAsDOM("wfs?request=GetFeature&typeName=cdf:Fifteen&version=2.0.0&service=wfs&resourceid=Fifteen.2"); getAsDOM("wfs?request=GetFeature&typeNames=cdf:Fifteen&version=2.0.0&service=wfs&resourceid=Fifteen.2");
assertGML32(doc); assertGML32(doc);


XMLAssert.assertXpathEvaluatesTo("1", "count(//wfs:FeatureCollection/wfs:member/cdf:Fifteen)", XMLAssert.assertXpathEvaluatesTo("1", "count(//wfs:FeatureCollection/wfs:member/cdf:Fifteen)",
Expand Down Expand Up @@ -233,6 +233,29 @@ public void testGetWithInconsistentResourceId() throws Exception {


} }


@Test
public void testGetWithConsistentResourceId() throws Exception {
GeoServer gs = getGeoServer();
WFSInfo wfs = gs.getService(WFSInfo.class);
wfs.setCiteCompliant(true);
gs.save(wfs);

try {
Document doc =
getAsDOM("wfs?request=GetFeature&typeNames=cdf:Fifteen&version=2.0.0&service=wfs&resourceid=Fifteen.2");
assertGML32(doc);

XMLAssert.assertXpathEvaluatesTo("1", "count(//wfs:FeatureCollection/wfs:member/cdf:Fifteen)",
doc);
XMLAssert.assertXpathEvaluatesTo("Fifteen.2",
"//wfs:FeatureCollection/wfs:member/cdf:Fifteen/@gml:id", doc);
} finally {
wfs.setCiteCompliant(false);
gs.save(wfs);
}

}

@Test @Test
public void testGetWithBBOX() throws Exception { public void testGetWithBBOX() throws Exception {
Document dom = Document dom =
Expand Down

0 comments on commit 25b471f

Please sign in to comment.