@Test public void getStarRatingForAgPatchingTest() throws Exception{ List<Map<String,Object>> patchingList1 = new ArrayList<>(); Map<String,Object> patchingMap1 = new HashMap<String, Object>(); patchingMap1.put("date", "2018-03-31"); patchingMap1.put("ag", "aws-all"); patchingMap1.put("patching_percentage", "100"); Map<String,Object> patchingMap2 = new HashMap<String, Object>(); patchingMap2.put("date", "2018-02-24"); patchingMap2.put("ag", "aws-all"); patchingMap2.put("patching_percentage", "100"); Map<String,Object> patchingMap3 = new HashMap<String, Object>(); patchingMap3.put("date", "2018-01-28"); patchingMap3.put("ag", "aws-all"); patchingMap3.put("patching_percentage", "100"); patchingList1.add(patchingMap1); patchingList1.add(patchingMap2); patchingList1.add(patchingMap3); when(repository.getPatchingPercentForDateRange(anyString(), anyObject(), anyObject())).thenReturn(patchingList1); when(repository.getAmilAvailDate(anyInt(), anyInt())).thenReturn("2018-01-01"); Medal medal = patchingServiceImpl.getStarRatingForAgPatching("aws-all", 1, 2018); assertTrue(medal.getMedalType().equals("GOLD")); patchingMap3.put("patching_percentage", 80); medal = patchingServiceImpl.getStarRatingForAgPatching("aws-all", 1, 2018); assertTrue(medal.getMedalType().equals("SILVER")); patchingMap2.put("patching_percentage", 100); patchingMap1.put("patching_percentage", 90); medal = patchingServiceImpl.getStarRatingForAgPatching("aws-all", 1, 2018); assertTrue(medal.getMedalType().equals("BRONZE")); patchingMap3.put("patching_percentage", 80); patchingMap2.put("patching_percentage", 80); patchingMap1.put("patching_percentage", 100); medal = patchingServiceImpl.getStarRatingForAgPatching("aws-all", 1, 2018); assertTrue(medal.getMedalType().equals("BRONZE")); patchingMap3.put("patching_percentage", 80); patchingMap2.put("patching_percentage", 80); patchingMap1.put("patching_percentage", 80); medal = patchingServiceImpl.getStarRatingForAgPatching("aws-all", 1, 2018); assertTrue(medal.getMedalType().equals("")); assertTrue(medal.getMedalStatus().equals("")); patchingMap3.put("patching_percentage", 100); patchingMap3.put("date", "2018-08-10"); patchingMap2.put("patching_percentage", 100); patchingMap2.put("date", "2018-08-11"); patchingMap1.put("patching_percentage", 100); patchingMap1.put("date", "2018-08-12"); medal = patchingServiceImpl.getStarRatingForAgPatching("aws-all", 3, 2018); assertNotNull(medal.getMedalStatus()); }
@Override public Medal getStarRatingForAgPatching(String ag, int quarter, int year) { LocalDate firstDay = LocalDate.parse(repository.getAmilAvailDate(year, quarter)); LocalDate lastDay = getLastDayOfQuarter(quarter, year); boolean incompleteQuarter = false; if (lastDay.isAfter(LocalDate.now())) { lastDay = LocalDate.now(); incompleteQuarter = true; } List<Map<String, Object>> ratingList = repository.getPatchingPercentForDateRange(ag, firstDay, lastDay); List<Map<String, Object>> filteredRatingList = new ArrayList<Map<String, Object>>(); ratingList.forEach(rateMap -> { if (ag.equals(rateMap.get("ag"))) { filteredRatingList.add(rateMap); } }); Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate .parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo(LocalDate.parse(m1.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(filteredRatingList, comp); List<String> patchingPercentFor45Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor45Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<45)) { patchingPercentFor45Days.add(rateMap.get("patching_percentage").toString()); } }); List<String> patchingPercentFor60Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor60Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<60)) { patchingPercentFor60Days.add(rateMap.get("patching_percentage").toString()); } }); Medal patchingMedal = new Medal(); patchingMedal.setMedalType(""); patchingMedal.setMedalStatus(""); double patchingPercentValueFor45Days = patchingPercentFor45Days.isEmpty()?0:Double.parseDouble(patchingPercentFor45Days.get(0)); double patchingPercentValueFor60Days = patchingPercentFor60Days.isEmpty()?0:Double.parseDouble(patchingPercentFor60Days.get(0)); double lastDatePatchingPercentValue = filteredRatingList.isEmpty()?0:Double.parseDouble(filteredRatingList.get(0).get("patching_percentage").toString()); if(incompleteQuarter) { patchingMedal.setMedalStatus("Pending"); if(patchingPercentValueFor45Days>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor60Days>=100) { patchingMedal.setMedalType("SILVER"); } }else { patchingMedal.setMedalStatus("Confirmed"); if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("BRONZE"); }else if(lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("BRONZE"); }else { patchingMedal.setMedalStatus(""); } } return patchingMedal; }
PatchingServiceImpl implements PatchingService, Constants { @Override public Medal getStarRatingForAgPatching(String ag, int quarter, int year) { LocalDate firstDay = LocalDate.parse(repository.getAmilAvailDate(year, quarter)); LocalDate lastDay = getLastDayOfQuarter(quarter, year); boolean incompleteQuarter = false; if (lastDay.isAfter(LocalDate.now())) { lastDay = LocalDate.now(); incompleteQuarter = true; } List<Map<String, Object>> ratingList = repository.getPatchingPercentForDateRange(ag, firstDay, lastDay); List<Map<String, Object>> filteredRatingList = new ArrayList<Map<String, Object>>(); ratingList.forEach(rateMap -> { if (ag.equals(rateMap.get("ag"))) { filteredRatingList.add(rateMap); } }); Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate .parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo(LocalDate.parse(m1.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(filteredRatingList, comp); List<String> patchingPercentFor45Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor45Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<45)) { patchingPercentFor45Days.add(rateMap.get("patching_percentage").toString()); } }); List<String> patchingPercentFor60Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor60Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<60)) { patchingPercentFor60Days.add(rateMap.get("patching_percentage").toString()); } }); Medal patchingMedal = new Medal(); patchingMedal.setMedalType(""); patchingMedal.setMedalStatus(""); double patchingPercentValueFor45Days = patchingPercentFor45Days.isEmpty()?0:Double.parseDouble(patchingPercentFor45Days.get(0)); double patchingPercentValueFor60Days = patchingPercentFor60Days.isEmpty()?0:Double.parseDouble(patchingPercentFor60Days.get(0)); double lastDatePatchingPercentValue = filteredRatingList.isEmpty()?0:Double.parseDouble(filteredRatingList.get(0).get("patching_percentage").toString()); if(incompleteQuarter) { patchingMedal.setMedalStatus("Pending"); if(patchingPercentValueFor45Days>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor60Days>=100) { patchingMedal.setMedalType("SILVER"); } }else { patchingMedal.setMedalStatus("Confirmed"); if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("BRONZE"); }else if(lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("BRONZE"); }else { patchingMedal.setMedalStatus(""); } } return patchingMedal; } }
PatchingServiceImpl implements PatchingService, Constants { @Override public Medal getStarRatingForAgPatching(String ag, int quarter, int year) { LocalDate firstDay = LocalDate.parse(repository.getAmilAvailDate(year, quarter)); LocalDate lastDay = getLastDayOfQuarter(quarter, year); boolean incompleteQuarter = false; if (lastDay.isAfter(LocalDate.now())) { lastDay = LocalDate.now(); incompleteQuarter = true; } List<Map<String, Object>> ratingList = repository.getPatchingPercentForDateRange(ag, firstDay, lastDay); List<Map<String, Object>> filteredRatingList = new ArrayList<Map<String, Object>>(); ratingList.forEach(rateMap -> { if (ag.equals(rateMap.get("ag"))) { filteredRatingList.add(rateMap); } }); Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate .parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo(LocalDate.parse(m1.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(filteredRatingList, comp); List<String> patchingPercentFor45Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor45Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<45)) { patchingPercentFor45Days.add(rateMap.get("patching_percentage").toString()); } }); List<String> patchingPercentFor60Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor60Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<60)) { patchingPercentFor60Days.add(rateMap.get("patching_percentage").toString()); } }); Medal patchingMedal = new Medal(); patchingMedal.setMedalType(""); patchingMedal.setMedalStatus(""); double patchingPercentValueFor45Days = patchingPercentFor45Days.isEmpty()?0:Double.parseDouble(patchingPercentFor45Days.get(0)); double patchingPercentValueFor60Days = patchingPercentFor60Days.isEmpty()?0:Double.parseDouble(patchingPercentFor60Days.get(0)); double lastDatePatchingPercentValue = filteredRatingList.isEmpty()?0:Double.parseDouble(filteredRatingList.get(0).get("patching_percentage").toString()); if(incompleteQuarter) { patchingMedal.setMedalStatus("Pending"); if(patchingPercentValueFor45Days>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor60Days>=100) { patchingMedal.setMedalType("SILVER"); } }else { patchingMedal.setMedalStatus("Confirmed"); if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("BRONZE"); }else if(lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("BRONZE"); }else { patchingMedal.setMedalStatus(""); } } return patchingMedal; }  }
PatchingServiceImpl implements PatchingService, Constants { @Override public Medal getStarRatingForAgPatching(String ag, int quarter, int year) { LocalDate firstDay = LocalDate.parse(repository.getAmilAvailDate(year, quarter)); LocalDate lastDay = getLastDayOfQuarter(quarter, year); boolean incompleteQuarter = false; if (lastDay.isAfter(LocalDate.now())) { lastDay = LocalDate.now(); incompleteQuarter = true; } List<Map<String, Object>> ratingList = repository.getPatchingPercentForDateRange(ag, firstDay, lastDay); List<Map<String, Object>> filteredRatingList = new ArrayList<Map<String, Object>>(); ratingList.forEach(rateMap -> { if (ag.equals(rateMap.get("ag"))) { filteredRatingList.add(rateMap); } }); Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate .parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo(LocalDate.parse(m1.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(filteredRatingList, comp); List<String> patchingPercentFor45Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor45Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<45)) { patchingPercentFor45Days.add(rateMap.get("patching_percentage").toString()); } }); List<String> patchingPercentFor60Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor60Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<60)) { patchingPercentFor60Days.add(rateMap.get("patching_percentage").toString()); } }); Medal patchingMedal = new Medal(); patchingMedal.setMedalType(""); patchingMedal.setMedalStatus(""); double patchingPercentValueFor45Days = patchingPercentFor45Days.isEmpty()?0:Double.parseDouble(patchingPercentFor45Days.get(0)); double patchingPercentValueFor60Days = patchingPercentFor60Days.isEmpty()?0:Double.parseDouble(patchingPercentFor60Days.get(0)); double lastDatePatchingPercentValue = filteredRatingList.isEmpty()?0:Double.parseDouble(filteredRatingList.get(0).get("patching_percentage").toString()); if(incompleteQuarter) { patchingMedal.setMedalStatus("Pending"); if(patchingPercentValueFor45Days>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor60Days>=100) { patchingMedal.setMedalType("SILVER"); } }else { patchingMedal.setMedalStatus("Confirmed"); if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("BRONZE"); }else if(lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("BRONZE"); }else { patchingMedal.setMedalStatus(""); } } return patchingMedal; }  @Override List<Map<String, Object>> getNonCompliantNumberForAG(
            String assetGroup); @Override List<Map<String, Object>> getNonCompliantExecsForAG(String assetGroup); @Override List<Map<String, Object>> getPatchingDetails(String assetGroup,
            Map<String, String> filter); @Override Map<String, Object> getPatchingProgress(String assetGroup, int year,
            int quarter); @Override List<Map<String, Object>> getQuartersWithPatchingData(
            String assetGroup); @Override LocalDate getFirstDayOfQuarter(int quarterNumber, int year); @Override LocalDate getLastDayOfQuarter(int quarterNumber, int year); @Override int getOngoingQuarter(); @Override int getOngoingYear(); @Override Object filterMatchingCollectionElements(
            List<Map<String, Object>> masterDetailList, String searchText,
            boolean b); @Override Medal getStarRatingForAgPatching(String ag, int quarter, int year); }
