Review comments addressed

This commit is contained in:
VenuShyam
2015-09-03 19:51:07 +05:30
parent 5a990af553
commit 670b6eef19
10 changed files with 1153 additions and 58 deletions
@@ -32,6 +32,7 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.charge.data.ChargeData;
import org.mifosplatform.portfolio.charge.service.ChargeReadPlatformService;
@@ -74,24 +75,23 @@ public class ClientChargesApiResource {
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllClientCharges(@PathParam("clientId") final Long clientId,
public String retrieveAllClientCharges(
@PathParam("clientId") final Long clientId,
@DefaultValue(ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ALL) @QueryParam(ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS) final String chargeStatus,
@QueryParam("paid") final Boolean paid, @Context final UriInfo uriInfo) {
@QueryParam("paid") final Boolean paid, @Context final UriInfo uriInfo, @QueryParam("limit") final Integer limit,
@QueryParam("offset") final Integer offset) {
this.context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_CHARGES_RESOURCE_NAME);
if (!(is(chargeStatus, ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ALL)
|| is(chargeStatus, ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ACTIVE)
|| is(chargeStatus,
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_INACTIVE))) { throw new UnrecognizedQueryParamException(
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS, chargeStatus,
new Object[] { ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ALL,
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ACTIVE,
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_INACTIVE }); }
final Collection<ClientChargeData> clientCharges = this.clientChargeReadPlatformService.retrieveClientCharges(clientId,
chargeStatus, paid);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
if (!(is(chargeStatus, ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ALL)
|| is(chargeStatus, ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ACTIVE) || is(chargeStatus,
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_INACTIVE))) { throw new UnrecognizedQueryParamException(
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS, chargeStatus, new Object[] {
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ALL,
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ACTIVE,
ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_INACTIVE }); }
final Page<ClientChargeData> clientCharges = this.clientChargeReadPlatformService.retrieveClientCharges(clientId, chargeStatus,
paid, limit, offset);
return this.toApiJsonSerializer.serialize(settings, clientCharges, ClientApiConstants.CLIENT_CHARGES_RESPONSE_DATA_PARAMETERS);
}
@@ -123,9 +123,7 @@ public class ClientChargesApiResource {
@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_CHARGES_RESOURCE_NAME);
ClientChargeData clientCharge = this.clientChargeReadPlatformService.retrieveClientCharge(clientId, chargeId);
// extract associations
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
if (!associationParameters.isEmpty()) {
@@ -136,13 +134,11 @@ public class ClientChargesApiResource {
if (associationParameters.contains(ClientApiConstants.CLIENT_CHARGE_ASSOCIATIONS_TRANSACTIONS)) {
Collection<ClientTransactionData> clientTransactionDatas = this.clientTransactionReadPlatformService
.retrieveAllTransactions(clientId, chargeId);
if (CollectionUtils.isEmpty(clientTransactionDatas)) {
clientTransactionDatas = null;
if (!CollectionUtils.isEmpty(clientTransactionDatas)) {
clientCharge = ClientChargeData.addAssociations(clientCharge, clientTransactionDatas);
}
clientCharge = ClientChargeData.addAssociations(clientCharge, clientTransactionDatas);
}
}
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, clientCharge, ClientApiConstants.CLIENT_CHARGES_RESPONSE_DATA_PARAMETERS);
}
@@ -61,7 +61,6 @@ public class ClientTransactionsApiResource {
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllClientTransactions(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_CHARGES_RESOURCE_NAME);
final Collection<ClientTransactionData> clientTransactions = this.clientTransactionReadPlatformService
.retrieveAllTransactions(clientId);
@@ -5,13 +5,13 @@
*/
package org.mifosplatform.portfolio.client.service;
import java.util.Collection;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.portfolio.client.data.ClientChargeData;
public interface ClientChargeReadPlatformService {
Collection<ClientChargeData> retrieveClientCharges(Long clientId, String status, Boolean isPaid);
Page<ClientChargeData> retrieveClientCharges(Long clientId, String status, Boolean isPaid, Integer limit, Integer offset);
ClientChargeData retrieveClientCharge(Long clientId, Long clientChargeId);
@@ -13,6 +13,8 @@ import java.util.Collection;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.infrastructure.core.service.PaginationHelper;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.data.CurrencyData;
@@ -30,13 +32,16 @@ import org.springframework.stereotype.Service;
@Service
public class ClientChargeReadPlatformServiceImpl implements ClientChargeReadPlatformService {
private final PaginationHelper<ClientChargeData> paginationHelper = new PaginationHelper<>();
private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
private final ClientChargeMapper clientChargeMapper;
@Autowired
public ClientChargeReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource) {
this.context = context;
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.clientChargeMapper = new ClientChargeMapper();
}
public static final class ClientChargeMapper implements RowMapper<ClientChargeData> {
@@ -97,10 +102,25 @@ public class ClientChargeReadPlatformServiceImpl implements ClientChargeReadPlat
}
@Override
public Collection<ClientChargeData> retrieveClientCharges(Long clientId, String status, Boolean isPaid) {
public ClientChargeData retrieveClientCharge(Long clientId, Long clientChargeId) {
try {
this.context.authenticatedUser();
final ClientChargeMapper rm = new ClientChargeMapper();
final String sql = "select " + rm.schema() + " where cc.client_id=? and cc.id=? ";
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { clientId, clientChargeId });
} catch (final EmptyResultDataAccessException e) {
throw new ClientChargeNotFoundException(clientChargeId, clientId);
}
}
@Override
public Page<ClientChargeData> retrieveClientCharges(Long clientId, String status, Boolean isPaid,Integer limit,Integer offset) {
final ClientChargeMapper rm = new ClientChargeMapper();
final StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("select ").append(rm.schema()).append(" where cc.client_id=? ");
sqlBuilder.append("select SQL_CALC_FOUND_ROWS ").append(rm.schema()).append(" where cc.client_id=? ");
// filter for active charges
if (status.equalsIgnoreCase(ClientApiConstants.CLIENT_CHARGE_QUERY_PARAM_STATUS_VALUE_ACTIVE)) {
@@ -115,25 +135,10 @@ public class ClientChargeReadPlatformServiceImpl implements ClientChargeReadPlat
} else if (isPaid != null && !isPaid) {
sqlBuilder.append(" and (cc.is_paid_derived = 0 and cc.waived = 0) ");
}
sqlBuilder.append(" order by cc.charge_time_enum ASC, cc.charge_due_date ASC, cc.is_penalty ASC");
return this.jdbcTemplate.query(sqlBuilder.toString(), rm, new Object[] { clientId });
}
@Override
public ClientChargeData retrieveClientCharge(Long clientId, Long clientChargeId) {
try {
this.context.authenticatedUser();
final ClientChargeMapper rm = new ClientChargeMapper();
final String sql = "select " + rm.schema() + " where cc.client_id=? and cc.id=? ";
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { clientId, clientChargeId });
} catch (final EmptyResultDataAccessException e) {
throw new ClientChargeNotFoundException(clientChargeId, clientId);
}
sqlBuilder.append(" order by cc.charge_time_enum ASC, cc.charge_due_date ASC, cc.is_penalty ASC "+"limit "+limit+" offset "+offset);
final String sqlCountRows = "SELECT FOUND_ROWS()";
return this.paginationHelper.fetchPage(this.jdbcTemplate,sqlCountRows, sqlBuilder.toString(),new Object[] { clientId },this.clientChargeMapper);
}
}
@@ -148,10 +148,10 @@ public class ClientChargeWritePlatformServiceJpaRepositoryImpl implements Client
generateAccountingEntries(clientTransaction);
return new CommandProcessingResultBuilder() //
.withTransactionId(clientTransaction.getId().toString())//
.withEntityId(clientCharge.getId()) //
.withOfficeId(clientCharge.getClient().getOffice().getId()) //
.withClientId(clientCharge.getClient().getId()) //
.build();
.withClientId(clientCharge.getClient().getId()).build();
}
@@ -181,7 +181,7 @@ public class ClientChargeWritePlatformServiceJpaRepositoryImpl implements Client
final ClientChargePaidBy chargePaidBy = ClientChargePaidBy.instance(clientTransaction, clientCharge, waivedAmount.getAmount());
clientTransaction.getClientChargePaidByCollection().add(chargePaidBy);
return new CommandProcessingResultBuilder() //
return new CommandProcessingResultBuilder().withTransactionId(clientTransaction.getId().toString())//
.withEntityId(clientCharge.getId()) //
.withOfficeId(clientCharge.getClient().getOffice().getId()) //
.withClientId(clientCharge.getClient().getId()) //
@@ -209,8 +209,7 @@ public class ClientChargeWritePlatformServiceJpaRepositoryImpl implements Client
/**
* Validates transaction to ensure that <br>
* charge is active <br>
* transaction date is valid (between client activation and todays date)
* <br>
* transaction date is valid (between client activation and todays date) <br>
* charge is not already paid or waived <br>
* amount is not more than total due
*
@@ -29,7 +29,7 @@ import org.springframework.stereotype.Service;
@Service
public class ClientTransactionReadPlatformServiceImpl implements ClientTransactionReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final ClientTransactionMapper clientTransactionMapper;
@@ -37,11 +37,11 @@ public class ClientTransactionReadPlatformServiceImpl implements ClientTransacti
public ClientTransactionReadPlatformServiceImpl(final RoutingDataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.clientTransactionMapper = new ClientTransactionMapper();
}
private static final class ClientTransactionMapper implements RowMapper<ClientTransactionData> {
private final String schemaSql;
public ClientTransactionMapper() {
@@ -119,8 +119,8 @@ public class ClientTransactionReadPlatformServiceImpl implements ClientTransacti
@Override
public Collection<ClientTransactionData> retrieveAllTransactions(Long clientId) {
Long chargeId = null;
return retrieveAllTransactions(clientId, chargeId);
Long chargeId=null;
return retrieveAllTransactions(clientId,chargeId);
}
@Override