Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuring additional links for collections #93

Merged
merged 3 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions deegree-ogcapi-documentation/src/main/asciidoc/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ The next example shows a complete configuration for a dataset called "trees" wit
<MetadataURL format="text/html">http://example.metadata.org/path_to_html/1234</MetadataURL> <!--11-->
</Metadata>

<ConfigureCollection id="SimpleFeature"> <!--12-->
<AddLink href="https://inspire.ec.europa.eu/featureconcept/XXX" rel="tag" type="text/html" title="Feature concept XXX"/>
</ConfigureCollection>

<ConfigureCollections> <!--13-->
<AddLink href="https://github.com/INSPIRE-MIF/XXX" rel="describedby" type="text/html" title="Encoding description"/>
</ConfigureCollections>


</deegreeOAF>
----
<1> identifier of the feature store configuration, links to file _datasources/feature/trees.xml_
Expand All @@ -208,6 +217,8 @@ The next example shows a complete configuration for a dataset called "trees" wit
<9> dataset provider contact details
<10> metadata link in format `application/xml` for the dataset (optional)
<11> metadata link in format `text/html` for the dataset (optional)
<12> configure additional links for an individual collection. In the example, an additional link to the INSPIRE feature concept for the collection is provided (optional) (required by INSPIRE)
<13> configure additional links for all collections. In the example, an additional link to the alternative encoding description for collections is provided (optional) (recommended by INSPIRE)

NOTE: The dataset configuration file must be stored in the subdirectory _ogcapi/_. The file is mandatory.

Expand All @@ -221,6 +232,8 @@ This configuration file can contain the following elements:
|DateTimeProperties |0..1 |Complex |Configuration of date and time properties, see http://docs.opengeospatial.org/is/17-069r3/17-069r3.html#_parameter_datetime[parameter datetime in the OGC API specification] for more information
|HtmlViewId |0..1 |String |Identifier of the HTML encoding configuration, see <<config_htmlview>> for more information
|Metadata |0..1 |Complex |Configuration of the dataset metadata provided on the dataset's landing page
|ConfigureCollection |0..1 |Complex |Custom configuration for an individual collection
|ConfigureCollections |0..1 |Complex |Custom configuration for all collections
|===

The element ```<DateTimeProperties/>``` can contain multiple elements of ```<DateTimeProperty/>``` which has the following subelements:
Expand All @@ -243,8 +256,26 @@ The element ```<Metadata/>``` has the following subelements:
|MetadataURL |0..n |URL |URL of the metadata record describing the dataset, use the attribute `format` to link HTML or XML representation. Use this link to a metadata record when you have a metadata record describing all containing feature collections. Otherwise use the element `<Dataset>` as described in the next chapter <<config_metadata>>.
|===

The element ```<ConfigureCollection/>``` has the following subelement:

[width="100%",cols="25%,15%,20%,40%",options="header",]
|===
|Option |Cardinality |Value |Description
|AddLink |0..1 |Complex | URL of additional link
|===

The element ```<ConfigureCollections/>``` has the following subelement:

[width="100%",cols="25%,15%,20%,40%",options="header",]
|===
|Option |Cardinality |Value |Description
|AddLink |0..1 |Complex | URL of additional link
|===

The elements ```<ProviderLicense/>``` and ```<DatasetLicense/>``` can have either a ```<Name/>``` and ```<Description/>``` element or a ```<Name/>``` and ```<URL/>``` element. The ```<URL/>``` can have an optional attribute `format` specifying the media type such as `application/xml` (default is `text/html`). Same applies to the element ```<MetadataURL/>```.

The ```<AddLink/>``` elements in ```<ConfigureCollection/>``` and ```<ConfigureCollections/>``` have ```href```, ```rel```, ```type``` and ```title``` parameters.

See the following section <<config_metadata>> for more configuration options for metadata.

