From a423d5994db73aba4c8b2d4e53c42ee064b02f6d Mon Sep 17 00:00:00 2001 From: fnecas Date: Wed, 15 May 2024 15:09:20 +0200 Subject: [PATCH 1/2] feat: add items type to paginable formats --- .../ogc/features/http/codec/MimeTypes.java | 14 ++++++++------ .../features/server/impl/CapabilitiesApiImpl.java | 15 +++++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypes.java b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypes.java index 9813988..f3d50aa 100644 --- a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypes.java +++ b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypes.java @@ -12,15 +12,15 @@ public enum MimeTypes { - JSON(new MimeType("application", "json"), "json", "JSON") { + JSON(new MimeType("application", "json"), "json", "JSON", true) { public @Override void addHeaders(String collectionId, HttpHeaders headers) { } }, - GeoJSON(new MimeType("application", "geo+json"), "geojson", "GeoJSON") { + GeoJSON(new MimeType("application", "geo+json"), "geojson", "GeoJSON", true) { public @Override void addHeaders(String collectionId, HttpHeaders headers) { } }, - SHAPEFILE(new MimeType("application", "x-shapefile"), "shapefile", "Esri Shapefile") { + SHAPEFILE(new MimeType("application", "x-shapefile"), "shapefile", "Esri Shapefile", false) { public @Override void addHeaders(String collectionId, HttpHeaders headers) { contentDisposition(collectionId, "shp.zip", headers); } @@ -29,13 +29,13 @@ public enum MimeTypes { return "feature".equals(itemType); } }, - CSV(new MimeType("text", "csv", StandardCharsets.UTF_8), "csv", "Comma Separated Values") { + CSV(new MimeType("text", "csv", StandardCharsets.UTF_8), "csv", "Comma Separated Values", true) { public @Override void addHeaders(String collectionId, HttpHeaders headers) { contentDisposition(collectionId, "csv", headers); } }, OOXML(new MimeType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet"), "ooxml", - "Excel 2007 / OOXML") { + "Excel 2007 / OOXML", false) { public @Override void addHeaders(String collectionId, HttpHeaders headers) { contentDisposition(collectionId, "xlsx", headers); } @@ -44,11 +44,13 @@ public enum MimeTypes { private final @Getter @NonNull MimeType mimeType; private final @Getter @NonNull String shortName; private final @Getter @NonNull String displayName; + private final @Getter @NonNull boolean paginable; - private MimeTypes(MimeType type, String shortName, String displayName) { + private MimeTypes(MimeType type, String shortName, String displayName, boolean paginable) { this.mimeType = type; this.shortName = shortName; this.displayName = displayName; + this.paginable = paginable; } public static Optional find(@NonNull MimeType contentType) { diff --git a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/CapabilitiesApiImpl.java b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/CapabilitiesApiImpl.java index cfd7e50..dc3102a 100644 --- a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/CapabilitiesApiImpl.java +++ b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/CapabilitiesApiImpl.java @@ -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; @@ -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()).filter(MimeTypes::isPaginable).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())) { @@ -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); From e7b328fe6042c8055b7cca35bfb671cebbbfe35f Mon Sep 17 00:00:00 2001 From: fnecas Date: Thu, 16 May 2024 14:53:36 +0200 Subject: [PATCH 2/2] feat: remove paginable and add items type to all Mimetypes --- .../ogc/features/http/codec/MimeTypes.java | 14 ++++++-------- .../features/server/impl/CapabilitiesApiImpl.java | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypes.java b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypes.java index f3d50aa..9813988 100644 --- a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypes.java +++ b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypes.java @@ -12,15 +12,15 @@ public enum MimeTypes { - JSON(new MimeType("application", "json"), "json", "JSON", true) { + JSON(new MimeType("application", "json"), "json", "JSON") { public @Override void addHeaders(String collectionId, HttpHeaders headers) { } }, - GeoJSON(new MimeType("application", "geo+json"), "geojson", "GeoJSON", true) { + GeoJSON(new MimeType("application", "geo+json"), "geojson", "GeoJSON") { public @Override void addHeaders(String collectionId, HttpHeaders headers) { } }, - SHAPEFILE(new MimeType("application", "x-shapefile"), "shapefile", "Esri Shapefile", false) { + SHAPEFILE(new MimeType("application", "x-shapefile"), "shapefile", "Esri Shapefile") { public @Override void addHeaders(String collectionId, HttpHeaders headers) { contentDisposition(collectionId, "shp.zip", headers); } @@ -29,13 +29,13 @@ public enum MimeTypes { return "feature".equals(itemType); } }, - CSV(new MimeType("text", "csv", StandardCharsets.UTF_8), "csv", "Comma Separated Values", true) { + CSV(new MimeType("text", "csv", StandardCharsets.UTF_8), "csv", "Comma Separated Values") { public @Override void addHeaders(String collectionId, HttpHeaders headers) { contentDisposition(collectionId, "csv", headers); } }, OOXML(new MimeType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet"), "ooxml", - "Excel 2007 / OOXML", false) { + "Excel 2007 / OOXML") { public @Override void addHeaders(String collectionId, HttpHeaders headers) { contentDisposition(collectionId, "xlsx", headers); } @@ -44,13 +44,11 @@ public enum MimeTypes { private final @Getter @NonNull MimeType mimeType; private final @Getter @NonNull String shortName; private final @Getter @NonNull String displayName; - private final @Getter @NonNull boolean paginable; - private MimeTypes(MimeType type, String shortName, String displayName, boolean paginable) { + private MimeTypes(MimeType type, String shortName, String displayName) { this.mimeType = type; this.shortName = shortName; this.displayName = displayName; - this.paginable = paginable; } public static Optional find(@NonNull MimeType contentType) { diff --git a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/CapabilitiesApiImpl.java b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/CapabilitiesApiImpl.java index dc3102a..d36bb3a 100644 --- a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/CapabilitiesApiImpl.java +++ b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/CapabilitiesApiImpl.java @@ -118,7 +118,7 @@ private Collection addLinks(Collection collection, String baseUrl) { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(baseUrl); builder.pathSegment("items"); - Arrays.stream(MimeTypes.values()).filter(MimeTypes::isPaginable).forEach(m -> { + Arrays.stream(MimeTypes.values()).forEach(m -> { if (m.supportsItemType(collection.getItemType())) { collection.addLinksItem(createItem(builder, m, collection.getId())); }