@Test public void test_Should_Create_MeterWaterRates() { final MeterWaterRatesRequest meterWaterRatesRequest = new MeterWaterRatesRequest(); final RequestInfo requestInfo = new RequestInfo(); final User user = new User(); user.setId(1l); requestInfo.setUserInfo(user); meterWaterRatesRequest.setRequestInfo(requestInfo); final List<MeterWaterRates> meterWaterRatesList = new ArrayList<>(); final MeterWaterRates meterWaterRates = getMeterWaterRates(); meterWaterRatesList.add(meterWaterRates); meterWaterRatesRequest.setMeterWaterRates(meterWaterRatesList); final MeterWaterRatesRequest meterWaterRatesReq = meterWaterRatesRepository .create(meterWaterRatesRequest); when(namedParameterJdbcTemplate.queryForObject(any(String.class), anyMap(), eq(Long.class))).thenReturn(2L); assertThat(meterWaterRatesReq.getMeterWaterRates().size()).isEqualTo(1); }
public MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest) { log.info("MeterWaterRatesRequest::" + meterWaterRatesRequest); final String meterWaterRatesInsertQuery = MeterWaterRatesQueryBuilder.insertMeterWaterRatesQuery(); final String pipesizeQuery = MeterWaterRatesQueryBuilder.getPipeSizeIdQuery(); final String sourcetypeQuery = MeterWaterRatesQueryBuilder.getSourceTypeIdQuery(); final List<MeterWaterRates> meterWaterRatesList = meterWaterRatesRequest.getMeterWaterRates(); final List<Slab> slabs = new ArrayList<>(); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) slabs.addAll(meterWaterRate.getSlab()); final String slabInsertQuery = MeterWaterRatesQueryBuilder.insertSlabQuery(); final List<Map<String, Object>> batchValuesSlab = new ArrayList<>(slabs.size()); final List<Map<String, Object>> batchValues = new ArrayList<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRates : meterWaterRatesList) { Long pipesizeId = 0L; try { pipesizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { meterWaterRates.getPipeSize(), meterWaterRates.getTenantId() }, 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 { sourcetypeId = jdbcTemplate.queryForObject(sourcetypeQuery, new Object[] { meterWaterRates.getSourceTypeName(), meterWaterRates.getTenantId() }, 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(meterWaterRates.getCode())) .addValue("code", meterWaterRates.getCode()) .addValue("billingtype", meterWaterRates.getBillingType()) .addValue("usagetypeid", meterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", meterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", meterWaterRates.getOutsideUlb()).addValue("sourcetypeid", sourcetypeId) .addValue("pipesizeid", pipesizeId).addValue("fromdate", meterWaterRates.getFromDate()) .addValue("todate", meterWaterRates.getToDate()).addValue("active", meterWaterRates.getActive()) .addValue("createdby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); final List<Slab> slabList = meterWaterRates.getSlab(); if (slabList != null && !slabList.isEmpty()) { log.info("the insert query for slab : " + slabInsertQuery); for (final Slab slab : slabList) batchValuesSlab .add(new MapSqlParameterSource("meterwaterratesid", Long.valueOf(meterWaterRates.getCode())) .addValue("fromunit", slab.getFromUnit()).addValue("tounit", slab.getToUnit()) .addValue("unitrate", slab.getUnitRate()) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); } } namedParameterJdbcTemplate.batchUpdate(meterWaterRatesInsertQuery, batchValues.toArray(new Map[meterWaterRatesList.size()])); namedParameterJdbcTemplate.batchUpdate(slabInsertQuery, batchValuesSlab.toArray(new Map[slabs.size()])); return meterWaterRatesRequest; }
MeterWaterRatesRepository { public MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest) { log.info("MeterWaterRatesRequest::" + meterWaterRatesRequest); final String meterWaterRatesInsertQuery = MeterWaterRatesQueryBuilder.insertMeterWaterRatesQuery(); final String pipesizeQuery = MeterWaterRatesQueryBuilder.getPipeSizeIdQuery(); final String sourcetypeQuery = MeterWaterRatesQueryBuilder.getSourceTypeIdQuery(); final List<MeterWaterRates> meterWaterRatesList = meterWaterRatesRequest.getMeterWaterRates(); final List<Slab> slabs = new ArrayList<>(); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) slabs.addAll(meterWaterRate.getSlab()); final String slabInsertQuery = MeterWaterRatesQueryBuilder.insertSlabQuery(); final List<Map<String, Object>> batchValuesSlab = new ArrayList<>(slabs.size()); final List<Map<String, Object>> batchValues = new ArrayList<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRates : meterWaterRatesList) { Long pipesizeId = 0L; try { pipesizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { meterWaterRates.getPipeSize(), meterWaterRates.getTenantId() }, 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 { sourcetypeId = jdbcTemplate.queryForObject(sourcetypeQuery, new Object[] { meterWaterRates.getSourceTypeName(), meterWaterRates.getTenantId() }, 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(meterWaterRates.getCode())) .addValue("code", meterWaterRates.getCode()) .addValue("billingtype", meterWaterRates.getBillingType()) .addValue("usagetypeid", meterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", meterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", meterWaterRates.getOutsideUlb()).addValue("sourcetypeid", sourcetypeId) .addValue("pipesizeid", pipesizeId).addValue("fromdate", meterWaterRates.getFromDate()) .addValue("todate", meterWaterRates.getToDate()).addValue("active", meterWaterRates.getActive()) .addValue("createdby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); final List<Slab> slabList = meterWaterRates.getSlab(); if (slabList != null && !slabList.isEmpty()) { log.info("the insert query for slab : " + slabInsertQuery); for (final Slab slab : slabList) batchValuesSlab .add(new MapSqlParameterSource("meterwaterratesid", Long.valueOf(meterWaterRates.getCode())) .addValue("fromunit", slab.getFromUnit()).addValue("tounit", slab.getToUnit()) .addValue("unitrate", slab.getUnitRate()) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); } } namedParameterJdbcTemplate.batchUpdate(meterWaterRatesInsertQuery, batchValues.toArray(new Map[meterWaterRatesList.size()])); namedParameterJdbcTemplate.batchUpdate(slabInsertQuery, batchValuesSlab.toArray(new Map[slabs.size()])); return meterWaterRatesRequest; } }
MeterWaterRatesRepository { public MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest) { log.info("MeterWaterRatesRequest::" + meterWaterRatesRequest); final String meterWaterRatesInsertQuery = MeterWaterRatesQueryBuilder.insertMeterWaterRatesQuery(); final String pipesizeQuery = MeterWaterRatesQueryBuilder.getPipeSizeIdQuery(); final String sourcetypeQuery = MeterWaterRatesQueryBuilder.getSourceTypeIdQuery(); final List<MeterWaterRates> meterWaterRatesList = meterWaterRatesRequest.getMeterWaterRates(); final List<Slab> slabs = new ArrayList<>(); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) slabs.addAll(meterWaterRate.getSlab()); final String slabInsertQuery = MeterWaterRatesQueryBuilder.insertSlabQuery(); final List<Map<String, Object>> batchValuesSlab = new ArrayList<>(slabs.size()); final List<Map<String, Object>> batchValues = new ArrayList<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRates : meterWaterRatesList) { Long pipesizeId = 0L; try { pipesizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { meterWaterRates.getPipeSize(), meterWaterRates.getTenantId() }, 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 { sourcetypeId = jdbcTemplate.queryForObject(sourcetypeQuery, new Object[] { meterWaterRates.getSourceTypeName(), meterWaterRates.getTenantId() }, 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(meterWaterRates.getCode())) .addValue("code", meterWaterRates.getCode()) .addValue("billingtype", meterWaterRates.getBillingType()) .addValue("usagetypeid", meterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", meterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", meterWaterRates.getOutsideUlb()).addValue("sourcetypeid", sourcetypeId) .addValue("pipesizeid", pipesizeId).addValue("fromdate", meterWaterRates.getFromDate()) .addValue("todate", meterWaterRates.getToDate()).addValue("active", meterWaterRates.getActive()) .addValue("createdby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); final List<Slab> slabList = meterWaterRates.getSlab(); if (slabList != null && !slabList.isEmpty()) { log.info("the insert query for slab : " + slabInsertQuery); for (final Slab slab : slabList) batchValuesSlab .add(new MapSqlParameterSource("meterwaterratesid", Long.valueOf(meterWaterRates.getCode())) .addValue("fromunit", slab.getFromUnit()).addValue("tounit", slab.getToUnit()) .addValue("unitrate", slab.getUnitRate()) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); } } namedParameterJdbcTemplate.batchUpdate(meterWaterRatesInsertQuery, batchValues.toArray(new Map[meterWaterRatesList.size()])); namedParameterJdbcTemplate.batchUpdate(slabInsertQuery, batchValuesSlab.toArray(new Map[slabs.size()])); return meterWaterRatesRequest; }  }
MeterWaterRatesRepository { public MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest) { log.info("MeterWaterRatesRequest::" + meterWaterRatesRequest); final String meterWaterRatesInsertQuery = MeterWaterRatesQueryBuilder.insertMeterWaterRatesQuery(); final String pipesizeQuery = MeterWaterRatesQueryBuilder.getPipeSizeIdQuery(); final String sourcetypeQuery = MeterWaterRatesQueryBuilder.getSourceTypeIdQuery(); final List<MeterWaterRates> meterWaterRatesList = meterWaterRatesRequest.getMeterWaterRates(); final List<Slab> slabs = new ArrayList<>(); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) slabs.addAll(meterWaterRate.getSlab()); final String slabInsertQuery = MeterWaterRatesQueryBuilder.insertSlabQuery(); final List<Map<String, Object>> batchValuesSlab = new ArrayList<>(slabs.size()); final List<Map<String, Object>> batchValues = new ArrayList<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRates : meterWaterRatesList) { Long pipesizeId = 0L; try { pipesizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { meterWaterRates.getPipeSize(), meterWaterRates.getTenantId() }, 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 { sourcetypeId = jdbcTemplate.queryForObject(sourcetypeQuery, new Object[] { meterWaterRates.getSourceTypeName(), meterWaterRates.getTenantId() }, 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(meterWaterRates.getCode())) .addValue("code", meterWaterRates.getCode()) .addValue("billingtype", meterWaterRates.getBillingType()) .addValue("usagetypeid", meterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", meterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", meterWaterRates.getOutsideUlb()).addValue("sourcetypeid", sourcetypeId) .addValue("pipesizeid", pipesizeId).addValue("fromdate", meterWaterRates.getFromDate()) .addValue("todate", meterWaterRates.getToDate()).addValue("active", meterWaterRates.getActive()) .addValue("createdby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); final List<Slab> slabList = meterWaterRates.getSlab(); if (slabList != null && !slabList.isEmpty()) { log.info("the insert query for slab : " + slabInsertQuery); for (final Slab slab : slabList) batchValuesSlab .add(new MapSqlParameterSource("meterwaterratesid", Long.valueOf(meterWaterRates.getCode())) .addValue("fromunit", slab.getFromUnit()).addValue("tounit", slab.getToUnit()) .addValue("unitrate", slab.getUnitRate()) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); } } namedParameterJdbcTemplate.batchUpdate(meterWaterRatesInsertQuery, batchValues.toArray(new Map[meterWaterRatesList.size()])); namedParameterJdbcTemplate.batchUpdate(slabInsertQuery, batchValuesSlab.toArray(new Map[slabs.size()])); return meterWaterRatesRequest; }  MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest); MeterWaterRatesRequest update(final MeterWaterRatesRequest meterWaterRatesRequest); List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest); boolean checkMeterWaterRatesExists(final String code, final Long usageTypeId, final Long subUsageTypeId,
            final String sourceTypeName, final Double pipeSize, 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); }
MeterWaterRatesRepository { public MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest) { log.info("MeterWaterRatesRequest::" + meterWaterRatesRequest); final String meterWaterRatesInsertQuery = MeterWaterRatesQueryBuilder.insertMeterWaterRatesQuery(); final String pipesizeQuery = MeterWaterRatesQueryBuilder.getPipeSizeIdQuery(); final String sourcetypeQuery = MeterWaterRatesQueryBuilder.getSourceTypeIdQuery(); final List<MeterWaterRates> meterWaterRatesList = meterWaterRatesRequest.getMeterWaterRates(); final List<Slab> slabs = new ArrayList<>(); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) slabs.addAll(meterWaterRate.getSlab()); final String slabInsertQuery = MeterWaterRatesQueryBuilder.insertSlabQuery(); final List<Map<String, Object>> batchValuesSlab = new ArrayList<>(slabs.size()); final List<Map<String, Object>> batchValues = new ArrayList<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRates : meterWaterRatesList) { Long pipesizeId = 0L; try { pipesizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { meterWaterRates.getPipeSize(), meterWaterRates.getTenantId() }, 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 { sourcetypeId = jdbcTemplate.queryForObject(sourcetypeQuery, new Object[] { meterWaterRates.getSourceTypeName(), meterWaterRates.getTenantId() }, 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(meterWaterRates.getCode())) .addValue("code", meterWaterRates.getCode()) .addValue("billingtype", meterWaterRates.getBillingType()) .addValue("usagetypeid", meterWaterRates.getUsageTypeId()) .addValue("subusagetypeid", meterWaterRates.getSubUsageTypeId()) .addValue("outsideulb", meterWaterRates.getOutsideUlb()).addValue("sourcetypeid", sourcetypeId) .addValue("pipesizeid", pipesizeId).addValue("fromdate", meterWaterRates.getFromDate()) .addValue("todate", meterWaterRates.getToDate()).addValue("active", meterWaterRates.getActive()) .addValue("createdby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(meterWaterRatesRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); final List<Slab> slabList = meterWaterRates.getSlab(); if (slabList != null && !slabList.isEmpty()) { log.info("the insert query for slab : " + slabInsertQuery); for (final Slab slab : slabList) batchValuesSlab .add(new MapSqlParameterSource("meterwaterratesid", Long.valueOf(meterWaterRates.getCode())) .addValue("fromunit", slab.getFromUnit()).addValue("tounit", slab.getToUnit()) .addValue("unitrate", slab.getUnitRate()) .addValue("tenantid", meterWaterRates.getTenantId()).getValues()); } } namedParameterJdbcTemplate.batchUpdate(meterWaterRatesInsertQuery, batchValues.toArray(new Map[meterWaterRatesList.size()])); namedParameterJdbcTemplate.batchUpdate(slabInsertQuery, batchValuesSlab.toArray(new Map[slabs.size()])); return meterWaterRatesRequest; }  MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest); MeterWaterRatesRequest update(final MeterWaterRatesRequest meterWaterRatesRequest); List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest); boolean checkMeterWaterRatesExists(final String code, final Long usageTypeId, final Long subUsageTypeId,
            final String sourceTypeName, final Double pipeSize, 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);  }