class ProjectionRepositoryImpl implements ProjectionRepository, Constants {

    @Override
    public Boolean updateProjectionByTargetType(ProjectionRequest projectionRequest) throws DataException {
        String resourceType = projectionRequest.getResourceType();
        int year = projectionRequest.getYear();
        int quarter = projectionRequest.getQuarter();
        List<Map<String, Object>> projectionByweeksList = projectionRequest.getProjectionByWeek();
        boolean isUpdated = false;
        List<String> insertValuesList = new ArrayList<>();
        List<String> deleteValuesList = new ArrayList<>();
        List<LocalDate> lastDayOfEachWeek = getListOfLastWeekDateOfQuarter();

        if (lastDayOfEachWeek.size() == projectionByweeksList.size()) {
            projectionByweeksList.parallelStream().forEach(
                    projectionByWeek -> {
                        int week = 0;
                        long projection = 0;
                        if (projectionByWeek.containsKey("week")) {
                            week = Integer.parseInt(projectionByWeek.get("week").toString());

                        }
                        if (projectionByWeek.containsKey("projection")) {
                            projection = Long.parseLong(projectionByWeek.get("projection").toString());
                        }
                        StringBuilder deleteValue = new StringBuilder("(").append("'" + year + "'")
                                .append("," + "'" + quarter + "'").append("," + "'" + week + "'").append(")");
                        StringBuilder insertValue = new StringBuilder("(").append("'" + resourceType + "'")
                                .append("," + "'" + year + "'").append("," + "'" + quarter + "'")
                                .append("," + "'" + week + "'").append("," + "'" + projection + "'").append(")");

                        synchronized (deleteValuesList) {
                            deleteValuesList.add(deleteValue.toString());
                        }
                        synchronized (insertValuesList) {
                            insertValuesList.add(insertValue.toString());
                        }

                    });
            StringBuilder insertQuery = new StringBuilder(
                    "INSERT INTO pac_v2_projections ( resourcetype,year,quarter,week,projection) VALUES ");
            insertQuery.append(String.join(",", insertValuesList));
            StringBuilder deleteQuery = new StringBuilder("DELETE FROM pac_v2_projections WHERE resourceType = '"
                    + resourceType + "' AND " + "( year,quarter,week) IN");
            deleteQuery.append("(").append(String.join(",", deleteValuesList)).append(")");
            rdsRepository.executeQuery(deleteQuery.toString());
            int[] count = rdsRepository.executeQuery(insertQuery.toString());
            if (count[0] > 0) {
                isUpdated = true;
            }
        } else {
            throw new DataException("Please enter correct no of weeks for the quarter");
        }

        return isUpdated;
    }

}