NOTE: The content of this file is returned under the resource _/datasets/{datasetId}_. This resource per dataset is called landing page. Furthermore the content of this file is provided unter the resource _/datasets/{datasetId}/api_.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.deegree.commons.tom.primitive.BaseType;
import org.deegree.commons.tom.primitive.PrimitiveType;
import org.deegree.commons.utils.Pair;
import org.deegree.cs.coordinatesystems.ICRS;
import org.deegree.cs.exceptions.TransformationException;
import org.deegree.cs.exceptions.UnknownCRSException;
import org.deegree.cs.persistence.CRSManager;
Expand All @@ -54,6 +53,8 @@
import org.deegree.services.oaf.workspace.configuration.OafDatasetConfiguration;
import org.deegree.services.ogcapi.features.DateTimePropertyType;
import org.deegree.services.ogcapi.features.DeegreeOAF;
import org.deegree.services.ogcapi.features.DeegreeOAF.ConfigureCollection;
import org.deegree.services.ogcapi.features.DeegreeOAF.ConfigureCollections;
import org.deegree.workspace.Resource;
import org.deegree.workspace.ResourceIdentifier;
import org.deegree.workspace.ResourceInitException;
Expand Down Expand Up @@ -94,8 +95,20 @@ public class OafResource implements Resource {
private OafDatasetConfiguration oafConfiguration;

private HtmlViewConfiguration htmlViewConfiguration;

public OafResource( ResourceMetadata<Resource> metadata, Workspace workspace, DeegreeOAF config ) {

private List<ConfigureCollection> additionalCollectionList = new ArrayList<>();

private List<ConfigureCollections> additionalCollectionsList = new ArrayList<>();

public List<ConfigureCollection> getAdditionalCollectionList() {
return additionalCollectionList;
}

public List<ConfigureCollections> getAdditionalCollectionsList() {
return additionalCollectionsList;
}

public OafResource( ResourceMetadata<Resource> metadata, Workspace workspace, DeegreeOAF config ) {
this.metadata = metadata;
this.workspace = workspace;
this.config = config;
Expand All @@ -120,6 +133,11 @@ public void init() {
this.oafConfiguration = new OafDatasetConfiguration( id, featureTypeMetadata, datasetMetadata, supportedCrs,
featureStores, useExistingGMLSchema );
this.htmlViewConfiguration = getHtmlViewConfig( workspace );

this.additionalCollectionList= config.getConfigureCollection();

this.additionalCollectionsList= config.getConfigureCollections();

LOG.debug("Initialising deegree ogcapi with " + oafConfiguration + " and HTML view config " + htmlViewConfiguration);
} catch ( InvalidConfigurationException e ) {
throw new ResourceInitException( "OAF Configuration could not be parsed", e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public void setLinks( List<Link> links ) {
this.links = links;
}


public void addAdditionalLinks( List<Link> links ) {
this.links.addAll(links);
}

public String getItemType() {
return itemType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public List<Link> getLinks() {
public void setLinks( List<Link> links ) {
this.links = links;
}

public void addAdditionalLinks( List<Link> links ) {
this.links.addAll(links);
}

public List<Collection> getCollections() {
return collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
import org.deegree.services.oaf.exceptions.InvalidParameterValue;
import org.deegree.services.oaf.exceptions.UnknownCollectionId;
import org.deegree.services.oaf.exceptions.UnknownDatasetId;
import org.deegree.services.oaf.link.Link;
import org.deegree.services.oaf.link.LinkBuilder;
import org.deegree.services.oaf.workspace.DataAccess;
import org.deegree.services.oaf.workspace.DeegreeWorkspaceInitializer;
import org.deegree.services.oaf.workspace.configuration.OafDatasetConfiguration;
import org.deegree.services.ogcapi.features.AddLink;
import org.deegree.services.ogcapi.features.DeegreeOAF.ConfigureCollection;

import javax.inject.Inject;
import javax.ws.rs.GET;
Expand All @@ -57,6 +60,10 @@
import static org.deegree.services.oaf.RequestFormat.XML;
import static org.deegree.services.oaf.RequestFormat.byFormatParameter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
Expand Down Expand Up @@ -153,12 +160,33 @@ private Response collection( String datasetId, String collectionId, UriInfo uriI
}
LinkBuilder linkBuilder = new LinkBuilder( uriInfo );
Collection collection = dataAccess.createCollection( oafConfiguration, collectionId, linkBuilder );
addAdditionalCollectionLinks( datasetId, collection);

if ( XML.equals( requestFormat ) ) {
Collections collections = new Collections();
collections.addCollection( collection );
return Response.ok( collections, APPLICATION_XML ).build();
}
return Response.ok( collection, APPLICATION_JSON ).build();
}

private void addAdditionalCollectionLinks(String datasetId, Collection collection) {
Map<String,List<ConfigureCollection>> additionalCollectionMap = DeegreeWorkspaceInitializer.getAdditionalCollectionMap();

if(additionalCollectionMap.containsKey(datasetId)) {
List<ConfigureCollection> configureCollectionList = additionalCollectionMap.get(datasetId);
for(ConfigureCollection additionalcoll: configureCollectionList) {
if(additionalcoll!=null && collection.getId().equals(additionalcoll.getId())) {
List<AddLink> addLinks = additionalcoll.getAddLink();
if(addLinks!=null) {
List<Link> oafLinks = new ArrayList<>();
for(AddLink addLink: addLinks) {
oafLinks.add(new Link(addLink.getHref(), addLink.getRel(), addLink.getType(), addLink.getTitle()));
}
collection.addAdditionalLinks(oafLinks);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.deegree.services.oaf.RequestFormat;
import org.deegree.services.oaf.domain.collections.Collection;
import org.deegree.services.oaf.domain.collections.Collections;
import org.deegree.services.oaf.exceptions.InvalidParameterValue;
import org.deegree.services.oaf.exceptions.UnknownDatasetId;
import org.deegree.services.oaf.link.Link;
import org.deegree.services.oaf.link.LinkBuilder;
import org.deegree.services.oaf.workspace.DataAccess;
import org.deegree.services.oaf.workspace.DeegreeWorkspaceInitializer;
import org.deegree.services.oaf.workspace.configuration.OafDatasetConfiguration;
import org.deegree.services.ogcapi.features.AddLink;
import org.deegree.services.ogcapi.features.DeegreeOAF.ConfigureCollection;
import org.deegree.services.ogcapi.features.DeegreeOAF.ConfigureCollections;

import javax.inject.Inject;
import javax.ws.rs.GET;
Expand All @@ -55,6 +60,10 @@
import static org.deegree.services.oaf.RequestFormat.XML;
import static org.deegree.services.oaf.RequestFormat.byFormatParameter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
Expand Down Expand Up @@ -141,8 +150,51 @@ private Response collections( String datasetId, UriInfo uriInfo, String formatPa

LinkBuilder linkBuilder = new LinkBuilder( uriInfo );
Collections collections = dataAccess.createCollections( oafConfiguration, linkBuilder );
addAdditionalCollectionsLinks(datasetId,collections);
for(Collection collection: collections.getCollections()) {
addAdditionalCollectionLinks(datasetId, collection);
}

return Response.ok( collections, mediaTypeFromRequestFormat( requestFormat ) ).build();
}

private void addAdditionalCollectionsLinks(String datasetId, Collections collections) {
Map<String,List<ConfigureCollections>> additionalCollectionsMap = DeegreeWorkspaceInitializer.getAdditionalCollectionsMap();

if(additionalCollectionsMap.containsKey(datasetId)) {
List<ConfigureCollections> configureCollectionsList = additionalCollectionsMap.get(datasetId);
for(ConfigureCollections additionalcolls: configureCollectionsList) {
List<AddLink> addLinks = additionalcolls.getAddLink();
if(addLinks!=null) {
List<Link> oafLinks = new ArrayList<>();
for(AddLink addLink: addLinks) {
oafLinks.add(new Link(addLink.getHref(), addLink.getRel(), addLink.getType(), addLink.getTitle()));
}
collections.addAdditionalLinks(oafLinks);
}
}
}
}

private void addAdditionalCollectionLinks(String datasetId, Collection collection) {
Map<String,List<ConfigureCollection>> additionalCollectionMap = DeegreeWorkspaceInitializer.getAdditionalCollectionMap();

if(additionalCollectionMap.containsKey(datasetId)) {
List<ConfigureCollection> configureCollectionList = additionalCollectionMap.get(datasetId);
for(ConfigureCollection additionalcoll: configureCollectionList) {
if(additionalcoll!=null && collection.getId().equals(additionalcoll.getId())) {
List<AddLink> addLinks = additionalcoll.getAddLink();
if(addLinks!=null) {
List<Link> oafLinks = new ArrayList<>();
for(AddLink addLink: addLinks) {
oafLinks.add(new Link(addLink.getHref(), addLink.getRel(), addLink.getType(), addLink.getTitle()));
}
collection.addAdditionalLinks(oafLinks);
}
}
}
}
}

private String mediaTypeFromRequestFormat( RequestFormat requestFormat ) {
return XML.equals( requestFormat ) ? APPLICATION_XML : APPLICATION_JSON;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.deegree.services.oaf.link.LinkBuilder;
import org.deegree.services.oaf.workspace.configuration.OafDatasetConfiguration;
import org.deegree.services.oaf.workspace.configuration.OafDatasets;
import org.deegree.services.ogcapi.features.DeegreeOAF.ConfigureCollection;
import org.deegree.services.ogcapi.features.DeegreeOAF.ConfigureCollections;
import org.deegree.workspace.Resource;
import org.deegree.workspace.ResourceIdentifier;
import org.deegree.workspace.Workspace;
Expand Down Expand Up @@ -72,6 +74,10 @@ public class DeegreeWorkspaceInitializer {
private static Map<String, HtmlViewConfiguration> htmlViewConfigurations = new HashMap<>();

private static HtmlViewConfiguration globalHtmlViewConfiguration;

private static Map<String, List<ConfigureCollection>> additionalCollectionMap = new HashMap<>();

private static Map<String, List<ConfigureCollections>> additionalCollectionsMap = new HashMap<>();

public void initialize() {
DeegreeWorkspace workspace = OGCFrontController.getServiceWorkspace();
Expand Down Expand Up @@ -130,8 +136,17 @@ public Path getAppschemaFile( String path )
throw new UnknownAppschema( path );
return appschema;
}


public String createAppschemaUrl( UriInfo uriInfo, String uri ) {
public static Map<String, List<ConfigureCollection>> getAdditionalCollectionMap() {
return additionalCollectionMap;
}

public static Map<String, List<ConfigureCollections>> getAdditionalCollectionsMap() {
return additionalCollectionsMap;
}

public String createAppschemaUrl( UriInfo uriInfo, String uri ) {
Path uriPath = Paths.get( URI.create( uri ) );
if ( uriPath.startsWith( pathToAppschemas ) ) {
Path relativizeUriPath = pathToAppschemas.relativize( uriPath );
Expand Down Expand Up @@ -179,6 +194,8 @@ private void initOafDatasets( Workspace newWorkspace ) {
HtmlViewConfiguration htmlViewConfiguration = resource.getHtmlViewConfiguration();
if ( htmlViewConfiguration != null )
htmlViewConfigurations.put( id, htmlViewConfiguration );
additionalCollectionMap.put(id, resource.getAdditionalCollectionList());
additionalCollectionsMap.put(id, resource.getAdditionalCollectionsList());
} );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@
<MetadataURL format="text/html">http://localhost:8080/linkZuHTml/89362</MetadataURL>
</Metadata>

<ConfigureCollection id="River">
<AddLink href="http://inspire.ec.europa.eu/featureconcept/Building" rel="tag" type="application/json" title="Feature concept Building"/>
</ConfigureCollection>

<ConfigureCollections>
<AddLink href="http://inspire.ec.europa.eu/featureconcept/Building" rel="tag" type="application/json" title="Feature concept Building"/>
</ConfigureCollections>

</deegreeOAF>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
</element>
<element name="HtmlViewId" type="string" minOccurs="0"/>
<element name="Metadata" type="oaf:MetadataType" minOccurs="0"/>
<element name="ConfigureCollection" minOccurs="0" maxOccurs="unbounded" >
<complexType>
<sequence>
<element name="AddLink" minOccurs="0" maxOccurs="unbounded" type="oaf:AddLink"/>
</sequence>
<attribute name="id" type="string"/>
</complexType>
</element>

<element name="ConfigureCollections" minOccurs="0" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="AddLink" minOccurs="0" maxOccurs="unbounded" type="oaf:AddLink"/>
</sequence>
</complexType>
</element>

</sequence>
<attribute name="configVersion" use="required">
<simpleType>
Expand All @@ -36,6 +53,14 @@
</complexType>
</element>


<complexType name="AddLink">
<attribute name="href" type="string"/>
<attribute name="rel" type="string"/>
<attribute name="type" type="string"/>
<attribute name="title" type="string"/>
</complexType>

<complexType name="DateTimePropertyType">
<sequence>
<element name="FeatureTypeName" type="QName"/>
Expand Down Expand Up @@ -85,5 +110,4 @@
</choice>
</sequence>
</complexType>

</schema>