Skip to content

Add new field "description" in attribute_metadata.proto #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ message AttributeMetadata {
string scope_string = 17;
bool internal = 18;
bool custom = 19;
string description = 20;
}

message AttributeSourceMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public class AttributeMetadataModel implements Document {

private boolean internal;

@JsonProperty(value = "description")
private String description;

protected AttributeMetadataModel() {}

public static AttributeMetadataModel fromDTO(AttributeMetadata attributeMetadata) {
Expand All @@ -97,6 +100,7 @@ public static AttributeMetadataModel fromDTO(AttributeMetadata attributeMetadata
attributeMetadataModel.setSources(attributeMetadata.getSourcesList());
attributeMetadataModel.setGroupable(attributeMetadata.getGroupable());
attributeMetadataModel.setDefinition(attributeMetadata.getDefinition());
attributeMetadataModel.setDescription(attributeMetadata.getDescription());
attributeMetadataModel.setMetadata(
attributeMetadata.getMetadataMap().entrySet().stream()
.collect(
Expand Down Expand Up @@ -148,6 +152,14 @@ public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public void setDescription(String description) {
this.description = description;
}

public String getDescription() {
return description;
}

public String getScopeString() {
return this.scopeString;
}
Expand Down Expand Up @@ -294,6 +306,9 @@ public AttributeMetadata.Builder toDTOBuilder() {
if (!definition.equals(AttributeDefinition.getDefaultInstance())) {
builder.setDefinition(definition);
}
if (description != null) {
builder.setDescription(description);
}

return builder;
}
Expand Down Expand Up @@ -349,6 +364,8 @@ public String toString() {
+ metadata
+ ", internal="
+ internal
+ ", description="
+ description
+ '}';
}

Expand Down Expand Up @@ -377,7 +394,8 @@ public boolean equals(Object o) {
&& Objects.equals(metadata, that.metadata)
&& Objects.equals(definition, that.definition)
&& Objects.equals(scopeString, that.scopeString)
&& Objects.equals(internal, that.internal);
&& Objects.equals(internal, that.internal)
&& Objects.equals(description, that.description);
}

@Override
Expand All @@ -399,7 +417,8 @@ public int hashCode() {
metadata,
definition,
scopeString,
internal);
internal,
description);
}

private static class ProtobufMessageSerializer extends JsonSerializer<Message> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void testAttributeMetadataModelJsonSerDes() throws IOException {
.setProjection(Projection.newBuilder().setAttributeId("test"))
.build());
attributeMetadataModel.setInternal(true);
attributeMetadataModel.setDescription("description");

String json = attributeMetadataModel.toJson();
String expectedJson =
Expand All @@ -60,7 +61,8 @@ public void testAttributeMetadataModelJsonSerDes() throws IOException {
+ "\"value_kind\":\"TYPE_STRING\","
+ "\"display_name\":\"Some Name\","
+ "\"scope_string\":\"EVENT\","
+ "\"tenant_id\":\"tenantId\""
+ "\"tenant_id\":\"tenantId\","
+ "\"description\":\"description\""
+ "}";
Assertions.assertEquals(expectedJson, json);
AttributeMetadataModel deserializedModel = AttributeMetadataModel.fromJson(json);
Expand All @@ -82,6 +84,7 @@ public void testAttributeMetaModelToFromDto() {
.setType(AttributeType.ATTRIBUTE)
.setUnit("ms")
.setValueKind(AttributeKind.TYPE_STRING)
.setDescription("description")
.putAllMetadata(
Collections.singletonMap(
AttributeSource.EDS.name(),
Expand Down Expand Up @@ -236,6 +239,7 @@ public void testAttributeDefinitionBackwardsCompatibility() throws IOException {
.setType(AttributeType.ATTRIBUTE)
.setUnit("ms")
.setValueKind(AttributeKind.TYPE_STRING)
.setDescription("Description")
.build());

String expectedJson =
Expand All @@ -256,11 +260,78 @@ public void testAttributeDefinitionBackwardsCompatibility() throws IOException {
+ "\"value_kind\":\"TYPE_STRING\","
+ "\"display_name\":\"Display\","
+ "\"scope_string\":\"EVENT\","
+ "\"tenant_id\":null"
+ "\"tenant_id\":null,"
+ "\"description\":\"Description\""
+ "}";
Assertions.assertEquals(expectedJson, modelFromMetadataWithoutDefinition.toJson());
}

@Test
public void testAttributeDescriptionBackwardsCompatibility() throws IOException {
String json =
"{"
+ "\"fqn\":\"fqn\","
+ "\"key\":\"key\","
+ "\"scope\":\"EVENT\","
+ "\"materialized\":true,"
+ "\"unit\":\"ms\","
+ "\"type\":\"ATTRIBUTE\","
+ "\"labels\":[\"item1\"],"
+ "\"groupable\":true,"
+ "\"supportedAggregations\":[],"
+ "\"onlyAggregationsAllowed\":false,"
+ "\"sources\":[],"
+ "\"definition\":{},"
+ "\"id\":\"EVENT.key\","
+ "\"value_kind\":\"TYPE_BOOL\","
+ "\"display_name\":\"Some Name\","
+ "\"tenant_id\":\"tenantId\""
+ "}";

AttributeMetadataModel deserializedModel = AttributeMetadataModel.fromJson(json);
Assertions.assertNull(deserializedModel.getDescription());
AttributeMetadata metadata = deserializedModel.toDTO();
Assertions.assertEquals("", metadata.getDescription());

AttributeMetadataModel modelFromMetadataWithoutDescription =
AttributeMetadataModel.fromDTO(
AttributeMetadata.newBuilder()
.setFqn("fqn")
.setId("id")
.setKey("key")
.setDisplayName("Display")
.setMaterialized(true)
.setScope(AttributeScope.EVENT)
.setDescription(AttributeDefinition.getDefaultInstance().toString())
.setType(AttributeType.ATTRIBUTE)
.setUnit("ms")
.setValueKind(AttributeKind.TYPE_STRING)
.build());

String expectedJson =
"{"
+ "\"fqn\":\"fqn\","
+ "\"key\":\"key\","
+ "\"materialized\":true,"
+ "\"unit\":\"ms\","
+ "\"type\":\"ATTRIBUTE\","
+ "\"labels\":[],"
+ "\"groupable\":false,"
+ "\"supportedAggregations\":[],"
+ "\"onlyAggregationsAllowed\":false,"
+ "\"sources\":[],"
+ "\"definition\":{},"
+ "\"internal\":false,"
+ "\"id\":\"EVENT.key\","
+ "\"value_kind\":\"TYPE_STRING\","
+ "\"display_name\":\"Display\","
+ "\"scope_string\":\"EVENT\","
+ "\"tenant_id\":null,"
+ "\"description\":\"\""
+ "}";
Assertions.assertEquals(expectedJson, modelFromMetadataWithoutDescription.toJson());
}

@Test
void testScopeStringCompatibility() throws IOException {
final AttributeMetadata template =
Expand Down
Loading