Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed overall tagging count and individual tag count #935

Merged
merged 2 commits into from
Mar 17, 2023
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 @@ -1164,7 +1164,7 @@ public List<Map<String, Object>> getListAssetsTaggable(String assetGroup, Map<St

String[] tags = mandatoryTags.split(",");
for (String tag : tags) {
shouldFilter.put(CommonUtils.convertAttributetoKeyword(tag.trim()), AssetConstants.TAG_NOT_FOUND);
shouldFilter.put(CommonUtils.convertAttributetoKeyword(tag.replaceAll("\\s", "")), AssetConstants.TAG_NOT_FOUND);
}
List<Map<String, Object>> untaggedAssets;
List<Map<String, Object>> totalAssets;
Expand Down Expand Up @@ -1245,7 +1245,9 @@ public List<Map<String, Object>> getListAssetsTaggable(String assetGroup, Map<St
assetDetails = getAssetsByAssetGroup(assetGroup, targetType, new HashMap(), null, fieldNames);
}
} else {

ruleIdWithTargetTypeQuery = "SELECT DISTINCT p.targetType FROM cf_PolicyTable p WHERE p.status = 'ENABLED' AND p.category = 'tagging'";

ruleIdwithTargetType = rdsRepository.getDataFromPacman(ruleIdWithTargetTypeQuery);
List<String> validTypes = ruleIdwithTargetType.stream()
.map(obj -> obj.get(Constants.TARGET_TYPE).toString()).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public Map<String, Long> getTagging(String assetGroup, String targetType) throws
AssetCount assetCount;
AssetCountByAppEnvDTO[] assetcountCount;
StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/").append(assetGroup).append("/")
.append(UNDERSCORE_COUNT);
.append(SEARCH);
StringBuilder requestBody = null;
List<String> tagsList = new ArrayList<>(Arrays.asList(mandatoryTags.split(",")));

Expand All @@ -507,17 +507,20 @@ public Map<String, Long> getTagging(String assetGroup, String targetType) throws
}
body = body.substring(0, body.length() - 1);
body = body + "]";
body = body + ",\"minimum_should_match\":1";
body = body + ",\"minimum_should_match\":1}}";
body = body + ",\"aggs\":{\"distinct_resourceids\":{\"cardinality\":{\"field\":\"_resourceid.keyword\"}}}";
}
body = body + "}}}";
body = body + "}";
requestBody = new StringBuilder(body);
try {
responseDetails = PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString());
} catch (Exception e) {
throw new DataException(e);
}
JsonObject responseJson = parser.parse(responseDetails).getAsJsonObject();
totaluntagged = responseJson.get(COUNT).getAsLong();
JsonObject aggs = responseJson.get(AGGREGATIONS).getAsJsonObject();
JsonObject resourceids = aggs.get("distinct_resourceids").getAsJsonObject();
totaluntagged = resourceids.get("value").getAsLong();
policyIdWithTargetTypeQuery = "SELECT p.targetType FROM cf_PolicyTable p WHERE p.status = 'ENABLED' AND p.category = '"+Constants.CATEGORY_TAGGING+"'";
policyIdwithTargetType = rdsepository.getDataFromPacman(policyIdWithTargetTypeQuery);
if (Strings.isNullOrEmpty(targetType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public Long getUntaggedIssues(String assetGroup, String mandatoryTag)
mandatoryTagsList.add(mandatoryTag);
}
mustFilter.put(CommonUtils.convertAttributetoKeyword(TYPE), ISSUE);
mustFilter.put(CommonUtils.convertAttributetoKeyword(Constants.POLICY_CATEGORY),CATEGORY_TAGGING);
// @ToDo
// mustFilter.put(CommonUtils.convertAttributetoKeyword(POLICYID),
// TAGGING_POLICY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1632,8 +1632,10 @@ public long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, Str
Map<String, Object> mustTermsFilter,
Map<String, List<String>> matchPhrasePrefix) throws Exception {

String urlToQuery = buildCountURL(esUrl, index, type);

String urlToQuery = buildESURL(esUrl, index, type,0,0);
JsonParser parser = new JsonParser();
JsonObject aggregationObject = new JsonObject();
long totaluntagged = 0;
Map<String, Object> requestBody = new HashMap<String, Object>();
Map<String, Object> matchFilters = Maps.newHashMap();
if (mustFilter == null) {
Expand All @@ -1649,15 +1651,20 @@ public long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, Str
} else {
requestBody.put(QUERY, matchFilters);
}
StringBuilder aggregationQuery = new StringBuilder("{\"distinct_resourceids\": {\"cardinality\": {\"field\": \"_resourceid.keyword\"}}}");
aggregationObject = parser.parse(aggregationQuery.toString()).getAsJsonObject();
requestBody.put(AGGS,aggregationObject);
String responseDetails = null;
Gson gson = new GsonBuilder().create();
try {

String requestJson = gson.toJson(requestBody, Object.class);
responseDetails = PacHttpUtils.doHttpPost(urlToQuery, requestJson);
Map<String, Object> response = (Map<String, Object>) gson.fromJson(
responseDetails, Object.class);
return (long) (Double.parseDouble(response.get(COUNT).toString()));
JsonObject responseJson = parser.parse(responseDetails).getAsJsonObject();
JsonObject aggs = responseJson.get(AGGREGATIONS).getAsJsonObject();
JsonObject resourceids = aggs.get("distinct_resourceids").getAsJsonObject();
totaluntagged = resourceids.get("value").getAsLong();
return totaluntagged;
} catch (Exception e) {
LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e);
throw e;
Expand Down