PatchingServiceImpl implements PatchingService, Constants { @Override public Medal getStarRatingForAgPatching(String ag, int quarter, int year) { LocalDate firstDay = LocalDate.parse(repository.getAmilAvailDate(year, quarter)); LocalDate lastDay = getLastDayOfQuarter(quarter, year); boolean incompleteQuarter = false; if (lastDay.isAfter(LocalDate.now())) { lastDay = LocalDate.now(); incompleteQuarter = true; } List<Map<String, Object>> ratingList = repository.getPatchingPercentForDateRange(ag, firstDay, lastDay); List<Map<String, Object>> filteredRatingList = new ArrayList<Map<String, Object>>(); ratingList.forEach(rateMap -> { if (ag.equals(rateMap.get("ag"))) { filteredRatingList.add(rateMap); } }); Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate .parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo(LocalDate.parse(m1.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(filteredRatingList, comp); List<String> patchingPercentFor45Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor45Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<45)) { patchingPercentFor45Days.add(rateMap.get("patching_percentage").toString()); } }); List<String> patchingPercentFor60Days = new ArrayList<>(); filteredRatingList.forEach(rateMap->{ LocalDate d = LocalDate.parse(rateMap.get("date").toString(), DateTimeFormatter.ISO_DATE); if((patchingPercentFor60Days.isEmpty()) && (ChronoUnit.DAYS.between(firstDay,d)<60)) { patchingPercentFor60Days.add(rateMap.get("patching_percentage").toString()); } }); Medal patchingMedal = new Medal(); patchingMedal.setMedalType(""); patchingMedal.setMedalStatus(""); double patchingPercentValueFor45Days = patchingPercentFor45Days.isEmpty()?0:Double.parseDouble(patchingPercentFor45Days.get(0)); double patchingPercentValueFor60Days = patchingPercentFor60Days.isEmpty()?0:Double.parseDouble(patchingPercentFor60Days.get(0)); double lastDatePatchingPercentValue = filteredRatingList.isEmpty()?0:Double.parseDouble(filteredRatingList.get(0).get("patching_percentage").toString()); if(incompleteQuarter) { patchingMedal.setMedalStatus("Pending"); if(patchingPercentValueFor45Days>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor60Days>=100) { patchingMedal.setMedalType("SILVER"); } }else { patchingMedal.setMedalStatus("Confirmed"); if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("GOLD"); }else if(patchingPercentValueFor45Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("SILVER"); }else if(patchingPercentValueFor60Days>=100 && lastDatePatchingPercentValue>=90) { patchingMedal.setMedalType("BRONZE"); }else if(lastDatePatchingPercentValue>=100) { patchingMedal.setMedalType("BRONZE"); }else { patchingMedal.setMedalStatus(""); } } return patchingMedal; }  @Override List<Map<String, Object>> getNonCompliantNumberForAG(
            String assetGroup); @Override List<Map<String, Object>> getNonCompliantExecsForAG(String assetGroup); @Override List<Map<String, Object>> getPatchingDetails(String assetGroup,
            Map<String, String> filter); @Override Map<String, Object> getPatchingProgress(String assetGroup, int year,
            int quarter); @Override List<Map<String, Object>> getQuartersWithPatchingData(
            String assetGroup); @Override LocalDate getFirstDayOfQuarter(int quarterNumber, int year); @Override LocalDate getLastDayOfQuarter(int quarterNumber, int year); @Override int getOngoingQuarter(); @Override int getOngoingYear(); @Override Object filterMatchingCollectionElements(
            List<Map<String, Object>> masterDetailList, String searchText,
            boolean b); @Override Medal getStarRatingForAgPatching(String ag, int quarter, int year);  }