@Test public void updateProjectionByTargetTypeTest() throws Exception { List<LocalDate>numberofWeeks=projectionRepositoryImpl.getListOfLastWeekDateOfQuarter(); ProjectionRequest projectionRequest = new ProjectionRequest(); projectionRequest.setYear(2018); projectionRequest.setQuarter(2); List<Map<String, Object>> projectionByweeksList = new ArrayList<>(); Map<String, Object> projectionByweek = new HashMap<>(); for(int i=0;i<numberofWeeks.size();i++) { projectionByweek.put("week",i); projectionByweek.put("projection", 100); projectionByweeksList.add(projectionByweek); } projectionRequest.setProjectionByWeek(projectionByweeksList); int[] count = { 1 }; when(rdsRepository.executeQuery(anyString())).thenReturn(count); projectionRepositoryImpl.updateProjectionByTargetType(projectionRequest); int[] counttemp = { 0 }; when(rdsRepository.executeQuery(anyString())).thenReturn(counttemp); projectionRepositoryImpl.updateProjectionByTargetType(projectionRequest); ProjectionRequest projectionRequestTemp = new ProjectionRequest(); List<Map<String, Object>> projectionByweeksListTemp = new ArrayList<>(); for(int i=0;i<numberofWeeks.size();i++) { projectionByweek.put("weekdummy",i); projectionByweek.put("projectiondmmy", 100); projectionByweeksListTemp.add(projectionByweek); } projectionRequestTemp.setProjectionByWeek(projectionByweeksListTemp); projectionRepositoryImpl.updateProjectionByTargetType(projectionRequestTemp); projectionByweek.put("week",100); projectionByweek.put("projection", 100); projectionByweeksList.add(projectionByweek); assertThatThrownBy(() ->projectionRepositoryImpl.updateProjectionByTargetType(projectionRequest)).isInstanceOf( DataException.class); }
@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; }
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; } }
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; }  }
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; }  @Override Boolean updateProjectionByTargetType(ProjectionRequest projectionRequest); @Override List<Map<String, Object>> getProjectionDetailsFromDb(String targetType, int year, int quarter); @Override Long getTotalAssetCountByTargetType(String targetType); List<LocalDate> getListOfLastWeekDateOfQuarter(); int getWeekNoByDate(LocalDate date); @Override Map<Integer, Long> getPatchingSnapshot(String assetGroup); Map<String, Long> getUnPatchedDetailsByApplication(String assetGroup, String resourceType); Map<String, Long> getAssetDetailsByApplication(String assetGroup, String resourceType); Long getAssetCountByAg(String assetGroup, String resourceType); @SuppressWarnings("deprecation") List<Map<String, Object>> getAppsDetails(String appType); }
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; }  @Override Boolean updateProjectionByTargetType(ProjectionRequest projectionRequest); @Override List<Map<String, Object>> getProjectionDetailsFromDb(String targetType, int year, int quarter); @Override Long getTotalAssetCountByTargetType(String targetType); List<LocalDate> getListOfLastWeekDateOfQuarter(); int getWeekNoByDate(LocalDate date); @Override Map<Integer, Long> getPatchingSnapshot(String assetGroup); Map<String, Long> getUnPatchedDetailsByApplication(String assetGroup, String resourceType); Map<String, Long> getAssetDetailsByApplication(String assetGroup, String resourceType); Long getAssetCountByAg(String assetGroup, String resourceType); @SuppressWarnings("deprecation") List<Map<String, Object>> getAppsDetails(String appType);  }