class ComplianceServiceImpl implements ComplianceService, Constants {

    @Override
    public Map<String, Object> getOverallComplianceByDomain(String assetGroup, String domain) throws ServiceException {
        double numerator = 0;
        double denominator = 0;
        double overallcompliance = 0;
        // get all the targettypes mapped to domain
        // get all rules mapped to these targetTypes
        List<Object> rules = getRules(repository.getTargetTypeForAG(assetGroup, domain));
        List<LinkedHashMap<String, Object>> complainceByRules = getComplainceByRules(domain, assetGroup, rules);
        Map<String, Map<String, Double>> rulesComplianceByCategory = getRulesComplianceByCategory(complainceByRules,
                assetGroup);
        int totalCategories = rulesComplianceByCategory.entrySet().size();
        LinkedHashMap<String, Object> ruleCatWeightage = getRuleCategoryBWeightage(domain, totalCategories,
                rulesComplianceByCategory);

        int ruleCategoryWeightage = 1;
        int totalWeightage = 0;
        LinkedHashMap<String, Object> ruleCatDistributionWithOverall = new LinkedHashMap<>();
        for (Map.Entry<String, Object> entry : ruleCatWeightage.entrySet()) {
            for (Map.Entry<String, Map<String, Double>> categoryDistribution : rulesComplianceByCategory.entrySet()) {
                // calculate compliance By Category
                if (entry.getKey().equals(categoryDistribution.getKey())) {

                    ruleCategoryWeightage = (null != ruleCatWeightage.get(categoryDistribution.getKey())) ? Integer
                            .valueOf(ruleCatWeightage.get(categoryDistribution.getKey()).toString()) : 1;
                    totalWeightage += ruleCategoryWeightage;

                    denominator = (categoryDistribution.getValue().get(DENOMINATOR));
                    numerator = (categoryDistribution.getValue().get(NUMERATOR));
                    double issueCompliance = calculateIssueCompliance(numerator, denominator);

                    ruleCatDistributionWithOverall.put(categoryDistribution.getKey(), issueCompliance);
                    overallcompliance += (ruleCategoryWeightage * issueCompliance);
                    if (totalCategories == 1) {
                        overallcompliance = overallcompliance / totalWeightage;
                        overallcompliance = Math.floor(overallcompliance);
                        ruleCatDistributionWithOverall.put("overall", overallcompliance);
                    }
                    // Calculate Overall Compliance
                    totalCategories -= 1;

                }
            }
        }
        if (ruleCatDistributionWithOverall.isEmpty()) {
            throw new ServiceException(NO_DATA_FOUND);
        }
        return ruleCatDistributionWithOverall;
    }

}