Skip to content

Commit

Permalink
Adding tiles links in standalone collections too
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Oct 15, 2018
1 parent db632a9 commit 064a776
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void extendCollection(CollectionDocument collection, BaseRequest request)
"tilingScheme",
MapBoxTileBuilderFactory.MIME_TYPE,
collectionId
+ " associated tiling schemes. he link is a URI template \"\n"
+ " associated tiling schemes. The link is a URI template \"\n"
+ " + \"where {tilingSchemeId} is one of the schemes listed in the 'tilingSchemes' resource",
"items"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public List<Link> getLinks() {
public Iterator<CollectionDocument> getCollections() {
// single collection case
if (featureType != null) {
return Collections.singleton(new CollectionDocument(geoServer, request, featureType))
.iterator();
CollectionDocument document = new CollectionDocument(geoServer, request, featureType);
decorateWithExtensions(document);
return Collections.singleton(document).iterator();
}

// full scan case
Expand All @@ -111,11 +112,7 @@ public boolean hasNext() {
FeatureTypeInfo featureType = featureTypes.next();
CollectionDocument collection =
new CollectionDocument(geoServer, request, featureType);
if (extensions != null) {
for (WFS3Extension extension : extensions) {
extension.extendCollection(collection, request);
}
}
decorateWithExtensions(collection);

next = collection;
return true;
Expand All @@ -135,4 +132,12 @@ public CollectionDocument next() {
}
};
}

private void decorateWithExtensions(CollectionDocument collection) {
if (extensions != null) {
for (WFS3Extension extension : extensions) {
extension.extendCollection(collection, request);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

import com.jayway.jsonpath.DocumentContext;
import java.util.List;
Expand All @@ -14,15 +15,16 @@
import org.geoserver.data.test.MockData;
import org.geoserver.wfs.request.FeatureCollectionResponse;
import org.geoserver.wfs3.response.GML32WFS3OutputFormat;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.w3c.dom.Document;

public class CollectionTest extends WFS3TestSupport {

@Test
public void testCollectionJson() throws Exception {
DocumentContext json =
getAsJSONPath("wfs3/collections/" + getEncodedName(MockData.ROAD_SEGMENTS), 200);
String roadSegments = getEncodedName(MockData.ROAD_SEGMENTS);
DocumentContext json = getAsJSONPath("wfs3/collections/" + roadSegments, 200);

assertEquals("cite__RoadSegments", json.read("$.name", String.class));
assertEquals("RoadSegments", json.read("$.title", String.class));
Expand All @@ -34,7 +36,9 @@ public void testCollectionJson() throws Exception {
// check we have the expected number of links and they all use the right "rel" relation
List<String> formats =
DefaultWebFeatureService30.getAvailableFormats(FeatureCollectionResponse.class);
assertEquals(formats.size(), (int) json.read("$.links.length()", Integer.class));
assertThat(
(int) json.read("$.links.length()", Integer.class),
Matchers.greaterThanOrEqualTo(formats.size()));
for (String format : formats) {
// check title and rel.
List items = json.read("$.links[?(@.type=='" + format + "')]", List.class);
Expand All @@ -44,6 +48,20 @@ public void testCollectionJson() throws Exception {
}
// the WFS3 specific GML3.2 output format is available
assertNotNull(json.read("$.links[?(@.type=='" + GML32WFS3OutputFormat.FORMAT + "')]"));

// tiling scheme extension
Map tilingScheme = (Map) json.read("links[?(@.rel=='tilingScheme')]", List.class).get(0);
assertEquals(
"http://localhost:8080/geoserver/wfs3/collections/"
+ roadSegments
+ "/tiles/{tilingSchemeId}",
tilingScheme.get("href"));
Map tiles = (Map) json.read("links[?(@.rel=='tiles')]", List.class).get(0);
assertEquals(
"http://localhost:8080/geoserver/wfs3/collections/"
+ roadSegments
+ "/tiles/{tilingSchemeId}/{level}/{row}/{col}",
tiles.get("href"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ public void testCollectionsJson() throws Exception {
Map item = (Map) items.get(0);
assertEquals("item", item.get("rel"));
}
// tiling scheme extension
Map tilingScheme =
(Map)
json.read("collections[0].links[?(@.rel=='tilingScheme')]", List.class)
.get(0);
assertEquals(
"http://localhost:8080/geoserver/wfs3/collections/cgf__Lines/tiles/{tilingSchemeId}",
tilingScheme.get("href"));
Map tiles = (Map) json.read("collections[0].links[?(@.rel=='tiles')]", List.class).get(0);
assertEquals(
"http://localhost:8080/geoserver/wfs3/collections/cgf__Lines/tiles/{tilingSchemeId}/{level}/{row}/{col}",
tiles.get("href"));
}

@Test
Expand Down

0 comments on commit 064a776

Please sign in to comment.