class TaggingServiceImpl implements TaggingService, Constants {

    @Override
    public List<Map<String, Long>> taggingByApplication(String assetGroup, String targetType) throws ServiceException {
        List<Map<String, Long>> taggsApplication = new ArrayList<>();
        List<String> tagsList = new ArrayList<>();
        tagsList.add("");
        tagsList.add("unknown");
        Map<String, Long> tagsMap = new HashMap<>();
        Map<String, Object> mustTermsFilter = new HashMap<>();
        String targetTypes = complainceRepository.getTargetTypeForAG(assetGroup, null);
        List<String> targetTypesList = new ArrayList<>(Arrays.asList(targetTypes.split(",")));
        Map<String, Object> mustNotFilter = new HashMap<>();
        HashMultimap<String, Object> shouldFilter = HashMultimap.create();
        String aggsEntityType = "_entitytype.keyword";
        mustTermsFilter.put("tags.Application.keyword", tagsList);
        Map<String, Object> mustFilter = new HashMap<>();
        mustFilter.put("latest", true);
        Map<String, Long> assetWithoutTag;
        Map<String, Long> emptyOrUnkownAssets;
        Long emptyOrUnkownAssetsLong;
        Long assetWithoutTagLong = 0l; 
        String type = null;
        if (!StringUtils.isEmpty(targetType)) {
            type = "'" + targetType + "'";
            if (targetTypesList.contains(type)) {
                assetWithoutTag = getAssetCountWithoutApplicationTag(assetGroup, targetType);
                try {
                    emptyOrUnkownAssetsLong = elasticSearchRepository
                            .getTotalDocumentCountForIndexAndTypeWithMustNotTermsFilter(assetGroup, targetType,
                                    mustFilter, null, null, null, mustTermsFilter, null, null);
                } catch (Exception e) {
                    throw new ServiceException(e);
                }
                if (assetWithoutTag.containsKey(targetType)) {
                    assetWithoutTagLong = assetWithoutTag.get(targetType);
                }
                tagsMap.put(targetType, emptyOrUnkownAssetsLong + assetWithoutTagLong);
            }
        } else {
            assetWithoutTag = getAssetCountWithoutApplicationTag(assetGroup, null);
            try {
                emptyOrUnkownAssets = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, null,
                        mustFilter, mustNotFilter, shouldFilter, aggsEntityType, TEN_THOUSAND, mustTermsFilter);
            } catch (Exception e) {
                throw new ServiceException(e);
            }
           getNoTagsData(tagsMap, targetTypesList, assetWithoutTag, emptyOrUnkownAssets);
        }
        taggsApplication.add(tagsMap);
        return taggsApplication;
    }

}