Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ public String buildDocId(Map<String, Object> data) {
data.put(AssetDocumentFields.LEGACY_ACCOUNT_ID,
data.get(AssetDocumentFields.ACCOUNT_ID));
}
var docId = STR."\{dataSource}_\{type}_\{StringHelper.concatenate(data, docIdFields,
"_")}";
var concatenatedId = StringHelper.concatenate(data, docIdFields, "_");
var docId = "azure".equalsIgnoreCase(dataSource)
? concatenatedId
: STR."\{dataSource}_\{type}_\{concatenatedId}";
Comment on lines +141 to +144

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify Java version supports template strings (21+)
if [ -f "pom.xml" ]; then
  echo "=== Java version in pom.xml ==="
  rg -n '<java.version>|<maven.compiler.source>|<maven.compiler.target>' pom.xml
fi

if [ -f "build.gradle" ]; then
  echo "=== Java version in build.gradle ==="
  rg -n 'sourceCompatibility|targetCompatibility' build.gradle
fi

# Search for code that might construct or parse Azure docIds with prefix
echo -e "\n=== Searching for azure docId construction patterns ==="
rg -nP --type=java 'azure.*_.*_' -C2

# Search for migration logic or docId format changes
echo -e "\n=== Searching for docId migration or format handling ==="
rg -nP --type=java 'docId.*azure|azure.*docId' -C2 | head -50

Repository: PaladinCloud/ce-extensions

Length of output: 1049


🏁 Script executed:

#!/bin/bash

# Find pom.xml files in the repository
echo "=== Locating pom.xml files ==="
fd -n "pom.xml" | head -20

# Look for build.gradle
echo -e "\n=== Locating build.gradle files ==="
fd -n "build.gradle" | head -20

Repository: PaladinCloud/ce-extensions

Length of output: 618


🏁 Script executed:

#!/bin/bash

# Once we find pom.xml, check the Java version in the relevant pom.xml
if [ -f "assets-management/services/svc-asset-delta-engine/pom.xml" ]; then
  echo "=== Java version in svc-asset-delta-engine pom.xml ==="
  cat assets-management/services/svc-asset-delta-engine/pom.xml | grep -A2 -B2 "java.version\|maven.compiler"
fi

# Also check parent pom if exists
if [ -f "assets-management/pom.xml" ]; then
  echo -e "\n=== Java version in assets-management pom.xml ==="
  cat assets-management/pom.xml | grep -A2 -B2 "java.version\|maven.compiler"
fi

if [ -f "pom.xml" ]; then
  echo -e "\n=== Java version in root pom.xml ==="
  cat pom.xml | grep -A2 -B2 "java.version\|maven.compiler"
fi

Repository: PaladinCloud/ce-extensions

Length of output: 693


🏁 Script executed:

#!/bin/bash

# Get the full context of the buildDocId method to understand the breaking change
echo "=== Full buildDocId method context ==="
cat -n assets-management/services/svc-asset-delta-engine/src/main/java/com/paladincloud/common/assets/AssetDocumentHelper.java | sed -n '120,160p'

Repository: PaladinCloud/ce-extensions

Length of output: 2085


🏁 Script executed:

#!/bin/bash

# Search for tests that validate docId generation
echo "=== Searching for docId tests ==="
fd -n "Test\.java$|Tests\.java$" assets-management/services/svc-asset-delta-engine | xargs -I {} bash -c 'grep -l "docId\|buildDocId" "{}" 2>/dev/null && echo "Found in: {}"' | head -10

Repository: PaladinCloud/ce-extensions

Length of output: 353


🏁 Script executed:

#!/bin/bash

# Search for any references to the docId format or Azure docId handling elsewhere in the codebase
echo "=== Searching for docId format documentation or comments ==="
rg -nP --type=java 'docId|buildDocId' assets-management/services/svc-asset-delta-engine/src | head -30

Repository: PaladinCloud/ce-extensions

Length of output: 5665


Confirm the intentional Azure docId format change and verify data migration.

The Java 21 template string syntax is valid and correctly supported. However, the change introduces a breaking format for Azure docIds: from azure_type_resourceid to just resourceid. This affects existing documents stored in Elasticsearch and downstream lookups.

Verify that:

  • This format change is intentional and documented
  • Existing Azure documents are migrated or no longer queried by the old format
  • Any systems that depend on the azure_ prefix for Azure docIds are updated accordingly
🧰 Tools
🪛 PMD (7.24.0)

[High] 144-144: Parse Error: LexException: Lexical error in file 'assets-management/services/svc-asset-delta-engine/src/main/java/com/paladincloud/common/assets/AssetDocumentHelper.java' at line 144, column 25: "{" (123), after : ""\" (in lexical state DEFAULT)

