Skip to content

Commit

Permalink
Merge pull request #27 from georchestra/add-items-to-paginable-formats
Browse files Browse the repository at this point in the history
Add items type to paginable formats
  • Loading branch information
f-necas authored May 20, 2024
2 parents e3f854f + e7b328f commit fabbcfb
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.camptocamp.opendata.ogc.features.server.impl;

import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import com.camptocamp.opendata.ogc.features.model.*;
import com.camptocamp.opendata.ogc.features.model.Collection;
Expand Down Expand Up @@ -117,10 +118,11 @@ private Collection addLinks(Collection collection, String baseUrl) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(baseUrl);
builder.pathSegment("items");

MimeTypes defFormat = MimeTypes.GeoJSON;
UriComponents itemsc = builder.replaceQueryParam("f", defFormat.getShortName()).build();
Link items = link(itemsc.toString(), "items", defFormat.getMimeType().toString(), collection.getId());
collection.addLinksItem(items);
Arrays.stream(MimeTypes.values()).forEach(m -> {
if (m.supportsItemType(collection.getItemType())) {
collection.addLinksItem(createItem(builder, m, collection.getId()));
}
});

Arrays.stream(MimeTypes.values()).forEach(m -> {
if (m.supportsItemType(collection.getItemType())) {
Expand All @@ -135,6 +137,11 @@ private Collection addLinks(Collection collection, String baseUrl) {
return collection;
}

private Link createItem(UriComponentsBuilder builder, MimeTypes defFormat, String collectionId) {
UriComponents itemsc = builder.replaceQueryParam("f", defFormat.getShortName()).build();
return link(itemsc.toString(), "items", defFormat.getMimeType().toString(), collectionId);
}

private Link link(String href, String rel, String type, String title) {
Link link = new Link(href);
link.setRel(rel);
Expand Down

0 comments on commit fabbcfb

Please sign in to comment.