From 597d0c7fc7d34d728c7fed58901b0a1be0281dda Mon Sep 17 00:00:00 2001 From: Olivier Levitt Date: Wed, 16 Oct 2024 13:32:12 +0200 Subject: [PATCH] Only return latest version --- .../api/configuration/CustomObjectMapper.java | 6 +++++- .../onyxia/model/catalog/CatalogWrapper.java | 21 +++++++++++++++++++ .../fr/insee/onyxia/model/catalog/Pkg.java | 2 -- .../fr/insee/onyxia/model/views/Views.java | 12 +++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 onyxia-model/src/main/java/fr/insee/onyxia/model/views/Views.java diff --git a/onyxia-api/src/main/java/fr/insee/onyxia/api/configuration/CustomObjectMapper.java b/onyxia-api/src/main/java/fr/insee/onyxia/api/configuration/CustomObjectMapper.java index 4168cc3b..6a50bd17 100644 --- a/onyxia-api/src/main/java/fr/insee/onyxia/api/configuration/CustomObjectMapper.java +++ b/onyxia-api/src/main/java/fr/insee/onyxia/api/configuration/CustomObjectMapper.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import fr.insee.onyxia.model.views.Views; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -27,7 +28,10 @@ public ObjectMapper objectMapper() { mapper.enable(ALLOW_TRAILING_COMMA); mapper.enable(ALLOW_SINGLE_QUOTES); - return mapper.build(); + ObjectMapper returnMapper = mapper.build(); + returnMapper.setConfig(returnMapper.getSerializationConfig().withView(Views.General.class)); + + return returnMapper; } @Bean(name = "helm") diff --git a/onyxia-model/src/main/java/fr/insee/onyxia/model/catalog/CatalogWrapper.java b/onyxia-model/src/main/java/fr/insee/onyxia/model/catalog/CatalogWrapper.java index 5d599296..a2d0b2a0 100644 --- a/onyxia-model/src/main/java/fr/insee/onyxia/model/catalog/CatalogWrapper.java +++ b/onyxia-model/src/main/java/fr/insee/onyxia/model/catalog/CatalogWrapper.java @@ -1,7 +1,11 @@ package fr.insee.onyxia.model.catalog; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; import fr.insee.onyxia.model.helm.Chart; +import fr.insee.onyxia.model.views.Views; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -10,6 +14,7 @@ public abstract class CatalogWrapper { @Schema(description = "This entries are those from a standard helm repository") + @JsonView(Views.Full.class) private Map> entries = Map.of(); public Optional getPackageByName(String name) { @@ -32,10 +37,26 @@ public Optional getPackageByNameAndVersion(String name, String version) { /** * @return the packages */ + @JsonView(Views.Full.class) public Map> getEntries() { return entries; } + @JsonProperty("latestPackages") + public Map getLatestPackages() { + if (entries == null || entries.isEmpty()) { + return null; + } + final Map latestCharts = new HashMap<>(); + entries.forEach( + (key, value) -> { + if (value != null && !value.isEmpty()) { + latestCharts.put(key, value.get(0)); + } + }); + return latestCharts; + } + /** * @param entries the packages to set */ diff --git a/onyxia-model/src/main/java/fr/insee/onyxia/model/catalog/Pkg.java b/onyxia-model/src/main/java/fr/insee/onyxia/model/catalog/Pkg.java index b8f7e6a5..d1a9d7f6 100644 --- a/onyxia-model/src/main/java/fr/insee/onyxia/model/catalog/Pkg.java +++ b/onyxia-model/src/main/java/fr/insee/onyxia/model/catalog/Pkg.java @@ -1,6 +1,5 @@ package fr.insee.onyxia.model.catalog; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.JsonNode; import io.swagger.v3.oas.annotations.media.Schema; @@ -16,7 +15,6 @@ public class Pkg { private String version; @Schema(description = "") - @JsonIgnore private JsonNode config; public String getName() { diff --git a/onyxia-model/src/main/java/fr/insee/onyxia/model/views/Views.java b/onyxia-model/src/main/java/fr/insee/onyxia/model/views/Views.java new file mode 100644 index 00000000..39b82a36 --- /dev/null +++ b/onyxia-model/src/main/java/fr/insee/onyxia/model/views/Views.java @@ -0,0 +1,12 @@ +package fr.insee.onyxia.model.views; + +public class Views { + + // A general view for all fields except deep-nested charts + public static class General {} + + // A specific view to include only the first chart in the nested structure + public static class FirstChartOnly extends General {} + + public static class Full extends General {} +}