class CertificateRepository implements Constants {

    public Map<String, Object> getCertificatesSummary(String assetGroup)
            throws DataException {
        Map<String, Object> certificateSummary = new HashMap<>();

        Map<String, Long> certificates = complianceRepository
                .getCertificates(assetGroup);
        StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(
                assetGroup);
        urlToQuery.append(CERT_SEARCH);
        String requestBody = "{\"size\":0,\"aggs\":{\"certs\":{\"children\":{\"type\":\"issue_cert\"},\"aggs\":{\"openfilter\":{\"filter\":{\"term\":{\"issueStatus\":\"open\"}},"
                + "\"aggs\":{\"rules\":{\"terms\":{\"field\":\"ruleId.keyword\",\"size\":10}}}}}}}}";

        String responseJson = "";
        try {
            responseJson = PacHttpUtils.doHttpPost(urlToQuery.toString(),
                    requestBody);
        } catch (Exception e) {
          throw new DataException(e);
        }
        JsonParser jsonParser = new JsonParser();
        JsonObject resultJson = (JsonObject) jsonParser.parse(responseJson);
        JsonObject aggsJson = (JsonObject) jsonParser.parse(resultJson.get(
                "aggregations").toString());

        certificateSummary.put(EXP_IN_45_DAYS, 0);
        certificateSummary.put(EXP_IN_30_DAYS, 0);
        try {
            JsonArray rules = aggsJson.getAsJsonObject()
                    .getAsJsonObject("certs").getAsJsonObject("openfilter")
                    .getAsJsonObject("rules").getAsJsonArray(BUCKETS);
            if (rules.size() > 0) {
                for (int j = 0; j < rules.size(); j++) {
                    if (SSL_CERT_45_DAYS_EXP_RULE.equals(rules.get(j)
                            .getAsJsonObject().get("key").getAsString())) {
                        certificateSummary.put(
                                EXP_IN_45_DAYS,
                                Integer.valueOf(rules.get(j).getAsJsonObject()
                                        .get(DOC_COUNT).toString()));
                    }
                    if (SSL_CERT_30_DAYS_EXP_RULE.equals(rules.get(j)
                            .getAsJsonObject().get("key").getAsString())) {
                        certificateSummary.put(
                                EXP_IN_30_DAYS,
                                Integer.valueOf(rules.get(j).getAsJsonObject()
                                        .get(DOC_COUNT).toString()));
                    }
                }
            }
        } catch (Exception e) {
            LOGGER.error("Error in getCerticatesSummary", e);
        }

        float compliantCount = Float.valueOf(certificates.get(CERTIFICATES).toString())
                - Float.valueOf(certificates.get("certificates_expiring").toString());
        DecimalFormat df = new DecimalFormat("#.00");
        if (certificates.get(CERTIFICATES) > 0) {
            certificateSummary.put("compliantPercent", Math.floor(Float
                    .valueOf(df.format((compliantCount / certificates
                            .get(CERTIFICATES)) * HUNDRED))));
        } else {
            certificateSummary.put("compliantPercent", HUNDRED);
        }
        certificateSummary.put("totalCertificates",
                certificates.get(CERTIFICATES));
        return certificateSummary;
    }

}