diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/ConnectorsDirectoryReport.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/ConnectorsDirectoryReport.java index fdbc71a..c251be5 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/ConnectorsDirectoryReport.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/ConnectorsDirectoryReport.java @@ -235,7 +235,7 @@ private Map> determineTags() { final JsonNode connector = connectorEntry.getValue(); final ConnectorJsonNodeReader reader = new ConnectorJsonNodeReader(connector); return reader - .getTags() + .getAndCompleteTags(enterpriseConnectorIds.contains(connectorEntry.getKey())) .stream() .filter(tag -> !tag.isBlank()) .map(tag -> new AbstractMap.SimpleEntry<>(tag, connectorEntry)); diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java index a7afc8d..5b0555f 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java @@ -27,6 +27,10 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -601,19 +605,40 @@ private JsonNode getMapping(final JsonNode job) { } /** - * Retrieves a list of tags from the detection JSON node. + * Retrieves and adds a specified tag to the detection JSON node's "tags" list. + *

+ * Adds either "enterprise" or "community" to the "tags" field based on the {@code isEnterprise} parameter. + * If the "tags" field is absent or null, it initializes a new array with the specified tag. + *

* - * @return a list of tags as strings, or an empty list if no tags are found. + * @param isEnterprise {@code true} to add "enterprise" to the tags; {@code false} to add "community". + * @return a list of tags as strings, including the added tag, or an empty list if the detection node is null. */ - public List getTags() { + public List getAndCompleteTags(final boolean isEnterprise) { JsonNode detection = getDetection(); if (nonNull(detection)) { final JsonNode tagsNode = detection.get("tags"); // NOSONAR nonNull() is already called - return nodeToStringList(tagsNode); + final ArrayNode tagsArrayNode = tagsNode != null && !tagsNode.isNull() ? (ArrayNode) tagsNode : JsonNodeFactory.instance.arrayNode(); + + tagsArrayNode.add(isEnterprise ? "enterprise" : "community"); + + ((ObjectNode) detection).set("tags", tagsArrayNode); + return nodeToStringList(tagsArrayNode); } return Collections.emptyList(); } + /** + * Retrieves a list of tags from the detection JSON node. + * + * @return a list of tags as strings, or an empty list if no tags are found. + */ + public List getTags() { + JsonNode detection = getDetection(); + return nonNull(detection) ? nodeToStringList(detection.get("tags")) // NOSONAR nonNull() is already called + : Collections.emptyList(); + } + /** * Retrieves all variable names from the connector template. * Variables are expected to be in the format: ${var::variableName}. diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java index 2fad27c..2b6b48a 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java @@ -106,10 +106,6 @@ public void produce( sink.section1(); sink.sectionTitle1(); sink.text(displayName); - // If the connector is Enterprise - if (enterpriseConnectorIds.contains(connectorId)) { - sink.rawText(SinkHelper.bootstrapLabel("Enterprise", "metricshub-enterprise-label")); - } sink.sectionTitle1_(); // Description