Skip to content

Commit

Permalink
Only return latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
olevitt committed Oct 16, 2024
1 parent 6cbbe57 commit 597d0c7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, List<Chart>> entries = Map.of();

public Optional<Chart> getPackageByName(String name) {
Expand All @@ -32,10 +37,26 @@ public Optional<Chart> getPackageByNameAndVersion(String name, String version) {
/**
* @return the packages
*/
@JsonView(Views.Full.class)
public Map<String, List<Chart>> getEntries() {
return entries;
}

@JsonProperty("latestPackages")
public Map<String, Chart> getLatestPackages() {
if (entries == null || entries.isEmpty()) {
return null;
}
final Map<String, Chart> 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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,7 +15,6 @@ public class Pkg {
private String version;

@Schema(description = "")
@JsonIgnore
private JsonNode config;

public String getName() {
Expand Down
12 changes: 12 additions & 0 deletions onyxia-model/src/main/java/fr/insee/onyxia/model/views/Views.java
Original file line number Diff line number Diff line change
@@ -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 {}
}

0 comments on commit 597d0c7

Please sign in to comment.