class AssetGroupStatsCollector implements Constants {

    public void uploadAssetGroupCountStats(List<String> assetGroups) throws Exception {

        log.info("     Start Collecing  Asset count");
        Map<String, Map<String, Map<String, Object>>> currentInfo = ESManager
                .fetchCurrentCountStatsForAssetGroups(CURR_DATE);
        List<Map<String, Object>> docs = new ArrayList<>();
        for (String ag : assetGroups) {
            try {
                List<Map<String, Object>> typeCounts = AssetGroupUtil.fetchTypeCounts(ASSET_API_URL, ag,getToken());
                Map<String, Map<String, Object>> currInfoMap = currentInfo.get(ag);
                typeCounts.forEach(typeCount -> {
                    String type = typeCount.get("type").toString();
                    long count = Long.valueOf(typeCount.get("count").toString());
                    long min;
                    long max;
                    if (currInfoMap != null) {
                        Map<String, Object> _minMax = currInfoMap.get(type);
                        long _min;
                        long _max;
                        if (_minMax != null) {
                            _min = Long.valueOf(_minMax.get("min").toString());
                            _max = Long.valueOf(_minMax.get("max").toString());
                        } else {
                            _min = count;
                            _max = count;
                        }
                        min = count < _min ? count : _min;
                        max = count > _max ? count : _max;

                    } else {
                        min = count;
                        max = count;
                    }
                    Map<String, Object> doc = new HashMap<>();
                    doc.put("ag", ag);
                    doc.put("type", type);
                    doc.put("min", min);
                    doc.put("max", max);
                    doc.put("date", CURR_DATE);
                    doc.put("@id", Util.getUniqueID(ag + type + CURR_DATE));
                    docs.add(doc);
                });
            } catch (Exception e) {
                log.error("Exception in uploadAssetGroupCountStats" , e);
                Map<String,String> errorMap = new HashMap<>();
                errorMap.put(ERROR, "Exception in uploadAssetGroupCountStats for Asset Group"+ag);
                errorMap.put(ERROR_TYPE, WARN);
                errorMap.put(EXCEPTION, e.getMessage());
                synchronized(errorList){
                    errorList.add(errorMap);
                }
            }
        }
        ESManager.uploadData(AG_STATS, "count_type", docs, "@id", false);

        log.info("    End Collecing  Asset count");
    }

}