Skip to content

Commit

Permalink
[GEOS-10058] Dynamic GeoServer Welcome Page service capability links
Browse files Browse the repository at this point in the history
This is the subject of GSIP-202:

* Introduce ServiceDescriptionProvider as a replacement for CapabilitiesHomePageProvider
* GeoServerHomePage allows the selection of worksapce and layer / layer group to determine service capability links displayed
* Contact Information panel allows for configuration of welcome, online resource, address delivery point
* GeoServerHomePage description updates dynmicly to reflect global service or virtual services being shown
* Contact information (welcome, organization name, online resource) used to create welcome blurb at top of page
* Contact information (email address) used to show contact administrator in page footer
  • Loading branch information
jodygarnett committed Sep 27, 2022
1 parent 5c42623 commit 6bd4864
Show file tree
Hide file tree
Showing 63 changed files with 3,016 additions and 503 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* (c) 2022 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.wps.web;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.PublishedInfo;
import org.geoserver.catalog.WorkspaceInfo;
import org.geoserver.config.GeoServer;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.platform.Service;
import org.geoserver.web.ServiceDescription;
import org.geoserver.web.ServiceDescriptionProvider;
import org.geoserver.web.ServiceLinkDescription;
import org.geoserver.wps.WPSInfo;
import org.geoserver.wps.WebProcessingService;
import org.geotools.util.logging.Logging;

