class ComplianceServiceImpl implements ComplianceService, Constants {

   @SuppressWarnings("unchecked")
   public List<Map<String, Object>> getRuleDetailsbyApplication(String assetGroup, String ruleId, String searchText)
           throws ServiceException {
       Map<String, Long> assetcountbyAplications;
       List<Map<String, Object>> applicationList = new ArrayList<>();
       String targetType = null;
       JsonArray buckets;
       try {
           buckets = repository.getRuleDetailsByApplicationFromES(assetGroup, ruleId, searchText);
       } catch (DataException e) {
       	logger.error("Error @ getRuleDetailsbyApplication while getting the application by rule from ES", e);
           throw new ServiceException(e);
       }
       Gson googleJson = new Gson();
       List<Map<String, Object>> issuesByApplcationList = googleJson.fromJson(buckets, ArrayList.class);
       Map<String, Long> issuesByApplcationListMap = issuesByApplcationList.parallelStream().collect(
               Collectors.toMap(issue -> issue.get(KEY).toString(),
                       issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString())));
       targetType = getTargetTypeByRuleId(ruleId);
       if (!Strings.isNullOrEmpty(targetType)) {
           // Get AssetCount By application for Rule TargetType

           if (ruleId.contains(CLOUD_KERNEL_COMPLIANCE_POLICY)) {
               try {
                   assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText,
                           targetType);
               } catch (DataException e) {
               	logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for cloud kernel rule from ES", e);
                   throw new ServiceException(e);
               }
           } else if ((ruleId.equalsIgnoreCase(ONPREM_KERNEL_COMPLIANCE_RULE))) {
               try {
                   assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText,
                           ONPREMSERVER);
               } catch (DataException e) {
               	logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for onprem kernel rule from ES", e);
                   throw new ServiceException(e);
               }
           } else if ((ruleId.contains(CLOUD_QUALYS_POLICY) && qualysEnabled) || ruleId.equalsIgnoreCase(SSM_AGENT_RULE)) {
               try{
               assetcountbyAplications = repository.getInstanceCountForQualysByAppsOrEnv(assetGroup, "policydetailsbyapplication","","",targetType);
               } catch (DataException e) {
               	logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for qualys from ES", e);
                   throw new ServiceException(e);
               }
           }else {
               assetcountbyAplications = repository.getAllApplicationsAssetCountForTargetType(assetGroup, targetType);
           }
           // Form Compliance Details by Application
          formComplianceDetailsByApplication(applicationList, assetcountbyAplications,
                   issuesByApplcationListMap);
       } else {
           throw new ServiceException("No Target Type associated");
       }
       return applicationList;

   }

}