diff --git a/.github/workflows/codeQl.yaml b/.github/workflows/codeQl.yaml index 78a5dc93e..ddf31fb89 100644 --- a/.github/workflows/codeQl.yaml +++ b/.github/workflows/codeQl.yaml @@ -47,7 +47,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -62,7 +62,7 @@ jobs: # If this step fails, then you should remove it and run the build manually (see below) - if: matrix.language == 'python' || matrix.language == 'javascript' name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 - if: matrix.language == 'java' name: Build Java @@ -81,4 +81,4 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/util/AssetGroupUtil.java b/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/util/AssetGroupUtil.java index 7b8fc5366..eed52e8e3 100644 --- a/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/util/AssetGroupUtil.java +++ b/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/util/AssetGroupUtil.java @@ -15,10 +15,9 @@ ******************************************************************************/ package com.tmobile.cso.pacman.datashipper.util; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.*; import com.tmobile.cso.pacman.datashipper.dao.RDSDBManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,7 +65,7 @@ public static List> fetchTypeCounts(String ag) throws Except String url = ASSET_SVC_BASE_URL + "/count?ag=" + ag; String typeCountJson = HttpUtil.get(url, AuthManager.getToken()); Map typeCountMap = Util.parseJson(typeCountJson); - return (List>) ((Map) typeCountMap.get("data")).get("assetcount"); + return (List>) ((Map) typeCountMap.get("data")).get("assetcount"); } /** @@ -317,65 +316,29 @@ public static String fetchAssetCount(String platform, String accountId) throws E } public static List> fetchTaggingSummaryForAssetGroup(String ag) throws Exception { - List> issueInfoList = new ArrayList<>(); + List> resultList = new ArrayList<>(); try { - - String distributionResponse = LambdaInvoker.invokeTaggingSummaryLambda(ag); - if (distributionResponse == null || distributionResponse.isEmpty()) { + String response = LambdaInvoker.invokeTaggingSummaryLambda(ag); + if (response == null || response.isEmpty()) { LOGGER.warn("Empty response from tagging summary API for ag: {}", ag); - return issueInfoList; - } - JsonObject distributionJson = JsonParser.parseString(distributionResponse).getAsJsonObject(); - JsonObject dataObj = distributionJson.getAsJsonObject("data"); - if (dataObj == null || dataObj.isJsonNull()) { - LOGGER.warn("No data found in tagging summary response for ag: {}", ag); - return issueInfoList; + return resultList; } - Map summaryInfo = new HashMap<>(); - summaryInfo.put("totalAssets", dataObj.get("totalAssets").getAsLong()); - summaryInfo.put("overallCompliancePercentage", dataObj.get("overallCompliancePercentage").getAsDouble()); - summaryInfo.put("overallTaggedCount", dataObj.get("overallTaggedCount").getAsLong()); - summaryInfo.put("overallAssetCount", dataObj.get("overallAssetCount").getAsLong()); - summaryInfo.put("description", dataObj.get("description").getAsString()); - - JsonArray assetTypesArray = dataObj.getAsJsonArray("assetTypes"); - List> assetTypesList = new ArrayList<>(); - - for (int i = 0; i < assetTypesArray.size(); i++) { - JsonObject assetTypeObj = assetTypesArray.get(i).getAsJsonObject(); - - Map assetTypeInfo = new HashMap<>(); - assetTypeInfo.put("targetType", assetTypeObj.get("targetType").getAsString()); - assetTypeInfo.put("displayName", assetTypeObj.get("displayName").getAsString()); - assetTypeInfo.put("assetCount", assetTypeObj.get("assetCount").getAsLong()); - assetTypeInfo.put("taggedCount", assetTypeObj.get("taggedCount").getAsLong()); - assetTypeInfo.put("untaggedCount", assetTypeObj.get("untaggedCount").getAsLong()); - assetTypeInfo.put("compliancePercentage", assetTypeObj.get("compliancePercentage").getAsDouble()); - - JsonArray tagDetailsArray = assetTypeObj.getAsJsonArray("tagDetails"); - List> tagDetailsList = new ArrayList<>(); - - for (int j = 0; j < tagDetailsArray.size(); j++) { - JsonObject tagDetailObj = tagDetailsArray.get(j).getAsJsonObject(); - - Map tagInfo = new HashMap<>(); - tagInfo.put("tagName", tagDetailObj.get("tagName").getAsString()); - tagInfo.put("count", tagDetailObj.get("count").getAsLong()); - tagInfo.put("tagCompliancePercentage", tagDetailObj.get("tagCompliancePercentage").getAsDouble()); - - tagDetailsList.add(tagInfo); - } + TaggingSummaryResponse summaryResponse = new Gson().fromJson(response, + TaggingSummaryResponse.class); - assetTypeInfo.put("tagDetails", tagDetailsList); - assetTypesList.add(assetTypeInfo); + if (summaryResponse.data == null) { + LOGGER.warn("No data found in tagging summary response for ag: {}", ag); + return resultList; } - summaryInfo.put("assetTypes", assetTypesList); - issueInfoList.add(summaryInfo); + ObjectMapper mapper = new ObjectMapper(); + Map summaryInfo = mapper.convertValue( + summaryResponse.data, new TypeReference>() { + }); + resultList.add(summaryInfo); } catch (Exception e) { - LOGGER.error("Error retrieving tagging summary data", e); - throw e; + LOGGER.error("Error retrieving tagging summary data for ag: {}", ag, e); } - return issueInfoList; + return resultList; } } diff --git a/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/util/TaggingSummaryResponse.java b/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/util/TaggingSummaryResponse.java new file mode 100644 index 000000000..360fd80de --- /dev/null +++ b/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/util/TaggingSummaryResponse.java @@ -0,0 +1,48 @@ +package com.tmobile.cso.pacman.datashipper.util; + +import java.util.List; + +public class TaggingSummaryResponse { + + public Data data; + + public static class Data { + public String ag; + public int totalAssets; + public double overallCompliancePercentage; + public int overallTaggedCount; + public int overallAssetCount; + public String description; + public List assetgroups; + } + + public static class AssetGroupEntry { + public String ag; + public Stats stats; + } + + public static class Stats { + public int totalAssets; + public double overallCompliancePercentage; + public int overallTaggedCount; + public int overallAssetCount; + public String description; + public List assetTypes; + } + + public static class AssetType { + public String targetType; + public String displayName; + public int assetCount; + public int taggedCount; + public int untaggedCount; + public double compliancePercentage; + public List tagDetails; + } + + public static class TagDetail { + public String tagName; + public int count; + public double tagCompliancePercentage; + } +} \ No newline at end of file