(Parse Error)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@assets-management/services/svc-asset-delta-engine/src/main/java/com/paladincloud/common/assets/AssetDocumentHelper.java`
around lines 141 - 144, The change to docId generation causes Azure entries to
lose the "azure_{type}_" prefix because docId is set to concatenatedId when
dataSource equals "azure"; confirm whether this was intentional and either
revert to the prior Azure format or add explicit migration/compatibility
handling: update the docId assignment in AssetDocumentHelper (variables:
concatenatedId, docId, dataSource, type, and the StringHelper.concatenate call)
so Azure follows the expected "azure_{type}_{concatenatedId}" pattern OR
implement a dual-lookup/migration path that maps old (prefixed) IDs to new ones,
plus update documentation and tests that assert Azure docId semantics.

if (StringUtils.isBlank(docId)) {
LOGGER.info(
STR."docId is not valid: '\{docId}' docIdFields=\{docIdFields} mapper data=\{MapHelper.toJsonString(
Expand Down Expand Up @@ -216,6 +218,9 @@ private void populateNewPrimary(Map<String, Object> data, AssetDTO dto, String i
if ("gcp".equalsIgnoreCase(dataSource)) {
addLegacyTags(data, dto);
}
else if ("azure".equalsIgnoreCase(dataSource)) {
addFlattenedTags(data, dto);
}

if ("azure".equalsIgnoreCase(dataSource)) {
dto.setAssetIdDisplayName(getAssetIdDisplayName(data));
Expand Down Expand Up @@ -343,10 +348,13 @@ private void updatePrimary(Map<String, Object> data, AssetDTO dto, String idValu
}

addTags(data, dto);
if ("gcp".equalsIgnoreCase(
data.getOrDefault(AssetDocumentFields.LEGACY_SOURCE, "").toString())) {
var legacySource = data.getOrDefault(AssetDocumentFields.LEGACY_SOURCE, "").toString();
if ("gcp".equalsIgnoreCase(legacySource)){
addLegacyTags(data, dto);
}
else if ("azure".equalsIgnoreCase(legacySource)) {
addFlattenedTags(data, dto);
}

// Transfer additional mapper provided fields that aren't already set
data.forEach((key, value) -> {
Expand Down Expand Up @@ -518,6 +526,16 @@ private void addLegacyTags(Map<String, Object> data, AssetDTO dto) {
}
}

private void addFlattenedTags(Map<String, Object> data, AssetDTO dto) {
var tagData = data.get(AssetDocumentFields.TAGS);
if (tagData instanceof Map) {
@SuppressWarnings("unchecked") var tagMap = (Map<String, Object>) tagData;
tagMap.forEach((key, value) -> {
dto.addType(STR."\{AssetDocumentFields.asTag(key)}", value);
});
}
}

private void addTags(Map<String, Object> data, AssetDTO dto) {
var tagData = data.get(AssetDocumentFields.TAGS);
if (tagData instanceof Map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,50 @@ private String getSamplePrimaryAssetDocument() {
}
""".trim();
}
private String getAzureLoadBalancerMapperDocument() {
return """
{
"id": "subscriptions/f4d319d8/resourceGroups/unused-resource/providers/Microsoft.Network/loadBalancers/Demo-Resource",
"name": "Demo-Resource",
"region": "eastus",
"source": "azure",
"source_display_name": "Azure",
"_cloudType": "azure",
"_entityType": "loadbalancer",
"_entityTypeDisplayName": "Load Balancer",
"subscriptionId": "f4d319d8",
"rawData": "{}",
"reporting_source": "azure",
"tags": {}
}""".trim();
}

@Test
void azureDocIdHasNoPrefix() throws JsonProcessingException {
var helper = AssetDocumentHelper.builder()
.loadDate(ZonedDateTime.now())
.idField("id")
.docIdFields(List.of("id"))
.dataSource("azure")
.displayName("Load Balancer")
.tags(List.of())
.type("loadbalancer")
.accountIdToNameFn((_) -> null)
.build();
var mapperData = JsonHelper.mapFromString(getAzureLoadBalancerMapperDocument());
var dto = helper.createFrom(mapperData);

assertEquals(
"subscriptions/f4d319d8/resourceGroups/unused-resource/providers/Microsoft.Network/loadBalancers/Demo-Resource",
dto.getDocId());
}

@Test
void gcpDocIdHasPrefix() throws JsonProcessingException {
AssetDocumentHelper helper = getHelper("gcp", "resource_id", "resource_name");
var mapperData = JsonHelper.mapFromString(getV2PrimaryMapperDocument());
var dto = helper.createFrom(mapperData);

assertEquals("gcp_ec2_us-central_17", dto.getDocId());
}
}
Loading