@Test public void sendDigestMail1(){ List<Map<String, Object>> ownerEmailDetails=new ArrayList<Map<String,Object>>(); Map<String,Object>ownerDetails=new HashMap<>(); ownerDetails.put("ownerName", "jack"); ownerDetails.put("assetGroup", "aws-all"); ownerDetails.put("ownerEmail", "test@mail.com"); ownerDetails.put("ownerName", "jack"); ownerEmailDetails.add(ownerDetails); Map<String,Object>patchingDetails=new HashMap<>(); patchingDetails.put("unpatched_instances", 0); patchingDetails.put("patched_instances", 5816); patchingDetails.put("total_instances", 5816); patchingDetails.put("patching_percentage", 100); patchingDetails.put("output", getOutput()); Response patchingResponse = new Response(); patchingResponse.setData(patchingDetails); Map<String,Object>certificateDetails=new HashMap<>(); certificateDetails.put("certificates", 1284); certificateDetails.put("certificates_expiring", 0); certificateDetails.put("output", getOutput()); Response CertificateResponse = new Response(); CertificateResponse.setData(certificateDetails); Map<String,Object> taggingDetails=new HashMap<>(); taggingDetails.put("assets", 122083); taggingDetails.put("untagged", 47744); taggingDetails.put("tagged", 74339); taggingDetails.put("compliance", 60); taggingDetails.put("output", getOutput()); Response taggingResponse = new Response(); taggingResponse.setData(taggingDetails); Map<String,Object> vulnerabilityDetails=new HashMap<>(); vulnerabilityDetails.put("hosts", 6964); vulnerabilityDetails.put("vulnerabilities", 94258); vulnerabilityDetails.put("totalVulnerableAssets", 5961); vulnerabilityDetails.put("output", getOutput()); Response vulnerabilityResponse = new Response(); vulnerabilityResponse.setData(taggingDetails); Map<String,Object> complianceStats=new HashMap<>(); complianceStats.put("hosts", 6964); complianceStats.put("vulnerabilities", 94258); complianceStats.put("totalVulnerableAssets", 5961); complianceStats.put("output", getOutput()); Map<String, Double> compliant = Maps.newHashMap(); compliant.put("overall_compliance", 1234d); compliant.put("patch_compliance", 1234d); compliant.put("vuln_compliance", 1234d); compliant.put("tag_compliance", 1234d); compliant.put("cert_compliance", 1234d); complianceStats.put("compliance_stats", compliant); Response complianceStatsResponse = new Response(); complianceStatsResponse.setData(complianceStats); Map<String, Object> responsetopNonCompliantDetails = Maps.newHashMap(); responsetopNonCompliantDetails.put("application", "application123"); List<Map<String, Object>> topNonCompliantResponse = Lists.newArrayList(); topNonCompliantResponse.add(responsetopNonCompliantDetails); Map<String,Object> topNonCompliant = new HashMap<>(); topNonCompliant.put("response", topNonCompliantResponse); topNonCompliant.put("hosts", 6964); topNonCompliant.put("vulnerabilities", 94258); topNonCompliant.put("totalVulnerableAssets", 5961); Response topNonCompliantAppsResponse = new Response(); topNonCompliantAppsResponse.setData(topNonCompliant); Map<String, Object> responseDetails = Maps.newHashMap(); responseDetails.put("application", "application123"); List<Map<String, Object>> response = Lists.newArrayList(); response.add(responseDetails); Map<String,Object> applicationNames = new HashMap<>(); applicationNames.put("response", response); applicationNames.put("hosts", 6964); applicationNames.put("vulnerabilities", 94258); applicationNames.put("totalVulnerableAssets", 5961); Response applicationNamesResponse = new Response(); applicationNamesResponse.setData(applicationNames); Map<String,Object> issueDetails = new HashMap<>(); issueDetails.put("hosts", 6964); issueDetails.put("vulnerabilities", 94258); issueDetails.put("totalVulnerableAssets", 5961); Map<String, Object> issueDistributionDetails = Maps.newHashMap(); Map<String, Integer> distributionBySeverity = Maps.newHashMap(); distributionBySeverity.put("critical", 1233); issueDistributionDetails.put("distribution_by_severity", Maps.newHashMap()); issueDetails.put("distribution", Maps.newHashMap()); Response issueDetailsResponse = new Response(); issueDetailsResponse.setData(issueDetails); issueDetailsResponse.setMessage("message"); assertTrue(issueDetailsResponse.getMessage().equals("message")); ReflectionTestUtils.setField(assetGroupEmailService, "mailTemplateUrl", mailTemplateUrl); when(complianceServiceClient.getPatching(anyString())).thenReturn(patchingResponse); when(complianceServiceClient.getCertificates(anyString())).thenReturn(CertificateResponse); when(complianceServiceClient.getTagging(anyString())).thenReturn(taggingResponse); when(statisticsServiceClient.getComplianceStats(anyString())).thenReturn(complianceStatsResponse); when(complianceServiceClient.getVulnerabilities(anyString())).thenReturn(vulnerabilityResponse); when(complianceServiceClient.getTopNonCompliantApps(anyString())).thenReturn(topNonCompliantAppsResponse); when(complianceServiceClient.getVulnerabilityByApplications(anyString())).thenReturn(applicationNamesResponse); when(complianceServiceClient.getDistribution(anyString())).thenReturn(issueDetailsResponse); when(notificationService.getAllAssetGroupOwnerEmailDetails()).thenReturn(ownerEmailDetails); assetGroupEmailService.sendDigestMail("assetGroupName", "ownerName", "ownerEmail", "mainTemplateUrl", "domainUrl"); }
@SuppressWarnings("unchecked") public void sendDigestMail(String assetGroupName, String ownerName, String ownerEmail, String mainTemplateUrl, String domainUrl) { try { Map<String, Object> report = Maps.newHashMap(); Response patchingDetails = complianceServiceClient.getPatching(assetGroupName); Response certificateDetails = complianceServiceClient.getCertificates(assetGroupName); Response taggingDetails = complianceServiceClient.getTagging(assetGroupName); Response vulnerabilityDetails = complianceServiceClient.getVulnerabilities(assetGroupName); Response complianceStats = statisticsServiceClient.getComplianceStats(assetGroupName); Response topNonCompliantApps = complianceServiceClient.getTopNonCompliantApps(assetGroupName); Response applicationNames = complianceServiceClient.getVulnerabilityByApplications(assetGroupName); Response issueDetails = complianceServiceClient.getDistribution(assetGroupName); Map<String, Object> issueDistributionDetails = (Map<String, Object>) issueDetails.getData().get("distribution"); List<Map<String, Object>> topAppsAndDirectors = (List<Map<String, Object>>) topNonCompliantApps.getData().get("response"); List<Map<String, Object>> topApplicationNames = (List<Map<String, Object>>) applicationNames.getData().get("response"); Set<String> appNames = getAppNames(topApplicationNames); report.put("appNames", appNames); report.put("appNamesCount", appNames.size()); report.put("ownerName", ownerName); if(!topAppsAndDirectors.isEmpty()){ if(topAppsAndDirectors.size()>=5){ report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, 5)); report.put(TOP_APP_COUNT, 5); } else { report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, topAppsAndDirectors.size())); report.put(TOP_APP_COUNT, topAppsAndDirectors.size()); } } else { report.put(TOP_APP_COUNT, 0); report.put(APP_TAB_DETAILS, Lists.newArrayList()); } Map<String, Double> compliant = (Map<String, Double>) complianceStats.getData().get("compliance_stats"); report.put("overallCompliance", compliant.get("overall_compliance")); Map<String, Integer> output = (Map<String, Integer>) patchingDetails.getData().get(OUTPUT); int unpatchedCount = output.get("unpatched_instances"); int unpatchedTotalInstances = getAssetGroupTotalCount("total_instances", output); int unpatchedCompliant = roundOf(compliant.get("patch_compliance")); report.put("unpatchedCount", unpatchedCount); report.put("unpatchedCompliant", unpatchedCompliant); report.put("unpatchedTotalInstances", unpatchedTotalInstances); output = (Map<String, Integer>) vulnerabilityDetails.getData().get(OUTPUT); int vulnerabilitiesCount = output.get("vulnerabilities"); int vulnerabilitiesTotalHosts = getAssetGroupTotalCount("hosts", output); int vulnerabilitiesCompliant = roundOf(compliant.get("vuln_compliance")); report.put("vulnerabilitiesCount", vulnerabilitiesCount); report.put("vulnerabilitiesCompliant", vulnerabilitiesCompliant); report.put("vulnerabilitiesTotalHosts", vulnerabilitiesTotalHosts); output = (Map<String, Integer>) taggingDetails.getData().get(OUTPUT); int untaggedCount = output.get("untagged"); int untaggedTotalInstances = getAssetGroupTotalCount("assets", output); int untaggedCompliant = roundOf(compliant.get("tag_compliance")); report.put("untaggedCount", untaggedCount); report.put("untaggedCompliant", untaggedCompliant); report.put("untaggedTotalInstances", untaggedTotalInstances); output = (Map<String, Integer>) certificateDetails.getData().get(OUTPUT); int expiringCount = output.get("certificates_expiring"); int expiringDays = getAssetGroupTotalCount("certificates", output); int expiringCompliant = roundOf(compliant.get("cert_compliance")); report.put("expiringCount", expiringCount); report.put("expiringCompliant", expiringCompliant == 0 ? 100: expiringCompliant); report.put("expiringDays", expiringDays); Map<String, Integer> criticalIssuesDetails = (Map<String, Integer>)issueDistributionDetails.get("distribution_by_severity"); if(criticalIssuesDetails.isEmpty()) { report.put(CRITICAL_ISSUE_COUNT, 0); } else { Integer criticalIssuesCount = criticalIssuesDetails.get("critical"); if(criticalIssuesCount != null) { report.put(CRITICAL_ISSUE_COUNT, criticalIssuesCount); } else { report.put(CRITICAL_ISSUE_COUNT, 0); } } report.put("criticalIssuesCompliant", compliant.get("overall_compliance")); report.put("criticalIssuesTotalIssues", issueDistributionDetails.get("total_issues")); domainUrl = domainUrl+"/un-subscribe?email="+ownerEmail; report.put("subscriptionUrl", domainUrl); String attachmentUrl=""; List<String> toDetails = Lists.newArrayList(); toDetails.add(ownerEmail); String emailContent = mailService.processTemplate(mainTemplateUrl, report); log.info(EXE_EMAIL_SEND,assetGroupName); if(emailContent != null) { mailService.prepareTemplateAndSendMail("noreply@pacman.t-mobile.com", toDetails, "Asset Group Weekly Report - "+assetGroupName, emailContent, attachmentUrl); } } catch(Exception exception) { log.info("Exception in sendDigestMail:",exception); } }
AssetGroupEmailService implements Constants { @SuppressWarnings("unchecked") public void sendDigestMail(String assetGroupName, String ownerName, String ownerEmail, String mainTemplateUrl, String domainUrl) { try { Map<String, Object> report = Maps.newHashMap(); Response patchingDetails = complianceServiceClient.getPatching(assetGroupName); Response certificateDetails = complianceServiceClient.getCertificates(assetGroupName); Response taggingDetails = complianceServiceClient.getTagging(assetGroupName); Response vulnerabilityDetails = complianceServiceClient.getVulnerabilities(assetGroupName); Response complianceStats = statisticsServiceClient.getComplianceStats(assetGroupName); Response topNonCompliantApps = complianceServiceClient.getTopNonCompliantApps(assetGroupName); Response applicationNames = complianceServiceClient.getVulnerabilityByApplications(assetGroupName); Response issueDetails = complianceServiceClient.getDistribution(assetGroupName); Map<String, Object> issueDistributionDetails = (Map<String, Object>) issueDetails.getData().get("distribution"); List<Map<String, Object>> topAppsAndDirectors = (List<Map<String, Object>>) topNonCompliantApps.getData().get("response"); List<Map<String, Object>> topApplicationNames = (List<Map<String, Object>>) applicationNames.getData().get("response"); Set<String> appNames = getAppNames(topApplicationNames); report.put("appNames", appNames); report.put("appNamesCount", appNames.size()); report.put("ownerName", ownerName); if(!topAppsAndDirectors.isEmpty()){ if(topAppsAndDirectors.size()>=5){ report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, 5)); report.put(TOP_APP_COUNT, 5); } else { report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, topAppsAndDirectors.size())); report.put(TOP_APP_COUNT, topAppsAndDirectors.size()); } } else { report.put(TOP_APP_COUNT, 0); report.put(APP_TAB_DETAILS, Lists.newArrayList()); } Map<String, Double> compliant = (Map<String, Double>) complianceStats.getData().get("compliance_stats"); report.put("overallCompliance", compliant.get("overall_compliance")); Map<String, Integer> output = (Map<String, Integer>) patchingDetails.getData().get(OUTPUT); int unpatchedCount = output.get("unpatched_instances"); int unpatchedTotalInstances = getAssetGroupTotalCount("total_instances", output); int unpatchedCompliant = roundOf(compliant.get("patch_compliance")); report.put("unpatchedCount", unpatchedCount); report.put("unpatchedCompliant", unpatchedCompliant); report.put("unpatchedTotalInstances", unpatchedTotalInstances); output = (Map<String, Integer>) vulnerabilityDetails.getData().get(OUTPUT); int vulnerabilitiesCount = output.get("vulnerabilities"); int vulnerabilitiesTotalHosts = getAssetGroupTotalCount("hosts", output); int vulnerabilitiesCompliant = roundOf(compliant.get("vuln_compliance")); report.put("vulnerabilitiesCount", vulnerabilitiesCount); report.put("vulnerabilitiesCompliant", vulnerabilitiesCompliant); report.put("vulnerabilitiesTotalHosts", vulnerabilitiesTotalHosts); output = (Map<String, Integer>) taggingDetails.getData().get(OUTPUT); int untaggedCount = output.get("untagged"); int untaggedTotalInstances = getAssetGroupTotalCount("assets", output); int untaggedCompliant = roundOf(compliant.get("tag_compliance")); report.put("untaggedCount", untaggedCount); report.put("untaggedCompliant", untaggedCompliant); report.put("untaggedTotalInstances", untaggedTotalInstances); output = (Map<String, Integer>) certificateDetails.getData().get(OUTPUT); int expiringCount = output.get("certificates_expiring"); int expiringDays = getAssetGroupTotalCount("certificates", output); int expiringCompliant = roundOf(compliant.get("cert_compliance")); report.put("expiringCount", expiringCount); report.put("expiringCompliant", expiringCompliant == 0 ? 100: expiringCompliant); report.put("expiringDays", expiringDays); Map<String, Integer> criticalIssuesDetails = (Map<String, Integer>)issueDistributionDetails.get("distribution_by_severity"); if(criticalIssuesDetails.isEmpty()) { report.put(CRITICAL_ISSUE_COUNT, 0); } else { Integer criticalIssuesCount = criticalIssuesDetails.get("critical"); if(criticalIssuesCount != null) { report.put(CRITICAL_ISSUE_COUNT, criticalIssuesCount); } else { report.put(CRITICAL_ISSUE_COUNT, 0); } } report.put("criticalIssuesCompliant", compliant.get("overall_compliance")); report.put("criticalIssuesTotalIssues", issueDistributionDetails.get("total_issues")); domainUrl = domainUrl+"/un-subscribe?email="+ownerEmail; report.put("subscriptionUrl", domainUrl); String attachmentUrl=""; List<String> toDetails = Lists.newArrayList(); toDetails.add(ownerEmail); String emailContent = mailService.processTemplate(mainTemplateUrl, report); log.info(EXE_EMAIL_SEND,assetGroupName); if(emailContent != null) { mailService.prepareTemplateAndSendMail("noreply@pacman.t-mobile.com", toDetails, "Asset Group Weekly Report - "+assetGroupName, emailContent, attachmentUrl); } } catch(Exception exception) { log.info("Exception in sendDigestMail:",exception); } } }
AssetGroupEmailService implements Constants { @SuppressWarnings("unchecked") public void sendDigestMail(String assetGroupName, String ownerName, String ownerEmail, String mainTemplateUrl, String domainUrl) { try { Map<String, Object> report = Maps.newHashMap(); Response patchingDetails = complianceServiceClient.getPatching(assetGroupName); Response certificateDetails = complianceServiceClient.getCertificates(assetGroupName); Response taggingDetails = complianceServiceClient.getTagging(assetGroupName); Response vulnerabilityDetails = complianceServiceClient.getVulnerabilities(assetGroupName); Response complianceStats = statisticsServiceClient.getComplianceStats(assetGroupName); Response topNonCompliantApps = complianceServiceClient.getTopNonCompliantApps(assetGroupName); Response applicationNames = complianceServiceClient.getVulnerabilityByApplications(assetGroupName); Response issueDetails = complianceServiceClient.getDistribution(assetGroupName); Map<String, Object> issueDistributionDetails = (Map<String, Object>) issueDetails.getData().get("distribution"); List<Map<String, Object>> topAppsAndDirectors = (List<Map<String, Object>>) topNonCompliantApps.getData().get("response"); List<Map<String, Object>> topApplicationNames = (List<Map<String, Object>>) applicationNames.getData().get("response"); Set<String> appNames = getAppNames(topApplicationNames); report.put("appNames", appNames); report.put("appNamesCount", appNames.size()); report.put("ownerName", ownerName); if(!topAppsAndDirectors.isEmpty()){ if(topAppsAndDirectors.size()>=5){ report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, 5)); report.put(TOP_APP_COUNT, 5); } else { report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, topAppsAndDirectors.size())); report.put(TOP_APP_COUNT, topAppsAndDirectors.size()); } } else { report.put(TOP_APP_COUNT, 0); report.put(APP_TAB_DETAILS, Lists.newArrayList()); } Map<String, Double> compliant = (Map<String, Double>) complianceStats.getData().get("compliance_stats"); report.put("overallCompliance", compliant.get("overall_compliance")); Map<String, Integer> output = (Map<String, Integer>) patchingDetails.getData().get(OUTPUT); int unpatchedCount = output.get("unpatched_instances"); int unpatchedTotalInstances = getAssetGroupTotalCount("total_instances", output); int unpatchedCompliant = roundOf(compliant.get("patch_compliance")); report.put("unpatchedCount", unpatchedCount); report.put("unpatchedCompliant", unpatchedCompliant); report.put("unpatchedTotalInstances", unpatchedTotalInstances); output = (Map<String, Integer>) vulnerabilityDetails.getData().get(OUTPUT); int vulnerabilitiesCount = output.get("vulnerabilities"); int vulnerabilitiesTotalHosts = getAssetGroupTotalCount("hosts", output); int vulnerabilitiesCompliant = roundOf(compliant.get("vuln_compliance")); report.put("vulnerabilitiesCount", vulnerabilitiesCount); report.put("vulnerabilitiesCompliant", vulnerabilitiesCompliant); report.put("vulnerabilitiesTotalHosts", vulnerabilitiesTotalHosts); output = (Map<String, Integer>) taggingDetails.getData().get(OUTPUT); int untaggedCount = output.get("untagged"); int untaggedTotalInstances = getAssetGroupTotalCount("assets", output); int untaggedCompliant = roundOf(compliant.get("tag_compliance")); report.put("untaggedCount", untaggedCount); report.put("untaggedCompliant", untaggedCompliant); report.put("untaggedTotalInstances", untaggedTotalInstances); output = (Map<String, Integer>) certificateDetails.getData().get(OUTPUT); int expiringCount = output.get("certificates_expiring"); int expiringDays = getAssetGroupTotalCount("certificates", output); int expiringCompliant = roundOf(compliant.get("cert_compliance")); report.put("expiringCount", expiringCount); report.put("expiringCompliant", expiringCompliant == 0 ? 100: expiringCompliant); report.put("expiringDays", expiringDays); Map<String, Integer> criticalIssuesDetails = (Map<String, Integer>)issueDistributionDetails.get("distribution_by_severity"); if(criticalIssuesDetails.isEmpty()) { report.put(CRITICAL_ISSUE_COUNT, 0); } else { Integer criticalIssuesCount = criticalIssuesDetails.get("critical"); if(criticalIssuesCount != null) { report.put(CRITICAL_ISSUE_COUNT, criticalIssuesCount); } else { report.put(CRITICAL_ISSUE_COUNT, 0); } } report.put("criticalIssuesCompliant", compliant.get("overall_compliance")); report.put("criticalIssuesTotalIssues", issueDistributionDetails.get("total_issues")); domainUrl = domainUrl+"/un-subscribe?email="+ownerEmail; report.put("subscriptionUrl", domainUrl); String attachmentUrl=""; List<String> toDetails = Lists.newArrayList(); toDetails.add(ownerEmail); String emailContent = mailService.processTemplate(mainTemplateUrl, report); log.info(EXE_EMAIL_SEND,assetGroupName); if(emailContent != null) { mailService.prepareTemplateAndSendMail("noreply@pacman.t-mobile.com", toDetails, "Asset Group Weekly Report - "+assetGroupName, emailContent, attachmentUrl); } } catch(Exception exception) { log.info("Exception in sendDigestMail:",exception); } }  }
AssetGroupEmailService implements Constants { @SuppressWarnings("unchecked") public void sendDigestMail(String assetGroupName, String ownerName, String ownerEmail, String mainTemplateUrl, String domainUrl) { try { Map<String, Object> report = Maps.newHashMap(); Response patchingDetails = complianceServiceClient.getPatching(assetGroupName); Response certificateDetails = complianceServiceClient.getCertificates(assetGroupName); Response taggingDetails = complianceServiceClient.getTagging(assetGroupName); Response vulnerabilityDetails = complianceServiceClient.getVulnerabilities(assetGroupName); Response complianceStats = statisticsServiceClient.getComplianceStats(assetGroupName); Response topNonCompliantApps = complianceServiceClient.getTopNonCompliantApps(assetGroupName); Response applicationNames = complianceServiceClient.getVulnerabilityByApplications(assetGroupName); Response issueDetails = complianceServiceClient.getDistribution(assetGroupName); Map<String, Object> issueDistributionDetails = (Map<String, Object>) issueDetails.getData().get("distribution"); List<Map<String, Object>> topAppsAndDirectors = (List<Map<String, Object>>) topNonCompliantApps.getData().get("response"); List<Map<String, Object>> topApplicationNames = (List<Map<String, Object>>) applicationNames.getData().get("response"); Set<String> appNames = getAppNames(topApplicationNames); report.put("appNames", appNames); report.put("appNamesCount", appNames.size()); report.put("ownerName", ownerName); if(!topAppsAndDirectors.isEmpty()){ if(topAppsAndDirectors.size()>=5){ report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, 5)); report.put(TOP_APP_COUNT, 5); } else { report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, topAppsAndDirectors.size())); report.put(TOP_APP_COUNT, topAppsAndDirectors.size()); } } else { report.put(TOP_APP_COUNT, 0); report.put(APP_TAB_DETAILS, Lists.newArrayList()); } Map<String, Double> compliant = (Map<String, Double>) complianceStats.getData().get("compliance_stats"); report.put("overallCompliance", compliant.get("overall_compliance")); Map<String, Integer> output = (Map<String, Integer>) patchingDetails.getData().get(OUTPUT); int unpatchedCount = output.get("unpatched_instances"); int unpatchedTotalInstances = getAssetGroupTotalCount("total_instances", output); int unpatchedCompliant = roundOf(compliant.get("patch_compliance")); report.put("unpatchedCount", unpatchedCount); report.put("unpatchedCompliant", unpatchedCompliant); report.put("unpatchedTotalInstances", unpatchedTotalInstances); output = (Map<String, Integer>) vulnerabilityDetails.getData().get(OUTPUT); int vulnerabilitiesCount = output.get("vulnerabilities"); int vulnerabilitiesTotalHosts = getAssetGroupTotalCount("hosts", output); int vulnerabilitiesCompliant = roundOf(compliant.get("vuln_compliance")); report.put("vulnerabilitiesCount", vulnerabilitiesCount); report.put("vulnerabilitiesCompliant", vulnerabilitiesCompliant); report.put("vulnerabilitiesTotalHosts", vulnerabilitiesTotalHosts); output = (Map<String, Integer>) taggingDetails.getData().get(OUTPUT); int untaggedCount = output.get("untagged"); int untaggedTotalInstances = getAssetGroupTotalCount("assets", output); int untaggedCompliant = roundOf(compliant.get("tag_compliance")); report.put("untaggedCount", untaggedCount); report.put("untaggedCompliant", untaggedCompliant); report.put("untaggedTotalInstances", untaggedTotalInstances); output = (Map<String, Integer>) certificateDetails.getData().get(OUTPUT); int expiringCount = output.get("certificates_expiring"); int expiringDays = getAssetGroupTotalCount("certificates", output); int expiringCompliant = roundOf(compliant.get("cert_compliance")); report.put("expiringCount", expiringCount); report.put("expiringCompliant", expiringCompliant == 0 ? 100: expiringCompliant); report.put("expiringDays", expiringDays); Map<String, Integer> criticalIssuesDetails = (Map<String, Integer>)issueDistributionDetails.get("distribution_by_severity"); if(criticalIssuesDetails.isEmpty()) { report.put(CRITICAL_ISSUE_COUNT, 0); } else { Integer criticalIssuesCount = criticalIssuesDetails.get("critical"); if(criticalIssuesCount != null) { report.put(CRITICAL_ISSUE_COUNT, criticalIssuesCount); } else { report.put(CRITICAL_ISSUE_COUNT, 0); } } report.put("criticalIssuesCompliant", compliant.get("overall_compliance")); report.put("criticalIssuesTotalIssues", issueDistributionDetails.get("total_issues")); domainUrl = domainUrl+"/un-subscribe?email="+ownerEmail; report.put("subscriptionUrl", domainUrl); String attachmentUrl=""; List<String> toDetails = Lists.newArrayList(); toDetails.add(ownerEmail); String emailContent = mailService.processTemplate(mainTemplateUrl, report); log.info(EXE_EMAIL_SEND,assetGroupName); if(emailContent != null) { mailService.prepareTemplateAndSendMail("noreply@pacman.t-mobile.com", toDetails, "Asset Group Weekly Report - "+assetGroupName, emailContent, attachmentUrl); } } catch(Exception exception) { log.info("Exception in sendDigestMail:",exception); } }  void executeEmailServiceForAssetGroup(); @SuppressWarnings("unchecked") void sendDigestMail(String assetGroupName, String ownerName, String ownerEmail, String mainTemplateUrl, String domainUrl); }
AssetGroupEmailService implements Constants { @SuppressWarnings("unchecked") public void sendDigestMail(String assetGroupName, String ownerName, String ownerEmail, String mainTemplateUrl, String domainUrl) { try { Map<String, Object> report = Maps.newHashMap(); Response patchingDetails = complianceServiceClient.getPatching(assetGroupName); Response certificateDetails = complianceServiceClient.getCertificates(assetGroupName); Response taggingDetails = complianceServiceClient.getTagging(assetGroupName); Response vulnerabilityDetails = complianceServiceClient.getVulnerabilities(assetGroupName); Response complianceStats = statisticsServiceClient.getComplianceStats(assetGroupName); Response topNonCompliantApps = complianceServiceClient.getTopNonCompliantApps(assetGroupName); Response applicationNames = complianceServiceClient.getVulnerabilityByApplications(assetGroupName); Response issueDetails = complianceServiceClient.getDistribution(assetGroupName); Map<String, Object> issueDistributionDetails = (Map<String, Object>) issueDetails.getData().get("distribution"); List<Map<String, Object>> topAppsAndDirectors = (List<Map<String, Object>>) topNonCompliantApps.getData().get("response"); List<Map<String, Object>> topApplicationNames = (List<Map<String, Object>>) applicationNames.getData().get("response"); Set<String> appNames = getAppNames(topApplicationNames); report.put("appNames", appNames); report.put("appNamesCount", appNames.size()); report.put("ownerName", ownerName); if(!topAppsAndDirectors.isEmpty()){ if(topAppsAndDirectors.size()>=5){ report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, 5)); report.put(TOP_APP_COUNT, 5); } else { report.put(APP_TAB_DETAILS, topAppsAndDirectors.subList(0, topAppsAndDirectors.size())); report.put(TOP_APP_COUNT, topAppsAndDirectors.size()); } } else { report.put(TOP_APP_COUNT, 0); report.put(APP_TAB_DETAILS, Lists.newArrayList()); } Map<String, Double> compliant = (Map<String, Double>) complianceStats.getData().get("compliance_stats"); report.put("overallCompliance", compliant.get("overall_compliance")); Map<String, Integer> output = (Map<String, Integer>) patchingDetails.getData().get(OUTPUT); int unpatchedCount = output.get("unpatched_instances"); int unpatchedTotalInstances = getAssetGroupTotalCount("total_instances", output); int unpatchedCompliant = roundOf(compliant.get("patch_compliance")); report.put("unpatchedCount", unpatchedCount); report.put("unpatchedCompliant", unpatchedCompliant); report.put("unpatchedTotalInstances", unpatchedTotalInstances); output = (Map<String, Integer>) vulnerabilityDetails.getData().get(OUTPUT); int vulnerabilitiesCount = output.get("vulnerabilities"); int vulnerabilitiesTotalHosts = getAssetGroupTotalCount("hosts", output); int vulnerabilitiesCompliant = roundOf(compliant.get("vuln_compliance")); report.put("vulnerabilitiesCount", vulnerabilitiesCount); report.put("vulnerabilitiesCompliant", vulnerabilitiesCompliant); report.put("vulnerabilitiesTotalHosts", vulnerabilitiesTotalHosts); output = (Map<String, Integer>) taggingDetails.getData().get(OUTPUT); int untaggedCount = output.get("untagged"); int untaggedTotalInstances = getAssetGroupTotalCount("assets", output); int untaggedCompliant = roundOf(compliant.get("tag_compliance")); report.put("untaggedCount", untaggedCount); report.put("untaggedCompliant", untaggedCompliant); report.put("untaggedTotalInstances", untaggedTotalInstances); output = (Map<String, Integer>) certificateDetails.getData().get(OUTPUT); int expiringCount = output.get("certificates_expiring"); int expiringDays = getAssetGroupTotalCount("certificates", output); int expiringCompliant = roundOf(compliant.get("cert_compliance")); report.put("expiringCount", expiringCount); report.put("expiringCompliant", expiringCompliant == 0 ? 100: expiringCompliant); report.put("expiringDays", expiringDays); Map<String, Integer> criticalIssuesDetails = (Map<String, Integer>)issueDistributionDetails.get("distribution_by_severity"); if(criticalIssuesDetails.isEmpty()) { report.put(CRITICAL_ISSUE_COUNT, 0); } else { Integer criticalIssuesCount = criticalIssuesDetails.get("critical"); if(criticalIssuesCount != null) { report.put(CRITICAL_ISSUE_COUNT, criticalIssuesCount); } else { report.put(CRITICAL_ISSUE_COUNT, 0); } } report.put("criticalIssuesCompliant", compliant.get("overall_compliance")); report.put("criticalIssuesTotalIssues", issueDistributionDetails.get("total_issues")); domainUrl = domainUrl+"/un-subscribe?email="+ownerEmail; report.put("subscriptionUrl", domainUrl); String attachmentUrl=""; List<String> toDetails = Lists.newArrayList(); toDetails.add(ownerEmail); String emailContent = mailService.processTemplate(mainTemplateUrl, report); log.info(EXE_EMAIL_SEND,assetGroupName); if(emailContent != null) { mailService.prepareTemplateAndSendMail("noreply@pacman.t-mobile.com", toDetails, "Asset Group Weekly Report - "+assetGroupName, emailContent, attachmentUrl); } } catch(Exception exception) { log.info("Exception in sendDigestMail:",exception); } }  void executeEmailServiceForAssetGroup(); @SuppressWarnings("unchecked") void sendDigestMail(String assetGroupName, String ownerName, String ownerEmail, String mainTemplateUrl, String domainUrl);  }