Skip to content

Commit

Permalink
Added a NONE option to the Compatibility level config + Return labels…
Browse files Browse the repository at this point in the history
…/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
  • Loading branch information
EricWittmann authored Sep 20, 2020
1 parent 8cebce0 commit d559ad3
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public enum CompatibilityLevel {
FORWARD,
FORWARD_TRANSITIVE,
FULL,
FULL_TRANSITIVE
FULL_TRANSITIVE,
NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +43,8 @@ public class ArtifactVersionMetaDataDto {
private long createdOn;
private ArtifactType type;
private ArtifactState state;
private List<String> labels;
private Map<String, String> properties;

/**
* Constructor.
Expand Down Expand Up @@ -158,4 +163,32 @@ public int getVersion() {
public void setVersion(int version) {
this.version = version;
}

/**
* @return the labels
*/
public List<String> getLabels() {
return labels;
}

/**
* @param labels the labels to set
*/
public void setLabels(List<String> labels) {
this.labels = labels;
}

/**
* @return the user-defined properties
*/
public Map<String, String> getProperties() {
return properties;
}

/**
* @param properties the user-defined properties to set
*/
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
}
25 changes: 20 additions & 5 deletions app/src/main/java/io/apicurio/registry/storage/MetaDataKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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<String, String> content) {
ArtifactMetaDataDto dto = new ArtifactMetaDataDto();

Expand Down Expand Up @@ -77,14 +81,15 @@ public static ArtifactMetaDataDto toArtifactMetaData(Map<String, String> 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<String, String>, ignore them
}
}
return dto;
}

@SuppressWarnings("unchecked")
public static ArtifactVersionMetaDataDto toArtifactVersionMetaData(Map<String, String> content) {
ArtifactVersionMetaDataDto dto = new ArtifactVersionMetaDataDto();
String createdOn = content.get(CREATED_ON);
Expand All @@ -98,6 +103,16 @@ public static ArtifactVersionMetaDataDto toArtifactVersionMetaData(Map<String, S
dto.setVersion(Integer.parseInt(content.get(VERSION)));
dto.setGlobalId(Long.parseLong(content.get(GLOBAL_ID)));
dto.setState(ArtifactStateExt.getState(content));
if (content.get(LABELS) != null) {
dto.setLabels(Arrays.asList(content.get(LABELS).split(",")));
}
if (content.get(PROPERTIES) != null) {
try {
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<String, String>, ignore them
}
}
return dto;
}

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/io/apicurio/registry/util/DtoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 17 additions & 2 deletions app/src/test/java/io/apicurio/registry/ArtifactsResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ public void testArtifactMetaData() throws Exception {
Map<String, String> expectedProperties = new HashMap<>();
expectedProperties.put("additionalProp1", "Empty API additional property");

given()
int version = given()
.when()
.pathParam("artifactId", "testGetArtifactMetaData/EmptyAPI")
.get("/artifacts/{artifactId}/meta")
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions app/src/test/java/io/apicurio/registry/RulesResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,8 @@
"type",
"globalId",
"state",
"id"
"id",
"properties"
})
public class VersionMetaData {

Expand All @@ -45,6 +47,9 @@ public class VersionMetaData {
private String description;
@JsonProperty("labels")
private List<String> labels;
@JsonProperty("properties")
private Map<String, String> properties;

/**
*
* (Required)
Expand Down Expand Up @@ -277,4 +282,14 @@ public void setLabels(List<String> labels) {
this.labels = labels;
}

@JsonProperty("properties")
public Map<String, String> getProperties() {
return properties;
}

@JsonProperty("properties")
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}

}

0 comments on commit d559ad3

Please sign in to comment.