/** Provide description of WPS services for welcome page. */
public class WPSServiceDescriptionProvider extends ServiceDescriptionProvider {

static final Logger LOGGER = Logging.getLogger(WPSServiceDescriptionProvider.class);

GeoServer geoserver;
Catalog catalog;

public WPSServiceDescriptionProvider(GeoServer gs) {
this.geoserver = gs;
catalog = gs.getCatalog();
}

/**
* Lookup WPSInfo using workspaceInfo / layerInfo context.
*
* @param workspaceInfo Workspace, or null for global.
* @param layerInfo Layer, LayerGroup, or null for any
* @return WPSInfo if available for workspace, or global WPSInfo.
*/
protected WPSInfo info(WorkspaceInfo workspaceInfo, PublishedInfo layerInfo) {
WPSInfo info = null;
if (workspaceInfo != null) {
info = geoserver.getService(workspaceInfo, WPSInfo.class);
}
if (info == null) {
info = geoserver.getService(WPSInfo.class);
}
return info;
}

@Override
public List<ServiceDescription> getServices(
WorkspaceInfo workspaceInfo, PublishedInfo layerInfo) {

List<ServiceDescription> descriptions = new ArrayList<>();
WPSInfo info = info(workspaceInfo, layerInfo);

if (workspaceInfo != null || geoserver.getGlobal().isGlobalServices()) {
descriptions.add(description(info, workspaceInfo, layerInfo));
}
return descriptions;
}

@Override
public List<ServiceLinkDescription> getServiceLinks(
WorkspaceInfo workspaceInfo, PublishedInfo layerInfo) {
List<ServiceLinkDescription> links = new ArrayList<>();

if (workspaceInfo == null && !geoserver.getGlobal().isGlobalServices()) {
return links;
}

List<Service> extensions = GeoServerExtensions.extensions(Service.class);

for (Service service : extensions) {
if (service.getService() instanceof WebProcessingService) {
String serviceId = service.getId();

String link = null;
if (service.getOperations().contains("GetCapabilities")) {
link = getCapabilitiesURL(workspaceInfo, layerInfo, service);
} else if (service.getCustomCapabilitiesLink() != null) {
link = service.getCustomCapabilitiesLink();
}

if (link != null) {
links.add(
new ServiceLinkDescription(
serviceId.toLowerCase(),
service.getVersion(),
link,
workspaceInfo != null ? workspaceInfo.getName() : null,
layerInfo != null ? layerInfo.getName() : null));
}
}
}
return links;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<constructor-arg index="0" value="gs-web-wps"/>
<constructor-arg index="1" value="GeoServer Web UI Web Processing Service"/>
</bean>
<bean id="wpsServiceDescriptor" class="org.geoserver.wps.web.WPSServiceDescriptionProvider">
</bean>
<bean id="wpsRequestBuilder" class="org.geoserver.web.DemoLinkInfo">
<property name="id" value="wpsRequestBuilder" />
<property name="titleKey" value="WPSRequestBuilder.title" />
Expand Down
31 changes: 28 additions & 3 deletions src/main/src/main/java/org/geoserver/config/ContactInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ public interface ContactInfo extends Info {
/** @uml.property name="addressCountry" */
void setAddressCountry(String addressCountry);

/** @uml.property name="addressDeliveryPoint" */
/**
* Synonym with {@code address}, see {@link #getAddress()}.
*
* @uml.property name="addressDeliveryPoint"
*/
String getAddressDeliveryPoint();

/** @uml.property name="addressDeliveryPoint" */
/**
* Synonym with {@code address}, see {@link #setAddress(String)}}.
*
* @uml.property name="addressDeliveryPoint"
*/
void setAddressDeliveryPoint(String addressDeliveryPoint);

/** @uml.property name="addressPostalCode" */
Expand Down Expand Up @@ -101,8 +109,21 @@ public interface ContactInfo extends Info {

void setOnlineResource(String onlineResource);

// i18n fields
/**
* Introduction message.
*
* @return introduction message
*/
String getWelcome();

/**
* Define introduction message
*
* @param welcome Introduction message
*/
void setWelcome(String welcome);

// i18n fields
/** @uml.property name="internationalAddress" */
InternationalString getInternationalAddress();

Expand Down Expand Up @@ -184,4 +205,8 @@ public interface ContactInfo extends Info {
InternationalString getInternationalOnlineResource();

void setInternationalOnlineResource(InternationalString onlineResource);

InternationalString getInternationalWelcome();

void setInternationalWelcome(InternationalString onlineResource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class ContactInfoImpl implements ContactInfo {

private String onlineResource;

private String welcome;

private InternationalString internationalAddress;

private InternationalString internationalAddressCity;
Expand Down Expand Up @@ -69,6 +71,8 @@ public class ContactInfoImpl implements ContactInfo {

private InternationalString internationalOnlineResource;

private InternationalString internationalWelcome;

@Override
public String getId() {
return id;
Expand Down Expand Up @@ -222,6 +226,16 @@ public void setOnlineResource(String onlineResource) {
this.onlineResource = onlineResource;
}

@Override
public String getWelcome() {
return InternationalStringUtils.getOrDefault(welcome, internationalWelcome);
}

@Override
public void setWelcome(String welcome) {
this.welcome = welcome;
}

@Override
public InternationalString getInternationalAddress() {
return internationalAddress;
Expand Down Expand Up @@ -300,6 +314,16 @@ public void setInternationalOnlineResource(InternationalString internationalOnli
InternationalStringUtils.growable(internationalOnlineResource);
}

@Override
public InternationalString getInternationalWelcome() {
return internationalWelcome;
}

@Override
public void setInternationalWelcome(InternationalString internationalWelcome) {
this.internationalWelcome = InternationalStringUtils.growable(internationalWelcome);
}

@Override
public InternationalString getInternationalAddressCity() {
return internationalAddressCity;
Expand Down Expand Up @@ -468,6 +492,11 @@ public int hashCode() {
+ ((internationalAddressDeliveryPoint == null)
? 0
: internationalAddressDeliveryPoint.hashCode());

result =
PRIME * result
+ ((internationalWelcome == null) ? 0 : internationalWelcome.hashCode());

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
* Dispatcher callback that sets and clears the {@link LocalWorkspace} and {@link LocalPublished}
* thread locals.
*
* <p>This class is responsible for parsing request context information ({@code workspace/ows?},
* {@code layergroup/wms?}, {@code workspace/layer}) and resolving the intended local workspace,
* layer group, and/or layer information which are stored in a thread locale for reference.
*
* <p>The logic used here is duplicated by GeoServerHomePage which provides a user interface
* reflecting this context lookup process.
*
* @author Justin Deoliveira, OpenGeo
*/
public class LocalWorkspaceCallback implements DispatcherCallback, ExtensionPriority {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class Service {
String customCapabilitiesLink;

/**
* Creates a new service descriptor.
* Creates a new global (no workspace) service descriptor.
*
* @param id A string identifing the service.
* @param service The object implementing the service.
Expand All @@ -53,7 +53,7 @@ public Service(String id, Object service, Version version, List<String> operatio
* Creates a new service descriptor.
*
* @param id A string identifying the service.
* @param namespace The namespace of the service, may be <code>null</code>
* @param namespace The namespace of the service, may be <code>null</code> for global.
* @param service The object implementing the service.
* @param version The version of the service.
* @param operations The list of operations the service provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ public void testGetGlobalAsJSON() throws Exception {
JSONObject contact = settings.getJSONObject("contact");
assertNotNull(contact);
assertEquals("Andrea Aime", contact.get("contactPerson"));
assertEquals("https://www.osgeo.org", contact.get("onlineResource"));

assertEquals("UTF-8", settings.get("charset"));
assertEquals("8", settings.get("numDecimals").toString().trim());
assertEquals("http://geoserver.org", settings.get("onlineResource"));
assertEquals("https://geoserver.org", settings.get("onlineResource"));

JSONObject jaiInfo = global.getJSONObject("jai");
assertNotNull(jaiInfo);
Expand All @@ -203,8 +204,10 @@ public void testGetGlobalAsXML() throws Exception {
assertEquals("global", dom.getDocumentElement().getLocalName());
assertXpathEvaluatesTo("UTF-8", "/global/settings/charset", dom);
assertXpathEvaluatesTo("8", "/global/settings/numDecimals", dom);
assertXpathEvaluatesTo("http://geoserver.org", "/global/settings/onlineResource", dom);
assertXpathEvaluatesTo("https://geoserver.org", "/global/settings/onlineResource", dom);
assertXpathEvaluatesTo("Andrea Aime", "/global/settings/contact/contactPerson", dom);
assertXpathEvaluatesTo(
"https://www.osgeo.org", "/global/settings/contact/onlineResource", dom);
assertXpathEvaluatesTo("false", "/global/jai/allowInterpolation", dom);
assertXpathEvaluatesTo("0.75", "/global/jai/memoryThreshold", dom);
assertXpathEvaluatesTo("UNBOUNDED", "/global/coverageAccess/queueType", dom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</p>
<ul style="margin-left: 2em;">
<li>
<a href="http://docs.geoserver.org"><wicket:message key="documentation">Documentation</wicket:message></a>
<a href="https://docs.geoserver.org"><wicket:message key="documentation">Documentation</wicket:message></a>
</li>
<li>
<a href="https://github.com/geoserver/geoserver/wiki"><wicket:message key="wiki">Wiki</wicket:message></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public interface CapabilitiesHomePageLinkProvider {

/**
* Returns a component to be added as a child of the home page {@link ListView} that contains
* the list of GetCapabilities links.
* the list of Services and Protocols (such as GetCapabilities links).
*
* @param id the id of the returned component
* @return a component suitable to be contained by the home page list of getcapabilities links
* @return a component suitable to be contained by the home page list of getcapabilities links,
* or {@code null} if not available.
*/
public Component getCapabilitiesComponent(final String id);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<html xmlns:wicket="http://wicket.apache.org/">
<body>
<wicket:panel>
<li wicket:id="services">
<span wicket:id="service"></span>
<ul class="flat">
<li wicket:id="versions">
<a wicket:id="link" class="external icon">
<span wicket:id="version">
</span></a>
</li>
</ul>
</li>
<div wicket:id="services">
<a wicket:id="link">
<div class="link-bordered">
<span wicket:id="service" class="serviceProtocol"></span>
<hr>
<span wicket:id="version" class="serviceVersion"></span>
</div>
</a>
<div class="spacer"></div>
</div>
</wicket:panel>
</body>
</html>
Loading

0 comments on commit 6bd4864

Please sign in to comment.