Skip to content

Commit

Permalink
Merge pull request #23958 from aloubyansky/category-metadata
Browse files Browse the repository at this point in the history
Serialize extension category metadata under 'metadata'
  • Loading branch information
aloubyansky committed Feb 25, 2022
2 parents 944a746 + 22c27b2 commit baa2410
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.quarkus.registry.json.JsonBuilder;
import io.quarkus.registry.json.JsonEntityWithAnySupport;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

Expand All @@ -18,17 +18,18 @@
* @see JsonBuilder.JsonBuilderSerializer for building a builder before serializing it.
*/
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class CategoryImpl extends JsonEntityWithAnySupport implements Category {
public class CategoryImpl implements Category {

private final String id;
private final String name;
private final String description;
private final Map<String, Object> metadata;

private CategoryImpl(Builder builder) {
super(builder);
this.id = builder.id;
this.name = builder.name;
this.description = builder.description;
this.metadata = JsonBuilder.toUnmodifiableMap(builder.metadata);
}

@Override
Expand All @@ -46,6 +47,11 @@ public String getDescription() {
return description;
}

@Override
public Map<String, Object> getMetadata() {
return metadata;
}

@Override
public boolean equals(Object o) {
return categoryEquals(this, o);
Expand All @@ -64,10 +70,11 @@ public String toString() {
/**
* Builder.
*/
public static class Builder extends JsonEntityWithAnySupport.Builder implements Category.Mutable {
public static class Builder implements Category.Mutable {
protected String id;
protected String name;
protected String description;
protected Map<String, Object> metadata;

Builder() {
}
Expand All @@ -77,7 +84,7 @@ public static class Builder extends JsonEntityWithAnySupport.Builder implements
this.id = config.getId();
this.name = config.getName();
this.description = config.getDescription();
super.setMetadata(config.getMetadata());
this.metadata = config.getMetadata();
}

@Override
Expand Down Expand Up @@ -111,20 +118,25 @@ public Builder setDescription(String description) {
}

@Override
public Builder setMetadata(Map<String, Object> metadata) {
super.setMetadata(metadata);
public Map<String, Object> getMetadata() {
return metadata == null ? metadata = new HashMap<>() : metadata;
}

@Override
public Builder setMetadata(Map<String, Object> newValues) {
metadata = JsonBuilder.modifiableMapOrNull(newValues, HashMap::new);
return this;
}

@Override
public Builder setMetadata(String name, Object value) {
super.setMetadata(name, value);
getMetadata().put(name, value);
return this;
}

@Override
public Builder removeMetadata(String key) {
super.removeMetadata(key);
getMetadata().remove(key);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* @see JsonBuilder.JsonBuilderSerializer for building a builder before serializing it.
*/
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonPropertyOrder({ "id", "platform", "bom", "quarkus-core-version", "extensions", "categories", "metadata" })
@JsonPropertyOrder({ "id", "platform", "bom", "quarkus-core-version", "upstream-quarkus-core-version", "extensions",
"categories", "metadata" })
public class ExtensionCatalogImpl extends ExtensionOriginImpl implements ExtensionCatalog {

private final String quarkusCoreVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"id" : "web",
"name" : "Web",
"description" : "Category description",
"pinned" : [ "blue", "green", "yellow" ]
"metadata" : {
"pinned" : [ "blue", "green", "yellow" ]
}
} ],
"metadata" : {
"project" : {
Expand Down

0 comments on commit baa2410

Please sign in to comment.