From d559ad391e038de3d00d82f8da525193d0bbce84 Mon Sep 17 00:00:00 2001 From: Eric Wittmann Date: Sat, 19 Sep 2020 20:52:19 -0400 Subject: [PATCH] Added a NONE option to the Compatibility level config + Return labels/properties in version meta-data (#857) * added a NONE option to the Compatibility level config. Fixes #820 * Return labels and properties in version meta-data. Fixes #820 * Return labels and properties in version meta-data. Fixes #832 --- .../compatibility/CompatibilityLevel.java | 3 +- .../storage/ArtifactVersionMetaDataDto.java | 33 +++++++++++++++++++ .../registry/storage/MetaDataKeys.java | 25 +++++++++++--- .../io/apicurio/registry/util/DtoUtil.java | 6 ++++ .../io/apicurio/registry/util/SearchUtil.java | 1 + .../registry/ArtifactsResourceTest.java | 19 +++++++++-- .../apicurio/registry/RulesResourceTest.java | 29 ++++++++++++++++ .../registry/rest/beans/VersionMetaData.java | 17 +++++++++- 8 files changed, 124 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/apicurio/registry/rules/compatibility/CompatibilityLevel.java b/app/src/main/java/io/apicurio/registry/rules/compatibility/CompatibilityLevel.java index 7056c2d93e..7e3e826b25 100644 --- a/app/src/main/java/io/apicurio/registry/rules/compatibility/CompatibilityLevel.java +++ b/app/src/main/java/io/apicurio/registry/rules/compatibility/CompatibilityLevel.java @@ -25,5 +25,6 @@ public enum CompatibilityLevel { FORWARD, FORWARD_TRANSITIVE, FULL, - FULL_TRANSITIVE + FULL_TRANSITIVE, + NONE } diff --git a/app/src/main/java/io/apicurio/registry/storage/ArtifactVersionMetaDataDto.java b/app/src/main/java/io/apicurio/registry/storage/ArtifactVersionMetaDataDto.java index 2cdde3f294..6f02928fd2 100644 --- a/app/src/main/java/io/apicurio/registry/storage/ArtifactVersionMetaDataDto.java +++ b/app/src/main/java/io/apicurio/registry/storage/ArtifactVersionMetaDataDto.java @@ -16,6 +16,9 @@ package io.apicurio.registry.storage; +import java.util.List; +import java.util.Map; + import io.apicurio.registry.types.ArtifactState; import io.apicurio.registry.types.ArtifactType; import lombok.AllArgsConstructor; @@ -40,6 +43,8 @@ public class ArtifactVersionMetaDataDto { private long createdOn; private ArtifactType type; private ArtifactState state; + private List labels; + private Map properties; /** * Constructor. @@ -158,4 +163,32 @@ public int getVersion() { public void setVersion(int version) { this.version = version; } + + /** + * @return the labels + */ + public List getLabels() { + return labels; + } + + /** + * @param labels the labels to set + */ + public void setLabels(List labels) { + this.labels = labels; + } + + /** + * @return the user-defined properties + */ + public Map getProperties() { + return properties; + } + + /** + * @param properties the user-defined properties to set + */ + public void setProperties(Map properties) { + this.properties = properties; + } } diff --git a/app/src/main/java/io/apicurio/registry/storage/MetaDataKeys.java b/app/src/main/java/io/apicurio/registry/storage/MetaDataKeys.java index 3c0946963c..d0b5a5b3d6 100644 --- a/app/src/main/java/io/apicurio/registry/storage/MetaDataKeys.java +++ b/app/src/main/java/io/apicurio/registry/storage/MetaDataKeys.java @@ -17,14 +17,15 @@ package io.apicurio.registry.storage; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.apicurio.registry.types.ArtifactType; - import java.util.Arrays; import java.util.Base64; import java.util.Map; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.apicurio.registry.types.ArtifactType; + /** * @author Ales Justin */ @@ -47,9 +48,12 @@ public class MetaDataKeys { // Internal public static String DELETED = "_deleted"; + + private static final ObjectMapper MAPPER = new ObjectMapper(); // Helpers + @SuppressWarnings("unchecked") public static ArtifactMetaDataDto toArtifactMetaData(Map content) { ArtifactMetaDataDto dto = new ArtifactMetaDataDto(); @@ -77,7 +81,7 @@ public static ArtifactMetaDataDto toArtifactMetaData(Map content } if (content.get(PROPERTIES) != null) { try { - dto.setProperties(new ObjectMapper().readValue(content.get(PROPERTIES), Map.class)); + dto.setProperties(MAPPER.readValue(content.get(PROPERTIES), Map.class)); } catch (JsonProcessingException e) { // If the user-defined properties cannot be parsed from a Json string to a Map, ignore them } @@ -85,6 +89,7 @@ public static ArtifactMetaDataDto toArtifactMetaData(Map content return dto; } + @SuppressWarnings("unchecked") public static ArtifactVersionMetaDataDto toArtifactVersionMetaData(Map content) { ArtifactVersionMetaDataDto dto = new ArtifactVersionMetaDataDto(); String createdOn = content.get(CREATED_ON); @@ -98,6 +103,16 @@ public static ArtifactVersionMetaDataDto toArtifactVersionMetaData(Map, ignore them + } + } return dto; } diff --git a/app/src/main/java/io/apicurio/registry/util/DtoUtil.java b/app/src/main/java/io/apicurio/registry/util/DtoUtil.java index d88ad6bb5c..634d7976bd 100644 --- a/app/src/main/java/io/apicurio/registry/util/DtoUtil.java +++ b/app/src/main/java/io/apicurio/registry/util/DtoUtil.java @@ -82,6 +82,8 @@ public static final VersionMetaData dtoToVersionMetaData(String artifactId, Arti metaData.setVersion(dto.getVersion()); metaData.setGlobalId(dto.getGlobalId()); metaData.setState(dto.getState()); + metaData.setLabels(dto.getLabels()); + metaData.setProperties(dto.getProperties()); return metaData; } @@ -104,6 +106,8 @@ public static final VersionMetaData dtoToVersionMetaData(String artifactId, Arti metaData.setVersion(amd.getVersion()); metaData.setGlobalId(amd.getGlobalId()); metaData.setState(amd.getState()); + metaData.setLabels(amd.getLabels()); + metaData.setProperties(amd.getProperties()); return metaData; } @@ -126,6 +130,8 @@ public static final VersionMetaData dtoToVersionMetaData(String artifactId, Arti metaData.setVersion(dto.getVersion()); metaData.setGlobalId(dto.getGlobalId()); metaData.setState(dto.getState()); + metaData.setLabels(dto.getLabels()); + metaData.setProperties(dto.getProperties()); return metaData; } diff --git a/app/src/main/java/io/apicurio/registry/util/SearchUtil.java b/app/src/main/java/io/apicurio/registry/util/SearchUtil.java index cac3f653c8..b3fb4ea89f 100644 --- a/app/src/main/java/io/apicurio/registry/util/SearchUtil.java +++ b/app/src/main/java/io/apicurio/registry/util/SearchUtil.java @@ -73,6 +73,7 @@ public static SearchedVersion buildSearchedVersion(ArtifactVersionMetaDataDto ar searchedVersion.setState(artifactVersionMetaData.getState()); searchedVersion.setType(artifactVersionMetaData.getType()); searchedVersion.setVersion(artifactVersionMetaData.getVersion()); + searchedVersion.setLabels(artifactVersionMetaData.getLabels()); return searchedVersion; } diff --git a/app/src/test/java/io/apicurio/registry/ArtifactsResourceTest.java b/app/src/test/java/io/apicurio/registry/ArtifactsResourceTest.java index 6f92ca1ec8..3ff80d8bfc 100644 --- a/app/src/test/java/io/apicurio/registry/ArtifactsResourceTest.java +++ b/app/src/test/java/io/apicurio/registry/ArtifactsResourceTest.java @@ -730,7 +730,7 @@ public void testArtifactMetaData() throws Exception { Map expectedProperties = new HashMap<>(); expectedProperties.put("additionalProp1", "Empty API additional property"); - given() + int version = given() .when() .pathParam("artifactId", "testGetArtifactMetaData/EmptyAPI") .get("/artifacts/{artifactId}/meta") @@ -741,7 +741,22 @@ public void testArtifactMetaData() throws Exception { .body("name", equalTo("Empty API Name")) .body("description", equalTo("Empty API description.")) .body("labels", equalToObject(expectedLabels)) - .body("properties", equalToObject(expectedProperties)); + .body("properties", equalToObject(expectedProperties)) + .extract().body().path("version"); + + // Make sure the version specific meta-data also returns all the custom meta-data + given() + .when() + .pathParam("artifactId", "testGetArtifactMetaData/EmptyAPI") + .pathParam("version", version) + .get("/artifacts/{artifactId}/versions/{version}/meta") + .then() + .statusCode(200) + .body("name", equalTo("Empty API Name")) + .body("description", equalTo("Empty API description.")) + .body("labels", equalToObject(expectedLabels)) + .body("properties", equalToObject(expectedProperties)) + .extract().body().path("version"); }); // Update the artifact content and then make sure the name/description meta-data is still available diff --git a/app/src/test/java/io/apicurio/registry/RulesResourceTest.java b/app/src/test/java/io/apicurio/registry/RulesResourceTest.java index 44bc473547..ce56768b2f 100644 --- a/app/src/test/java/io/apicurio/registry/RulesResourceTest.java +++ b/app/src/test/java/io/apicurio/registry/RulesResourceTest.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test; import io.apicurio.registry.rest.beans.Rule; +import io.apicurio.registry.rules.compatibility.CompatibilityLevel; import io.apicurio.registry.types.ArtifactType; import io.apicurio.registry.types.RuleType; import io.apicurio.registry.utils.tests.TestUtils; @@ -269,5 +270,33 @@ public void testDeleteAllGlobalRules() throws Exception { .body("message", equalTo("No rule named 'VALIDITY' was found.")); }); } + + @Test + public void testCompatilibityLevelNone() throws Exception { + // Add a global rule + Rule rule = new Rule(); + rule.setType(RuleType.COMPATIBILITY); + rule.setConfig(CompatibilityLevel.NONE.name()); + given() + .when() + .contentType(CT_JSON) + .body(rule) + .post("/rules") + .then() + .statusCode(204) + .body(anything()); + + // Get a single rule by name + TestUtils.retry(() -> { + given() + .when() + .get("/rules/COMPATIBILITY") + .then() + .statusCode(200) + .contentType(ContentType.JSON) + .body("type", equalTo("COMPATIBILITY")) + .body("config", equalTo("NONE")); + }); + } } diff --git a/common/src/main/java/io/apicurio/registry/rest/beans/VersionMetaData.java b/common/src/main/java/io/apicurio/registry/rest/beans/VersionMetaData.java index 6d332ebed7..5e2b026112 100644 --- a/common/src/main/java/io/apicurio/registry/rest/beans/VersionMetaData.java +++ b/common/src/main/java/io/apicurio/registry/rest/beans/VersionMetaData.java @@ -2,6 +2,7 @@ package io.apicurio.registry.rest.beans; import java.util.List; +import java.util.Map; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -28,7 +29,8 @@ "type", "globalId", "state", - "id" + "id", + "properties" }) public class VersionMetaData { @@ -45,6 +47,9 @@ public class VersionMetaData { private String description; @JsonProperty("labels") private List labels; + @JsonProperty("properties") + private Map properties; + /** * * (Required) @@ -277,4 +282,14 @@ public void setLabels(List labels) { this.labels = labels; } + @JsonProperty("properties") + public Map getProperties() { + return properties; + } + + @JsonProperty("properties") + public void setProperties(Map properties) { + this.properties = properties; + } + }