Skip to content

Commit

Permalink
Adding HTML representation for collections page
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Jun 28, 2018
1 parent 9816ce2 commit ee44d73
Show file tree
Hide file tree
Showing 16 changed files with 803 additions and 59 deletions.
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* (c) 2018 Open Source Geospatial Foundation - all rights reserved
* * This code is licensed under the GPL 2.0 license, available at the root
* * application directory.
*
*/

package org.geoserver.wfs3.response;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class AbstractDocument {
protected final List<Link> links = new ArrayList<>();

public void addLink(Link link) {
links.add(link);
}

@JacksonXmlProperty(namespace = Link.ATOM_NS, localName = "link")
@JacksonXmlElementWrapper(useWrapping = false)
public List<Link> getLinks() {
return links;
}

public String getLinkUrl(String classification, String type) {
return links.stream()
.filter(l -> Objects.equals(classification, l.getClassification()))
.filter(l -> type.equals(l.getType()))
.map(l -> l.getHref())
.findFirst()
.orElse(null);
}

public List<Link> getLinksExcept(String classification, String excludedType) {
return links.stream()
.filter(
l ->
classification == null
|| Objects.equals(classification, l.getClassification()))
.filter(l -> excludedType == null || !excludedType.equals(l.getType()))
.collect(Collectors.toList());
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.geoserver.catalog.FeatureTypeInfo; import org.geoserver.catalog.FeatureTypeInfo;
Expand All @@ -22,19 +21,18 @@


/** Description of a single collection, that will be serialized to JSON/XML/HTML */ /** Description of a single collection, that will be serialized to JSON/XML/HTML */
@JsonPropertyOrder({"name", "title", "description", "extent", "links"}) @JsonPropertyOrder({"name", "title", "description", "extent", "links"})
public class CollectionDocument { public class CollectionDocument extends AbstractDocument {
String name; String name;
String title; String title;
String description; String description;
WFSExtents extent; WFSExtents extent;
List<Link> links = new ArrayList<>();


public CollectionDocument(BaseRequest request, FeatureTypeInfo featureType) { public CollectionDocument(BaseRequest request, FeatureTypeInfo featureType) {
// basic info // basic info
String collectionId = NCNameResourceCodec.encode(featureType); String collectionId = NCNameResourceCodec.encode(featureType);
setName(collectionId); setName(collectionId);
setTitle(featureType.getTitle()); setTitle(featureType.getTitle());
setDescription(featureType.getDescription()); setDescription(featureType.getAbstract());
ReferencedEnvelope bbox = featureType.getLatLonBoundingBox(); ReferencedEnvelope bbox = featureType.getLatLonBoundingBox();
setExtent(new WFSExtents(bbox)); setExtent(new WFSExtents(bbox));


Expand All @@ -49,7 +47,13 @@ public CollectionDocument(BaseRequest request, FeatureTypeInfo featureType) {
"wfs3/collections/" + collectionId + "/items", "wfs3/collections/" + collectionId + "/items",
Collections.singletonMap("f", format), Collections.singletonMap("f", format),
URLMangler.URLType.SERVICE); URLMangler.URLType.SERVICE);
addLink(new Link(apiUrl, Link.REL_ABOUT, format, collectionId + " as " + format)); addLink(
new Link(
apiUrl,
Link.REL_ABOUT,
format,
collectionId + " as " + format,
"items"));
} }
} }


Expand Down Expand Up @@ -93,8 +97,4 @@ public void setExtent(WFSExtents extent) {
public List<Link> getLinks() { public List<Link> getLinks() {
return links; return links;
} }

public void addLink(Link link) {
links.add(link);
}
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
Expand All @@ -29,11 +28,10 @@
*/ */
@JacksonXmlRootElement(localName = "Collections") @JacksonXmlRootElement(localName = "Collections")
@JsonPropertyOrder({"links", "links", "collections"}) @JsonPropertyOrder({"links", "links", "collections"})
public class CollectionsDocument { public class CollectionsDocument extends AbstractDocument {


private final Catalog catalog; private final Catalog catalog;
private final WFSInfo wfs; private final WFSInfo wfs;
private final List<Link> links = new ArrayList<>();
private final BaseRequest request; private final BaseRequest request;
private final FeatureTypeInfo featureType; private final FeatureTypeInfo featureType;


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* (c) 2018 Open Source Geospatial Foundation - all rights reserved
* * This code is licensed under the GPL 2.0 license, available at the root
* * application directory.
*
*/
package org.geoserver.wfs3.response;

import java.io.IOException;
import org.geoserver.catalog.ResourceInfo;
import org.geoserver.config.GeoServer;
import org.geoserver.platform.GeoServerResourceLoader;

public class CollectionsHTMLResponse extends AbstractHTMLResponse {

public CollectionsHTMLResponse(GeoServerResourceLoader loader, GeoServer geoServer)
throws IOException {
super(CollectionsDocument.class, loader, geoServer);
}

@Override
protected String getTemplateName(Object value) {
return "collections.ftl";
}

@Override
protected ResourceInfo getResource(Object value) {
return null;
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@


import static org.geoserver.ows.util.ResponseUtils.buildURL; import static org.geoserver.ows.util.ResponseUtils.buildURL;


import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.OpenAPI;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import org.geoserver.catalog.Catalog; import org.geoserver.catalog.Catalog;
import org.geoserver.ows.URLMangler; import org.geoserver.ows.URLMangler;
import org.geoserver.wfs.WFSInfo; import org.geoserver.wfs.WFSInfo;
Expand All @@ -29,11 +23,10 @@
* JSON/YAML (and can be used as a Freemarker template model) * JSON/YAML (and can be used as a Freemarker template model)
*/ */
@JacksonXmlRootElement(localName = "LandingPage") @JacksonXmlRootElement(localName = "LandingPage")
public class LandingPageDocument { public class LandingPageDocument extends AbstractDocument {


private final Catalog catalog; private final Catalog catalog;
private final WFSInfo wfs; private final WFSInfo wfs;
private final List<Link> links = new ArrayList<>();
private final LandingPageRequest request; private final LandingPageRequest request;


public LandingPageDocument(LandingPageRequest request, WFSInfo wfs, Catalog catalog) { public LandingPageDocument(LandingPageRequest request, WFSInfo wfs, Catalog catalog) {
Expand Down Expand Up @@ -101,33 +94,7 @@ private void addLinksFor(
if (linkUpdater != null) { if (linkUpdater != null) {
linkUpdater.accept(format, link); linkUpdater.accept(format, link);
} }
links.add(link); addLink(link);
} }
} }

public void addLink(Link link) {
links.add(link);
}

@JacksonXmlProperty(namespace = Link.ATOM_NS, localName = "link")
@JacksonXmlElementWrapper(useWrapping = false)
public List<Link> getLinks() {
return links;
}

public String getLinkUrl(String classification, String type) {
return links.stream()
.filter(l -> Objects.equals(classification, l.getClassification()))
.filter(l -> type.equals(l.getType()))
.map(l -> l.getHref())
.findFirst()
.orElse(null);
}

public List<Link> getLinksExcept(String classification, String excludedType) {
return links.stream()
.filter(l -> Objects.equals(classification, l.getClassification()))
.filter(l -> !excludedType.equals(l.getType()))
.collect(Collectors.toList());
}
} }
4 changes: 4 additions & 0 deletions src/community/wfs3/src/main/resources/applicationContext.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<bean id="collectionsResponse" class="org.geoserver.wfs3.response.CollectionsDocumentResponse"> <bean id="collectionsResponse" class="org.geoserver.wfs3.response.CollectionsDocumentResponse">
<constructor-arg ref="geoServer"/> <constructor-arg ref="geoServer"/>
</bean> </bean>
<bean id="collectionsHTMLResponse" class="org.geoserver.wfs3.response.CollectionsHTMLResponse">
<constructor-arg ref="resourceLoader"/>
<constructor-arg ref="geoServer"/>
</bean>
<bean id="collectionResponse" class="org.geoserver.wfs3.response.CollectionDocumentResponse"> <bean id="collectionResponse" class="org.geoserver.wfs3.response.CollectionDocumentResponse">
<constructor-arg ref="geoServer"/> <constructor-arg ref="geoServer"/>
</bean> </bean>
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,40 @@
<#setting locale="en_US">
<html>
<head>
<link rel="stylesheet" href="${baseURL}wfs3css/blueprint/screen.css" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="${baseURL}wfs3css/blueprint/print.css" type="text/css" media="print" />
<link rel="stylesheet" href="${baseURL}wfs3css/geoserver.css" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="${baseURL}wfs3css/blueprint/ie.css" type="text/css" media="screen, projection" />
</head>
<body>
<div id="header">
<a href="${baseURL}"></a>
</div>
<div id="content">
<h2>GeoServer WFS3 collections</h2>
<p>This document lists all the collections available in the WFS 3 service.<br/>
This document is also available as <#list model.getLinksExcept(null, "text/html") as link><a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>.</p>

<#list model.collections as collection>
<a id="html_${collection.name}_link" href="${collection.getLinkUrl('items', 'text/html')!}&limit=${service.maxNumberOfFeaturesForPreview}"><h4>${collection.name}</h4></a>
<p>
<#if collection.title??>
<span id="${collection.name}_title">${collection.title}</span><br/>
</#if>
<#if collection.description??>
<span id="${collection.name}_description">${collection.description!}</span><br/>
</#if>
<#assign se = collection.extent.spatial>
Geographic extents: ${se.getMinX()}, ${se.getMinY()}, ${se.getMaxX()}, ${se.getMaxY()}.<br/>
Collection items are also available in the following formats:
<select onchange="window.open(this.options[this.selectedIndex].value + '&limit=${service.maxNumberOfFeaturesForPreview}');this.selectedIndex=0" >
<option value="none" selected>--Please choose an option--</option>
<#list collection.getLinksExcept("items", "text/html") as link>
<option value="${link.href}">${link.type}</option>
</#list>
</select>
</ul>
</#list>
</div>
</body>
</html>
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,27 +18,21 @@
<p>This is the landing page of the WFS 3 service, providing links to the service API and its contents. <p>This is the landing page of the WFS 3 service, providing links to the service API and its contents.
<br/> <br/>
This document is also available as This document is also available as
<#list model.getLinksExcept("landingPage", "text/html") as link> <#list model.getLinksExcept("landingPage", "text/html") as link><a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>.
<a href="${link.href}">${link.type}</a><#if link_has_next>, </#if>
</#list>.
</p> </p>


<h2>API definition</h2> <h2>API definition</h2>
<p>The <a id="jsonApiLink" href="${model.getLinkUrl('api', 'application/json')!}"> API document</a> provides a machine processable description of this service API conformant to OpenAPI 3. <p>The <a id="jsonApiLink" href="${model.getLinkUrl('api', 'application/json')!}"> 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("collections", "application/json") as link> <#list model.getLinksExcept("api", "application/json") as link><a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>.
<a href="${link.href}">${link.type}</a><#if link_has_next>, </#if>
</#list>.
</p> </p>


<h2>Collections</h2> <h2>Collections</h2>
<p>The <a id="htmlCollectionsLink" href="${model.getLinkUrl('collections', 'text/html')!}"> collection page</a> provides a list of all the collections available in this service. <p>The <a id="htmlCollectionsLink" href="${model.getLinkUrl('collections', 'text/html')!}"> collection page</a> provides a list of all the collections available in this service.
<br/> <br/>
This collection page is also available as This collection page is also available as
<#list model.getLinksExcept("collections", "text/html") as link> <#list model.getLinksExcept("collections", "text/html") as link><a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>.
<a href="${link.href}">${link.type}</a><#if link_has_next>, </#if>
</#list>.
</p> </p>


<h2>Contact information</h2> <h2>Contact information</h2>
Expand Down
43 changes: 43 additions & 0 deletions src/community/wfs3/src/main/resources/wfs3css/blueprint/AUTHORS
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,43 @@
Blueprint CSS Framework Authors and Contributors
----------------------------------------------------------------

Blueprint is based on the work of many talented people. It is
through their good intentions we are allowed to use many of the
techniques found in the framework.

(However, remember that the original authors are not maintaing
the framework, so please don't waste their or your time on
asking them for help or support.)


Original CSS authors
----------------------------------------------------------------

The grid and typography is based on work by:
* Jeff Croft [jeffcroft.com]
* Nathan Borror [playgroundblues.com]
* Christian Metts [mintchaos.com]
* Wilson Miner [wilsonminer.com]

The CSS reset is based on work by:
* Eric Meyer [meyerweb.com/eric]

The Fancy Type plugin is based on work by:
* Mark Boulton [markboulton.co.uk]
* Typogrify [typogrify.googlecode.com]


Current team
----------------------------------------------------------------

Admin:
* Olav Bjorkoy [bjorkoy.com]

Contributors:
* Josh Clayton [jdclayton.com]
* Kim Joar Bekkelund [kimjoar.net]
* Glenn Rempe

Also, thanks to the many of people who have pitched in on
the development of Blueprint through our mailing list:
* groups.google.com/group/blueprintcss

0 comments on commit ee44d73

Please sign in to comment.