@Test public void getUntaggingByTargetTypesTestExeptions() throws Exception { List<Map<String, Object>> emptyList = new ArrayList<>(); when(repository.getRuleTargetTypesFromDbByPolicyId(anyString())) .thenReturn(emptyList); ReflectionTestUtils.setField(taggingServiceImpl, "mandatoryTags", "Application,Environment"); assertThatThrownBy(() -> taggingServiceImpl .getUntaggingByTargetTypes(untaggedTargetTypeRequest)) .isInstanceOf(ServiceException.class); }
public List<Map<String, Object>> getUntaggingByTargetTypes(UntaggedTargetTypeRequest request) throws ServiceException { long assetCount ; long untaggedCount ; long taggedCount ; double compliancePercentage; String type; List<String> tagsList = new ArrayList<>(Arrays.asList(mandatoryTags.split(","))); List<Map<String, Object>> targetTypes; try { targetTypes = repository.getRuleTargetTypesFromDbByPolicyId(TAGGIG_POLICY); } catch (DataException e) { throw new ServiceException(e); } if (targetTypes.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } Map<String, String> filterTags = request.getFilter(); List<Map<String, Object>> unTagsList = new ArrayList<>(); Map<String, Long> assetCountByTypes = complainceRepository.getTotalAssetCount(request.getAg(), null,null,null); Map<String, Long> untaggedCountMap = getUntaggedTargetTypeIssues(request, tagsList); for (Map<String, Object> targetType : targetTypes) { type = targetType.get(TARGET_TYPE).toString(); Map<String, Object> data = new HashMap<>(); if (null != filterTags && !filterTags.isEmpty() && !filterTags.get(TARGET_TYPE).isEmpty() && (!type.equalsIgnoreCase(filterTags.get(TARGET_TYPE)))) { continue; } assetCount = (null != assetCountByTypes.get(type)) ? Long.parseLong(assetCountByTypes.get(type).toString()) : 0l; if (assetCount > 0) { untaggedCount = getUntaggedAsset(untaggedCountMap, type); if (untaggedCount > assetCount) { untaggedCount = assetCount; } taggedCount = assetCount - untaggedCount; compliancePercentage = (double) (taggedCount * INT_HUNDRED) / assetCount; compliancePercentage = Math.floor(compliancePercentage); data.put("name", type); data.put("untagged", untaggedCount); data.put("tagged", taggedCount); data.put("assetCount", assetCount); data.put(COMP_PERCENTAGE, compliancePercentage); unTagsList.add(data); } } if (unTagsList.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return unTagsList; }
TaggingServiceImpl implements TaggingService, Constants { public List<Map<String, Object>> getUntaggingByTargetTypes(UntaggedTargetTypeRequest request) throws ServiceException { long assetCount ; long untaggedCount ; long taggedCount ; double compliancePercentage; String type; List<String> tagsList = new ArrayList<>(Arrays.asList(mandatoryTags.split(","))); List<Map<String, Object>> targetTypes; try { targetTypes = repository.getRuleTargetTypesFromDbByPolicyId(TAGGIG_POLICY); } catch (DataException e) { throw new ServiceException(e); } if (targetTypes.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } Map<String, String> filterTags = request.getFilter(); List<Map<String, Object>> unTagsList = new ArrayList<>(); Map<String, Long> assetCountByTypes = complainceRepository.getTotalAssetCount(request.getAg(), null,null,null); Map<String, Long> untaggedCountMap = getUntaggedTargetTypeIssues(request, tagsList); for (Map<String, Object> targetType : targetTypes) { type = targetType.get(TARGET_TYPE).toString(); Map<String, Object> data = new HashMap<>(); if (null != filterTags && !filterTags.isEmpty() && !filterTags.get(TARGET_TYPE).isEmpty() && (!type.equalsIgnoreCase(filterTags.get(TARGET_TYPE)))) { continue; } assetCount = (null != assetCountByTypes.get(type)) ? Long.parseLong(assetCountByTypes.get(type).toString()) : 0l; if (assetCount > 0) { untaggedCount = getUntaggedAsset(untaggedCountMap, type); if (untaggedCount > assetCount) { untaggedCount = assetCount; } taggedCount = assetCount - untaggedCount; compliancePercentage = (double) (taggedCount * INT_HUNDRED) / assetCount; compliancePercentage = Math.floor(compliancePercentage); data.put("name", type); data.put("untagged", untaggedCount); data.put("tagged", taggedCount); data.put("assetCount", assetCount); data.put(COMP_PERCENTAGE, compliancePercentage); unTagsList.add(data); } } if (unTagsList.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return unTagsList; } }
TaggingServiceImpl implements TaggingService, Constants { public List<Map<String, Object>> getUntaggingByTargetTypes(UntaggedTargetTypeRequest request) throws ServiceException { long assetCount ; long untaggedCount ; long taggedCount ; double compliancePercentage; String type; List<String> tagsList = new ArrayList<>(Arrays.asList(mandatoryTags.split(","))); List<Map<String, Object>> targetTypes; try { targetTypes = repository.getRuleTargetTypesFromDbByPolicyId(TAGGIG_POLICY); } catch (DataException e) { throw new ServiceException(e); } if (targetTypes.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } Map<String, String> filterTags = request.getFilter(); List<Map<String, Object>> unTagsList = new ArrayList<>(); Map<String, Long> assetCountByTypes = complainceRepository.getTotalAssetCount(request.getAg(), null,null,null); Map<String, Long> untaggedCountMap = getUntaggedTargetTypeIssues(request, tagsList); for (Map<String, Object> targetType : targetTypes) { type = targetType.get(TARGET_TYPE).toString(); Map<String, Object> data = new HashMap<>(); if (null != filterTags && !filterTags.isEmpty() && !filterTags.get(TARGET_TYPE).isEmpty() && (!type.equalsIgnoreCase(filterTags.get(TARGET_TYPE)))) { continue; } assetCount = (null != assetCountByTypes.get(type)) ? Long.parseLong(assetCountByTypes.get(type).toString()) : 0l; if (assetCount > 0) { untaggedCount = getUntaggedAsset(untaggedCountMap, type); if (untaggedCount > assetCount) { untaggedCount = assetCount; } taggedCount = assetCount - untaggedCount; compliancePercentage = (double) (taggedCount * INT_HUNDRED) / assetCount; compliancePercentage = Math.floor(compliancePercentage); data.put("name", type); data.put("untagged", untaggedCount); data.put("tagged", taggedCount); data.put("assetCount", assetCount); data.put(COMP_PERCENTAGE, compliancePercentage); unTagsList.add(data); } } if (unTagsList.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return unTagsList; }  }
TaggingServiceImpl implements TaggingService, Constants { public List<Map<String, Object>> getUntaggingByTargetTypes(UntaggedTargetTypeRequest request) throws ServiceException { long assetCount ; long untaggedCount ; long taggedCount ; double compliancePercentage; String type; List<String> tagsList = new ArrayList<>(Arrays.asList(mandatoryTags.split(","))); List<Map<String, Object>> targetTypes; try { targetTypes = repository.getRuleTargetTypesFromDbByPolicyId(TAGGIG_POLICY); } catch (DataException e) { throw new ServiceException(e); } if (targetTypes.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } Map<String, String> filterTags = request.getFilter(); List<Map<String, Object>> unTagsList = new ArrayList<>(); Map<String, Long> assetCountByTypes = complainceRepository.getTotalAssetCount(request.getAg(), null,null,null); Map<String, Long> untaggedCountMap = getUntaggedTargetTypeIssues(request, tagsList); for (Map<String, Object> targetType : targetTypes) { type = targetType.get(TARGET_TYPE).toString(); Map<String, Object> data = new HashMap<>(); if (null != filterTags && !filterTags.isEmpty() && !filterTags.get(TARGET_TYPE).isEmpty() && (!type.equalsIgnoreCase(filterTags.get(TARGET_TYPE)))) { continue; } assetCount = (null != assetCountByTypes.get(type)) ? Long.parseLong(assetCountByTypes.get(type).toString()) : 0l; if (assetCount > 0) { untaggedCount = getUntaggedAsset(untaggedCountMap, type); if (untaggedCount > assetCount) { untaggedCount = assetCount; } taggedCount = assetCount - untaggedCount; compliancePercentage = (double) (taggedCount * INT_HUNDRED) / assetCount; compliancePercentage = Math.floor(compliancePercentage); data.put("name", type); data.put("untagged", untaggedCount); data.put("tagged", taggedCount); data.put("assetCount", assetCount); data.put(COMP_PERCENTAGE, compliancePercentage); unTagsList.add(data); } } if (unTagsList.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return unTagsList; }  @Override ResponseWithCount getUnTaggedAssetsByApplication(Request request); Map<String, Object> getTaggingSummary(String assetGroup); List<Map<String, Object>> getUntaggingByTargetTypes(UntaggedTargetTypeRequest request); @Override List<Map<String, Long>> taggingByApplication(String assetGroup, String targetType); }
TaggingServiceImpl implements TaggingService, Constants { public List<Map<String, Object>> getUntaggingByTargetTypes(UntaggedTargetTypeRequest request) throws ServiceException { long assetCount ; long untaggedCount ; long taggedCount ; double compliancePercentage; String type; List<String> tagsList = new ArrayList<>(Arrays.asList(mandatoryTags.split(","))); List<Map<String, Object>> targetTypes; try { targetTypes = repository.getRuleTargetTypesFromDbByPolicyId(TAGGIG_POLICY); } catch (DataException e) { throw new ServiceException(e); } if (targetTypes.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } Map<String, String> filterTags = request.getFilter(); List<Map<String, Object>> unTagsList = new ArrayList<>(); Map<String, Long> assetCountByTypes = complainceRepository.getTotalAssetCount(request.getAg(), null,null,null); Map<String, Long> untaggedCountMap = getUntaggedTargetTypeIssues(request, tagsList); for (Map<String, Object> targetType : targetTypes) { type = targetType.get(TARGET_TYPE).toString(); Map<String, Object> data = new HashMap<>(); if (null != filterTags && !filterTags.isEmpty() && !filterTags.get(TARGET_TYPE).isEmpty() && (!type.equalsIgnoreCase(filterTags.get(TARGET_TYPE)))) { continue; } assetCount = (null != assetCountByTypes.get(type)) ? Long.parseLong(assetCountByTypes.get(type).toString()) : 0l; if (assetCount > 0) { untaggedCount = getUntaggedAsset(untaggedCountMap, type); if (untaggedCount > assetCount) { untaggedCount = assetCount; } taggedCount = assetCount - untaggedCount; compliancePercentage = (double) (taggedCount * INT_HUNDRED) / assetCount; compliancePercentage = Math.floor(compliancePercentage); data.put("name", type); data.put("untagged", untaggedCount); data.put("tagged", taggedCount); data.put("assetCount", assetCount); data.put(COMP_PERCENTAGE, compliancePercentage); unTagsList.add(data); } } if (unTagsList.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return unTagsList; }  @Override ResponseWithCount getUnTaggedAssetsByApplication(Request request); Map<String, Object> getTaggingSummary(String assetGroup); List<Map<String, Object>> getUntaggingByTargetTypes(UntaggedTargetTypeRequest request); @Override List<Map<String, Long>> taggingByApplication(String assetGroup, String targetType);  }