@Test public void test_Should_Modify_Donation() throws Exception { final DonationRequest donationRequest = new DonationRequest(); final RequestInfo requestInfo = new RequestInfo(); final User user = new User(); user.setId(1L); requestInfo.setUserInfo(user); final List<Donation> donationList = new ArrayList<>(); donationList.add(getDonation()); donationRequest.setRequestInfo(requestInfo); donationRequest.setDonations(donationList); assertNotNull(donationRepository.update(donationRequest)); }
public DonationRequest update(final DonationRequest donationRequest) { log.info("Donation update Request::" + donationRequest); final String donationUpdate = DonationQueryBuilder.donationUpdateQuery(); final List<Donation> donationList = donationRequest.getDonations(); final List<Map<String, Object>> batchValues = new ArrayList<>(donationList.size()); for (final Donation donation : donationList) { final String pipesizeQuery = DonationQueryBuilder.getPipeSizeIdQuery(); Long maxPipeSizeId = 0L; try { maxPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMaxPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (maxPipeSizeId == null) log.info("Invalid input for MaxPipeSize."); Long minPipeSizeId = 0L; try { minPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMinPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } if (minPipeSizeId == null) log.info("Invalid input for MinPipeSize"); final String usageQuery = DonationQueryBuilder.getUsageTypeId(); Long usageTypeId = 0L; try { usageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (usageTypeId == null) log.info("Invalid input for MaxPipeSize."); Long subUsageTypeId = 0L; try { subUsageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getSubUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } batchValues.add( new MapSqlParameterSource("usagetypeid", usageTypeId) .addValue("subusagetypeid", subUsageTypeId) .addValue("outsideulb", donation.getOutsideUlb()) .addValue("maxpipesizeid", maxPipeSizeId).addValue("minpipesizeid", minPipeSizeId) .addValue("fromdate", donation.getFromDate()).addValue("todate", donation.getToDate()) .addValue("donationamount", donation.getDonationAmount()).addValue("active", donation.getActive()) .addValue("tenantid", donation.getTenantId()) .addValue("lastmodifiedby", Long.valueOf(donationRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifieddate", new Date().getTime()) .addValue("code", donation.getCode()).addValue("tenantid", donation.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(donationUpdate, batchValues.toArray(new Map[donationList.size()])); return donationRequest; }
DonationRepository { public DonationRequest update(final DonationRequest donationRequest) { log.info("Donation update Request::" + donationRequest); final String donationUpdate = DonationQueryBuilder.donationUpdateQuery(); final List<Donation> donationList = donationRequest.getDonations(); final List<Map<String, Object>> batchValues = new ArrayList<>(donationList.size()); for (final Donation donation : donationList) { final String pipesizeQuery = DonationQueryBuilder.getPipeSizeIdQuery(); Long maxPipeSizeId = 0L; try { maxPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMaxPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (maxPipeSizeId == null) log.info("Invalid input for MaxPipeSize."); Long minPipeSizeId = 0L; try { minPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMinPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } if (minPipeSizeId == null) log.info("Invalid input for MinPipeSize"); final String usageQuery = DonationQueryBuilder.getUsageTypeId(); Long usageTypeId = 0L; try { usageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (usageTypeId == null) log.info("Invalid input for MaxPipeSize."); Long subUsageTypeId = 0L; try { subUsageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getSubUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } batchValues.add( new MapSqlParameterSource("usagetypeid", usageTypeId) .addValue("subusagetypeid", subUsageTypeId) .addValue("outsideulb", donation.getOutsideUlb()) .addValue("maxpipesizeid", maxPipeSizeId).addValue("minpipesizeid", minPipeSizeId) .addValue("fromdate", donation.getFromDate()).addValue("todate", donation.getToDate()) .addValue("donationamount", donation.getDonationAmount()).addValue("active", donation.getActive()) .addValue("tenantid", donation.getTenantId()) .addValue("lastmodifiedby", Long.valueOf(donationRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifieddate", new Date().getTime()) .addValue("code", donation.getCode()).addValue("tenantid", donation.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(donationUpdate, batchValues.toArray(new Map[donationList.size()])); return donationRequest; } }
DonationRepository { public DonationRequest update(final DonationRequest donationRequest) { log.info("Donation update Request::" + donationRequest); final String donationUpdate = DonationQueryBuilder.donationUpdateQuery(); final List<Donation> donationList = donationRequest.getDonations(); final List<Map<String, Object>> batchValues = new ArrayList<>(donationList.size()); for (final Donation donation : donationList) { final String pipesizeQuery = DonationQueryBuilder.getPipeSizeIdQuery(); Long maxPipeSizeId = 0L; try { maxPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMaxPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (maxPipeSizeId == null) log.info("Invalid input for MaxPipeSize."); Long minPipeSizeId = 0L; try { minPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMinPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } if (minPipeSizeId == null) log.info("Invalid input for MinPipeSize"); final String usageQuery = DonationQueryBuilder.getUsageTypeId(); Long usageTypeId = 0L; try { usageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (usageTypeId == null) log.info("Invalid input for MaxPipeSize."); Long subUsageTypeId = 0L; try { subUsageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getSubUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } batchValues.add( new MapSqlParameterSource("usagetypeid", usageTypeId) .addValue("subusagetypeid", subUsageTypeId) .addValue("outsideulb", donation.getOutsideUlb()) .addValue("maxpipesizeid", maxPipeSizeId).addValue("minpipesizeid", minPipeSizeId) .addValue("fromdate", donation.getFromDate()).addValue("todate", donation.getToDate()) .addValue("donationamount", donation.getDonationAmount()).addValue("active", donation.getActive()) .addValue("tenantid", donation.getTenantId()) .addValue("lastmodifiedby", Long.valueOf(donationRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifieddate", new Date().getTime()) .addValue("code", donation.getCode()).addValue("tenantid", donation.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(donationUpdate, batchValues.toArray(new Map[donationList.size()])); return donationRequest; }  }
DonationRepository { public DonationRequest update(final DonationRequest donationRequest) { log.info("Donation update Request::" + donationRequest); final String donationUpdate = DonationQueryBuilder.donationUpdateQuery(); final List<Donation> donationList = donationRequest.getDonations(); final List<Map<String, Object>> batchValues = new ArrayList<>(donationList.size()); for (final Donation donation : donationList) { final String pipesizeQuery = DonationQueryBuilder.getPipeSizeIdQuery(); Long maxPipeSizeId = 0L; try { maxPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMaxPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (maxPipeSizeId == null) log.info("Invalid input for MaxPipeSize."); Long minPipeSizeId = 0L; try { minPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMinPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } if (minPipeSizeId == null) log.info("Invalid input for MinPipeSize"); final String usageQuery = DonationQueryBuilder.getUsageTypeId(); Long usageTypeId = 0L; try { usageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (usageTypeId == null) log.info("Invalid input for MaxPipeSize."); Long subUsageTypeId = 0L; try { subUsageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getSubUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } batchValues.add( new MapSqlParameterSource("usagetypeid", usageTypeId) .addValue("subusagetypeid", subUsageTypeId) .addValue("outsideulb", donation.getOutsideUlb()) .addValue("maxpipesizeid", maxPipeSizeId).addValue("minpipesizeid", minPipeSizeId) .addValue("fromdate", donation.getFromDate()).addValue("todate", donation.getToDate()) .addValue("donationamount", donation.getDonationAmount()).addValue("active", donation.getActive()) .addValue("tenantid", donation.getTenantId()) .addValue("lastmodifiedby", Long.valueOf(donationRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifieddate", new Date().getTime()) .addValue("code", donation.getCode()).addValue("tenantid", donation.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(donationUpdate, batchValues.toArray(new Map[donationList.size()])); return donationRequest; }  DonationRequest create(final DonationRequest donationRequest); DonationRequest update(final DonationRequest donationRequest); List<Donation> findForCriteria(final DonationGetRequest donationRequest); boolean checkDonationsExist(final String code, final String usageType,
            final String subUsageType, final Double maxPipeSize, final Double minPipeSize,
            final String tenantId); boolean checkPipeSizeExists(final Double pipeSize, final String tenantId); boolean checkUsageExists(final String usage, final String tenantId); }
DonationRepository { public DonationRequest update(final DonationRequest donationRequest) { log.info("Donation update Request::" + donationRequest); final String donationUpdate = DonationQueryBuilder.donationUpdateQuery(); final List<Donation> donationList = donationRequest.getDonations(); final List<Map<String, Object>> batchValues = new ArrayList<>(donationList.size()); for (final Donation donation : donationList) { final String pipesizeQuery = DonationQueryBuilder.getPipeSizeIdQuery(); Long maxPipeSizeId = 0L; try { maxPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMaxPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (maxPipeSizeId == null) log.info("Invalid input for MaxPipeSize."); Long minPipeSizeId = 0L; try { minPipeSizeId = jdbcTemplate.queryForObject(pipesizeQuery, new Object[] { donation.getMinPipeSize(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } if (minPipeSizeId == null) log.info("Invalid input for MinPipeSize"); final String usageQuery = DonationQueryBuilder.getUsageTypeId(); Long usageTypeId = 0L; try { usageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for max pipesize"); } if (usageTypeId == null) log.info("Invalid input for MaxPipeSize."); Long subUsageTypeId = 0L; try { subUsageTypeId = jdbcTemplate.queryForObject(usageQuery, new Object[] { donation.getSubUsageTypeCode(), donation.getTenantId() }, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set for min pipesize"); } batchValues.add( new MapSqlParameterSource("usagetypeid", usageTypeId) .addValue("subusagetypeid", subUsageTypeId) .addValue("outsideulb", donation.getOutsideUlb()) .addValue("maxpipesizeid", maxPipeSizeId).addValue("minpipesizeid", minPipeSizeId) .addValue("fromdate", donation.getFromDate()).addValue("todate", donation.getToDate()) .addValue("donationamount", donation.getDonationAmount()).addValue("active", donation.getActive()) .addValue("tenantid", donation.getTenantId()) .addValue("lastmodifiedby", Long.valueOf(donationRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifieddate", new Date().getTime()) .addValue("code", donation.getCode()).addValue("tenantid", donation.getTenantId()) .getValues()); } namedParameterJdbcTemplate.batchUpdate(donationUpdate, batchValues.toArray(new Map[donationList.size()])); return donationRequest; }  DonationRequest create(final DonationRequest donationRequest); DonationRequest update(final DonationRequest donationRequest); List<Donation> findForCriteria(final DonationGetRequest donationRequest); boolean checkDonationsExist(final String code, final String usageType,
            final String subUsageType, final Double maxPipeSize, final Double minPipeSize,
            final String tenantId); boolean checkPipeSizeExists(final Double pipeSize, final String tenantId); boolean checkUsageExists(final String usage, final String tenantId);  }