Skip to content

Commit

Permalink
feat: configure additional links for Collections
Browse files Browse the repository at this point in the history
Extend configuration options to add
additional links to Collections API.
  • Loading branch information
kapil-agnihotri authored and stempler committed Apr 3, 2023
1 parent caa4768 commit f7b7dc0
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
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 @@ -96,10 +97,16 @@ public class OafResource implements Resource {

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;
Expand Down Expand Up @@ -128,6 +135,8 @@ public void init() {

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 @@ -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 @@ -39,8 +39,8 @@
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.ConfigureCollection.AddLink;

import javax.inject.Inject;
import javax.ws.rs.GET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
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.ConfigureCollection.AddLink;
import org.deegree.services.ogcapi.features.DeegreeOAF.ConfigureCollections;

import javax.inject.Inject;
import javax.ws.rs.GET;
Expand Down Expand Up @@ -149,13 +150,32 @@ 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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 @@ -75,6 +76,8 @@ public class DeegreeWorkspaceInitializer {
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 @@ -138,6 +141,10 @@ public Path getAppschemaFile( String path )
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 ) );
Expand Down Expand Up @@ -188,6 +195,7 @@ private void initOafDatasets( Workspace newWorkspace ) {
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 @@ -39,4 +39,8 @@
<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 @@ -28,18 +28,20 @@
<element name="ConfigureCollection" minOccurs="0" maxOccurs="unbounded" >
<complexType>
<sequence>
<element name="AddLink" minOccurs="0" maxOccurs="unbounded">
<complexType>
<attribute name="href" type="string"/>
<attribute name="rel" type="string"/>
<attribute name="type" type="string"/>
<attribute name="title" type="string"/>
</complexType>
</element>
<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 @@ -51,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

0 comments on commit f7b7dc0

Please sign in to comment.