Skip to content

Commit

Permalink
Specifying the right rel for landing page links
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Aug 6, 2018
1 parent 100ed56 commit 38cb61f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,31 +49,31 @@ public LandingPageDocument(LandingPageRequest request, WFSInfo wfs, Catalog cata
link.setRel(Link.REL_SELF); link.setRel(Link.REL_SELF);
link.setTitle("This document"); link.setTitle("This document");
} }
}); }, Link.REL_ALTERNATE);
// api // api
addLinksFor( addLinksFor(
baseUrl, baseUrl,
"wfs3/api", "wfs3/api",
OpenAPI.class, OpenAPI.class,
"API definition for this endpoint as ", "API definition for this endpoint as ",
"api", "api",
null); null, Link.REL_SERVICE);
// conformance // conformance
addLinksFor( addLinksFor(
baseUrl, baseUrl,
"wfs3/conformance", "wfs3/conformance",
ConformanceDocument.class, ConformanceDocument.class,
"Conformance declaration as ", "Conformance declaration as ",
"conformance", "conformance",
null); null, "conformance");
// collections // collections
addLinksFor( addLinksFor(
baseUrl, baseUrl,
"wfs3/collections", "wfs3/collections",
CollectionsDocument.class, CollectionsDocument.class,
"Collections Metadata as ", "Collections Metadata as ",
"collections", "collections",
null); null, "data");
} }


/** Builds service links for the given response types */ /** Builds service links for the given response types */
Expand All @@ -83,13 +83,12 @@ private void addLinksFor(
Class<?> responseType, Class<?> responseType,
String titlePrefix, String titlePrefix,
String classification, String classification,
BiConsumer<String, Link> linkUpdater) { BiConsumer<String, Link> linkUpdater, String rel) {
for (String format : DefaultWebFeatureService30.getAvailableFormats(responseType)) { for (String format : DefaultWebFeatureService30.getAvailableFormats(responseType)) {
Map<String, String> params = Collections.singletonMap("f", format); Map<String, String> params = Collections.singletonMap("f", format);
String url = buildURL(baseUrl, path, params, URLMangler.URLType.SERVICE); String url = buildURL(baseUrl, path, params, URLMangler.URLType.SERVICE);
String linkType = Link.REL_SERVICE;
String linkTitle = titlePrefix + format; String linkTitle = titlePrefix + format;
Link link = new Link(url, linkType, format, linkTitle); Link link = new Link(url, rel, format, linkTitle);
link.setClassification(classification); link.setClassification(classification);
if (linkUpdater != null) { if (linkUpdater != null) {
linkUpdater.accept(format, link); linkUpdater.accept(format, link);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</p> </p>


<h2>API definition</h2> <h2>API definition</h2>
<p>The <a id="jsonApiLink" href="${model.getLinkUrl('api', 'text/html')!}"> API document</a> provides a machine processable description of this service API conformant to OpenAPI 3. <p>The <a id="htmlApiLink" href="${model.getLinkUrl('api', 'text/html')!}"> API document</a> provides a machine processable description of this service API conformant to OpenAPI 3.
<br/> <br/>
This API document is also available as This API document is also available as
<#list model.getLinksExcept("api", "application/json") as link><a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>. <#list model.getLinksExcept("api", "application/json") as link><a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>.
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;


import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.DocumentContext;
import java.util.List;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Test; import org.junit.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;


import java.util.List;

public class LandingPageTest extends WFS3TestSupport { public class LandingPageTest extends WFS3TestSupport {


@Test @Test
Expand Down Expand Up @@ -43,9 +45,9 @@ private void checkJSONLandingPage(DocumentContext json) {
assertJSONList( assertJSONList(
json, json,
"links[?(@.type != 'application/json' && @.href =~ /.*wfs3\\/\\?.*/)].rel", "links[?(@.type != 'application/json' && @.href =~ /.*wfs3\\/\\?.*/)].rel",
"service", "alternate",
"service", "alternate",
"service"); "alternate");
// check API links // check API links
assertJSONList( assertJSONList(
json, json,
Expand All @@ -58,17 +60,17 @@ private void checkJSONLandingPage(DocumentContext json) {
assertJSONList( assertJSONList(
json, json,
"links[?(@.href =~ /.*wfs3\\/conformance.*/)].rel", "links[?(@.href =~ /.*wfs3\\/conformance.*/)].rel",
"service", "conformance",
"service", "conformance",
"service"); "conformance");
// check collection links // check collection links
assertJSONList( assertJSONList(
json, json,
"links[?(@.href =~ /.*wfs3\\/collections.*/)].rel", "links[?(@.href =~ /.*wfs3\\/collections.*/)].rel",
"service", "data",
"service", "data",
"service", "data",
"service"); "data");
} }


private <T> void assertJSONList(DocumentContext json, String path, T... expected) { private <T> void assertJSONList(DocumentContext json, String path, T... expected) {
Expand Down Expand Up @@ -104,7 +106,7 @@ public void testLandingPageHTML() throws Exception {
"http://localhost:8080/geoserver/wfs3/collections?f=text%2Fhtml", "http://localhost:8080/geoserver/wfs3/collections?f=text%2Fhtml",
document.select("#htmlCollectionsLink").attr("href")); document.select("#htmlCollectionsLink").attr("href"));
assertEquals( assertEquals(
"http://localhost:8080/geoserver/wfs3/api?f=application%2Fjson", "http://localhost:8080/geoserver/wfs3/api?f=text%2Fhtml",
document.select("#jsonApiLink").attr("href")); document.select("#htmlApiLink").attr("href"));
} }
} }

0 comments on commit 38cb61f

Please sign in to comment.