class PatchingServiceImpl implements PatchingService, Constants {

    @Override
    public List<Map<String, Object>> getQuartersWithPatchingData(
            String assetGroup) throws ServiceException {
        Map<String, Long> patchingCountByQuarter;
        try {
            patchingCountByQuarter = repository
                    .getQuartersWithPatchingData(assetGroup);
        } catch (DataException e) {
            throw new ServiceException(e);
        }
        Map<Long, List<Long>> yearQuarterMap = new HashMap<>();

        patchingCountByQuarter.forEach((key, value) -> {
            LocalDateTime dateTime = LocalDateTime.parse(key,
                    DateTimeFormatter.ISO_DATE_TIME);

            LocalDate date = dateTime.toLocalDate();
            Long year = (long) date.getYear();
            List<Long> existingQuartersForCurrentYear = yearQuarterMap
                    .get(year);
            if (null == existingQuartersForCurrentYear) {
                existingQuartersForCurrentYear = new ArrayList<>();
                yearQuarterMap.put(year, existingQuartersForCurrentYear);
            }

            Long quarter = (long) (((date.getMonthValue() - 1) / THREE) + 1);
            existingQuartersForCurrentYear.add(quarter);

        });

        List<Map<String, Object>> listOfYears = new ArrayList<>();

        yearQuarterMap.forEach((key, value) -> {
            Map<String, Object> mapForCurrentYear = new HashMap<>();
            mapForCurrentYear.put("year", key);
            mapForCurrentYear.put("quarters", value);
            listOfYears.add(mapForCurrentYear);
        });
        if (listOfYears.isEmpty()) {
            throw new ServiceException(NO_DATA_FOUND);
        }
        return listOfYears;
    }

}