Skip to content

Commit

Permalink
Issue #66: Add Enterprise and Community tags on connectors
Browse files Browse the repository at this point in the history
* Added programatically `Enterprise` or `Community` tags on all connectors.
* Added `Enterprise` and `Community` tags pages.
* Tested the changes on both MetricsHub community and Enterprise Docs.
  • Loading branch information
CherfaElyes committed Oct 31, 2024
1 parent 5857d1b commit fe222b3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private Map<String, Map<String, JsonNode>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 33 in src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Extra separation in import group before 'java.util.ArrayList'

Check failure on line 33 in src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck

Unused import - java.util.ArrayList.

Check notice on line 33 in src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java

View workflow job for this annotation

GitHub Actions / PMD

Code Style UnnecessaryImport

Unused import 'java.util.ArrayList'
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -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.
* <p>
* 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.
* </p>
*
* @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<String> getTags() {
public List<String> 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<String> 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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe222b3

Please sign in to comment.