@Test public void test_Should_Create_NonMeterWaterRates() { final NonMeterWaterRatesReq nonMeterWaterRatesReq = new NonMeterWaterRatesReq(); final RequestInfo requestInfo = new RequestInfo(); final User user = new User(); user.setId(1l); requestInfo.setUserInfo(user); nonMeterWaterRatesReq.setRequestInfo(requestInfo); final List<NonMeterWaterRates> nonMeterWaterRatesList = new ArrayList<>(); final NonMeterWaterRates nonMeterWaterRates = getNonMeterWaterRates(); nonMeterWaterRatesList.add(nonMeterWaterRates); nonMeterWaterRatesReq.setNonMeterWaterRates(nonMeterWaterRatesList); final NonMeterWaterRatesReq nonMeterWaterRatesRequest = nonMeterWaterRatesRepository .create(nonMeterWaterRatesReq); when(namedParameterJdbcTemplate.queryForObject(any(String.class), anyMap(), eq(Long.class))).thenReturn(2L); assertThat(nonMeterWaterRatesRequest.getNonMeterWaterRates().size()).isEqualTo(1); }
public NonMeterWaterRatesReq create(final NonMeterWaterRatesReq nonMeterWaterRatesReq) { log.info("NonMeterWaterRatesReq::" + nonMeterWaterRatesReq); final String nonMeterWaterRatesInsertQuery = NonMeterWaterRatesQueryBuilder.insertNonMeterWaterRatesQuery(); final String pipesizeQuery = NonMeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(); final String sourcetypeQuery = NonMeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(); final List<NonMeterWaterRates> nonMeterWaterRatesList = nonMeterWaterRatesReq.getNonMeterWaterRates(); final List<Map<String, Object>> batchValues = new ArrayList<>(nonMeterWaterRatesList.size()); final Map<String, Object> batchArguments = new HashMap<>(); for (final NonMeterWaterRates nonMeterWaterRates : nonMeterWaterRatesList) { Long pipesizeId = 0L; try { batchArguments.put("sizeinmilimeter", nonMeterWaterRates.getPipeSize()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); pipesizeId = namedParameterJdbcTemplate.queryForObject(pipesizeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (pipesizeId == null) log.info("Invalid input."); Long sourcetypeId = 0L; try { batchArguments.put("name", nonMeterWaterRates.getSourceTypeName()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); sourcetypeId = namedParameterJdbcTemplate.queryForObject(sourcetypeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (sourcetypeId == null) log.info("Invalid input."); batchValues.add( new MapSqlParameterSource("id", Long.valueOf(nonMeterWaterRates.getCode())) .addValue("code", nonMeterWaterRates.getCode()) .addValue("billingtype", nonMeterWaterRates.getBillingType()) .addValue("connectiontype", nonMeterWaterRates.getConnectionType()) .addValue("usagetypeid", nonMeterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", nonMeterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", nonMeterWaterRates.getOutsideUlb()) .addValue("sourcetypeid", sourcetypeId).addValue("pipesizeid", pipesizeId) .addValue("fromdate", nonMeterWaterRates.getFromDate()) .addValue("amount", nonMeterWaterRates.getAmount()).addValue("active", nonMeterWaterRates.getActive()) .addValue("nooftaps", nonMeterWaterRates.getNoOfTaps()) .addValue("createdby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new java.util.Date().getTime()) .addValue("lastmodifieddate", new java.util.Date().getTime()) .addValue("tenantid", nonMeterWaterRates.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(nonMeterWaterRatesInsertQuery, batchValues.toArray(new Map[nonMeterWaterRatesList.size()])); return nonMeterWaterRatesReq; }
NonMeterWaterRatesRepository { public NonMeterWaterRatesReq create(final NonMeterWaterRatesReq nonMeterWaterRatesReq) { log.info("NonMeterWaterRatesReq::" + nonMeterWaterRatesReq); final String nonMeterWaterRatesInsertQuery = NonMeterWaterRatesQueryBuilder.insertNonMeterWaterRatesQuery(); final String pipesizeQuery = NonMeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(); final String sourcetypeQuery = NonMeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(); final List<NonMeterWaterRates> nonMeterWaterRatesList = nonMeterWaterRatesReq.getNonMeterWaterRates(); final List<Map<String, Object>> batchValues = new ArrayList<>(nonMeterWaterRatesList.size()); final Map<String, Object> batchArguments = new HashMap<>(); for (final NonMeterWaterRates nonMeterWaterRates : nonMeterWaterRatesList) { Long pipesizeId = 0L; try { batchArguments.put("sizeinmilimeter", nonMeterWaterRates.getPipeSize()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); pipesizeId = namedParameterJdbcTemplate.queryForObject(pipesizeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (pipesizeId == null) log.info("Invalid input."); Long sourcetypeId = 0L; try { batchArguments.put("name", nonMeterWaterRates.getSourceTypeName()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); sourcetypeId = namedParameterJdbcTemplate.queryForObject(sourcetypeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (sourcetypeId == null) log.info("Invalid input."); batchValues.add( new MapSqlParameterSource("id", Long.valueOf(nonMeterWaterRates.getCode())) .addValue("code", nonMeterWaterRates.getCode()) .addValue("billingtype", nonMeterWaterRates.getBillingType()) .addValue("connectiontype", nonMeterWaterRates.getConnectionType()) .addValue("usagetypeid", nonMeterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", nonMeterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", nonMeterWaterRates.getOutsideUlb()) .addValue("sourcetypeid", sourcetypeId).addValue("pipesizeid", pipesizeId) .addValue("fromdate", nonMeterWaterRates.getFromDate()) .addValue("amount", nonMeterWaterRates.getAmount()).addValue("active", nonMeterWaterRates.getActive()) .addValue("nooftaps", nonMeterWaterRates.getNoOfTaps()) .addValue("createdby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new java.util.Date().getTime()) .addValue("lastmodifieddate", new java.util.Date().getTime()) .addValue("tenantid", nonMeterWaterRates.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(nonMeterWaterRatesInsertQuery, batchValues.toArray(new Map[nonMeterWaterRatesList.size()])); return nonMeterWaterRatesReq; } }
NonMeterWaterRatesRepository { public NonMeterWaterRatesReq create(final NonMeterWaterRatesReq nonMeterWaterRatesReq) { log.info("NonMeterWaterRatesReq::" + nonMeterWaterRatesReq); final String nonMeterWaterRatesInsertQuery = NonMeterWaterRatesQueryBuilder.insertNonMeterWaterRatesQuery(); final String pipesizeQuery = NonMeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(); final String sourcetypeQuery = NonMeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(); final List<NonMeterWaterRates> nonMeterWaterRatesList = nonMeterWaterRatesReq.getNonMeterWaterRates(); final List<Map<String, Object>> batchValues = new ArrayList<>(nonMeterWaterRatesList.size()); final Map<String, Object> batchArguments = new HashMap<>(); for (final NonMeterWaterRates nonMeterWaterRates : nonMeterWaterRatesList) { Long pipesizeId = 0L; try { batchArguments.put("sizeinmilimeter", nonMeterWaterRates.getPipeSize()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); pipesizeId = namedParameterJdbcTemplate.queryForObject(pipesizeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (pipesizeId == null) log.info("Invalid input."); Long sourcetypeId = 0L; try { batchArguments.put("name", nonMeterWaterRates.getSourceTypeName()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); sourcetypeId = namedParameterJdbcTemplate.queryForObject(sourcetypeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (sourcetypeId == null) log.info("Invalid input."); batchValues.add( new MapSqlParameterSource("id", Long.valueOf(nonMeterWaterRates.getCode())) .addValue("code", nonMeterWaterRates.getCode()) .addValue("billingtype", nonMeterWaterRates.getBillingType()) .addValue("connectiontype", nonMeterWaterRates.getConnectionType()) .addValue("usagetypeid", nonMeterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", nonMeterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", nonMeterWaterRates.getOutsideUlb()) .addValue("sourcetypeid", sourcetypeId).addValue("pipesizeid", pipesizeId) .addValue("fromdate", nonMeterWaterRates.getFromDate()) .addValue("amount", nonMeterWaterRates.getAmount()).addValue("active", nonMeterWaterRates.getActive()) .addValue("nooftaps", nonMeterWaterRates.getNoOfTaps()) .addValue("createdby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new java.util.Date().getTime()) .addValue("lastmodifieddate", new java.util.Date().getTime()) .addValue("tenantid", nonMeterWaterRates.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(nonMeterWaterRatesInsertQuery, batchValues.toArray(new Map[nonMeterWaterRatesList.size()])); return nonMeterWaterRatesReq; }  }
NonMeterWaterRatesRepository { public NonMeterWaterRatesReq create(final NonMeterWaterRatesReq nonMeterWaterRatesReq) { log.info("NonMeterWaterRatesReq::" + nonMeterWaterRatesReq); final String nonMeterWaterRatesInsertQuery = NonMeterWaterRatesQueryBuilder.insertNonMeterWaterRatesQuery(); final String pipesizeQuery = NonMeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(); final String sourcetypeQuery = NonMeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(); final List<NonMeterWaterRates> nonMeterWaterRatesList = nonMeterWaterRatesReq.getNonMeterWaterRates(); final List<Map<String, Object>> batchValues = new ArrayList<>(nonMeterWaterRatesList.size()); final Map<String, Object> batchArguments = new HashMap<>(); for (final NonMeterWaterRates nonMeterWaterRates : nonMeterWaterRatesList) { Long pipesizeId = 0L; try { batchArguments.put("sizeinmilimeter", nonMeterWaterRates.getPipeSize()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); pipesizeId = namedParameterJdbcTemplate.queryForObject(pipesizeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (pipesizeId == null) log.info("Invalid input."); Long sourcetypeId = 0L; try { batchArguments.put("name", nonMeterWaterRates.getSourceTypeName()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); sourcetypeId = namedParameterJdbcTemplate.queryForObject(sourcetypeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (sourcetypeId == null) log.info("Invalid input."); batchValues.add( new MapSqlParameterSource("id", Long.valueOf(nonMeterWaterRates.getCode())) .addValue("code", nonMeterWaterRates.getCode()) .addValue("billingtype", nonMeterWaterRates.getBillingType()) .addValue("connectiontype", nonMeterWaterRates.getConnectionType()) .addValue("usagetypeid", nonMeterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", nonMeterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", nonMeterWaterRates.getOutsideUlb()) .addValue("sourcetypeid", sourcetypeId).addValue("pipesizeid", pipesizeId) .addValue("fromdate", nonMeterWaterRates.getFromDate()) .addValue("amount", nonMeterWaterRates.getAmount()).addValue("active", nonMeterWaterRates.getActive()) .addValue("nooftaps", nonMeterWaterRates.getNoOfTaps()) .addValue("createdby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new java.util.Date().getTime()) .addValue("lastmodifieddate", new java.util.Date().getTime()) .addValue("tenantid", nonMeterWaterRates.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(nonMeterWaterRatesInsertQuery, batchValues.toArray(new Map[nonMeterWaterRatesList.size()])); return nonMeterWaterRatesReq; }  NonMeterWaterRatesReq create(final NonMeterWaterRatesReq nonMeterWaterRatesReq); NonMeterWaterRatesReq update(final NonMeterWaterRatesReq nonMeterWaterRatesReq); List<NonMeterWaterRates> findForCriteria(final NonMeterWaterRatesGetReq nonMeterWaterRatesGetRequest); boolean checkNonMeterWaterRatesExists(final String code, final String connectionType, final Long usageTypeId,
            final Long subUsageTypeId, final String sourceTypeName, final Double pipeSize, final Long fromDate,
            final String tenantId); boolean checkPipeSizeExists(final Double pipeSize, final String tenantId); boolean checkSourceTypeExists(final String sourceTypeName, final String tenantId); Map<String, Object> checkUsageAndSubUsageTypeExists(final String usageType, final String tenantId); }
NonMeterWaterRatesRepository { public NonMeterWaterRatesReq create(final NonMeterWaterRatesReq nonMeterWaterRatesReq) { log.info("NonMeterWaterRatesReq::" + nonMeterWaterRatesReq); final String nonMeterWaterRatesInsertQuery = NonMeterWaterRatesQueryBuilder.insertNonMeterWaterRatesQuery(); final String pipesizeQuery = NonMeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(); final String sourcetypeQuery = NonMeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(); final List<NonMeterWaterRates> nonMeterWaterRatesList = nonMeterWaterRatesReq.getNonMeterWaterRates(); final List<Map<String, Object>> batchValues = new ArrayList<>(nonMeterWaterRatesList.size()); final Map<String, Object> batchArguments = new HashMap<>(); for (final NonMeterWaterRates nonMeterWaterRates : nonMeterWaterRatesList) { Long pipesizeId = 0L; try { batchArguments.put("sizeinmilimeter", nonMeterWaterRates.getPipeSize()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); pipesizeId = namedParameterJdbcTemplate.queryForObject(pipesizeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (pipesizeId == null) log.info("Invalid input."); Long sourcetypeId = 0L; try { batchArguments.put("name", nonMeterWaterRates.getSourceTypeName()); batchArguments.put("tenantId", nonMeterWaterRates.getTenantId()); sourcetypeId = namedParameterJdbcTemplate.queryForObject(sourcetypeQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } if (sourcetypeId == null) log.info("Invalid input."); batchValues.add( new MapSqlParameterSource("id", Long.valueOf(nonMeterWaterRates.getCode())) .addValue("code", nonMeterWaterRates.getCode()) .addValue("billingtype", nonMeterWaterRates.getBillingType()) .addValue("connectiontype", nonMeterWaterRates.getConnectionType()) .addValue("usagetypeid", nonMeterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", nonMeterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", nonMeterWaterRates.getOutsideUlb()) .addValue("sourcetypeid", sourcetypeId).addValue("pipesizeid", pipesizeId) .addValue("fromdate", nonMeterWaterRates.getFromDate()) .addValue("amount", nonMeterWaterRates.getAmount()).addValue("active", nonMeterWaterRates.getActive()) .addValue("nooftaps", nonMeterWaterRates.getNoOfTaps()) .addValue("createdby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(nonMeterWaterRatesReq.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new java.util.Date().getTime()) .addValue("lastmodifieddate", new java.util.Date().getTime()) .addValue("tenantid", nonMeterWaterRates.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(nonMeterWaterRatesInsertQuery, batchValues.toArray(new Map[nonMeterWaterRatesList.size()])); return nonMeterWaterRatesReq; }  NonMeterWaterRatesReq create(final NonMeterWaterRatesReq nonMeterWaterRatesReq); NonMeterWaterRatesReq update(final NonMeterWaterRatesReq nonMeterWaterRatesReq); List<NonMeterWaterRates> findForCriteria(final NonMeterWaterRatesGetReq nonMeterWaterRatesGetRequest); boolean checkNonMeterWaterRatesExists(final String code, final String connectionType, final Long usageTypeId,
            final Long subUsageTypeId, final String sourceTypeName, final Double pipeSize, final Long fromDate,
            final String tenantId); boolean checkPipeSizeExists(final Double pipeSize, final String tenantId); boolean checkSourceTypeExists(final String sourceTypeName, final String tenantId); Map<String, Object> checkUsageAndSubUsageTypeExists(final String usageType, final String tenantId);  }