class ComplianceServiceImpl implements ComplianceService, Constants {

    @Override
    public Map<String, Long> getPatching(String assetGroup, String targetType, String application) throws ServiceException {
    	logger.info("input value for getPatching are {} {} {}",assetGroup,targetType,application);
        Long totalPatched;
        Long totalUnpatched = 0l;
        Long totalAssets = 0l;
        double patchingPercentage;
        Map<String, Long> patching = new HashMap<>();
        AssetCountDTO[] targetTypes;
        try {
            if (StringUtils.isEmpty(targetType)) {
                targetTypes = filterRepository.getListOfTargetTypes(assetGroup, null);
            } else {
                AssetCountDTO apiName = new AssetCountDTO();
                apiName.setType(targetType);
                targetTypes = new AssetCountDTO[] { apiName };
            }
            for (AssetCountDTO targettype : targetTypes) {
                String type = targettype.getType();
                if (EC2.equalsIgnoreCase(type) || VIRTUALMACHINE.equalsIgnoreCase(type)) {
                    totalAssets += repository.getPatchabeAssetsCount(assetGroup, targettype.getType(),application,null,null);
                    totalUnpatched += repository.getUnpatchedAssetsCount(assetGroup, targettype.getType(),application);
                }
            }
        } catch (DataException e) {
        	logger.error("Error @ getPatching ", e);
            throw new ServiceException(e);
        }
        if(totalUnpatched > totalAssets){
        	totalUnpatched = totalAssets;
        }
        
        totalPatched = totalAssets - totalUnpatched;
        if (totalAssets > 0) {
            patchingPercentage = (totalPatched * HUNDRED) / totalAssets;
            patchingPercentage = Math.floor(patchingPercentage);
        } else {
            patchingPercentage = HUNDRED;
        }
        patching.put("unpatched_instances", totalUnpatched);
        patching.put("total_instances", totalAssets);
        patching.put("patched_instances", totalPatched);
        patching.put("patching_percentage", (long) patchingPercentage);
        if (patching.isEmpty()) {
            throw new ServiceException(NO_DATA_FOUND);
        }
        return patching;
    }

}