LoanProduct filtering changes
This commit is contained in:
@@ -7,9 +7,11 @@ import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.codehaus.jackson.map.annotate.JsonFilter;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
@XmlRootElement(name = "loanProduct")
|
||||
@JsonFilter("myFilter")
|
||||
public class LoanProductData implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.mifosng.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class LoanProductList {
|
||||
|
||||
private Collection<LoanProductData> products = new ArrayList<LoanProductData>();
|
||||
|
||||
protected LoanProductList() {
|
||||
//
|
||||
}
|
||||
|
||||
public LoanProductList(final Collection<LoanProductData> products) {
|
||||
this.products = products;
|
||||
}
|
||||
|
||||
public Collection<LoanProductData> getProducts() {
|
||||
return this.products;
|
||||
}
|
||||
|
||||
public void setProducts(final Collection<LoanProductData> products) {
|
||||
this.products = products;
|
||||
}
|
||||
}
|
||||
+66
-33
@@ -11,14 +11,16 @@ import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.LoanProductData;
|
||||
import org.mifosng.data.LoanProductList;
|
||||
import org.mifosng.data.command.LoanProductCommand;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
||||
import org.mifosng.platform.loanproduct.service.LoanProductReadPlatformService;
|
||||
import org.mifosng.platform.loanproduct.service.LoanProductWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,78 +32,109 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class LoanProductApiResource {
|
||||
|
||||
@Autowired
|
||||
private String defaultFieldList = "principalMoney,inArrearsTolerance,amortizationMethod,interestMethod,repaymentPeriodFrequency,interestRatePeriod,interestRateCalculatedInPeriod,repaidEvery,numberOfRepayments,interestRatePerPeriod,annualInterestRate,numberOfInterestFreePeriods,flexible,interestRebateAllowed";
|
||||
private String allowedFieldList = "possibleCurrencies,possibleAmortizationOptions,possibleInterestOptions,possibleInterestRateCalculatedInPeriodOptions,repaymentFrequencyOptions,interestFrequencyOptions";
|
||||
|
||||
@Autowired
|
||||
private LoanProductReadPlatformService loanProductReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private LoanProductWritePlatformService loanProductWritePlatformService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ApiDataConversionService apiDataConversionService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ApiJSONFormattingService jsonFormattingService;
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON})
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response createLoanProduct(LoanProductCommand command) {
|
||||
|
||||
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.createLoanProduct(command);
|
||||
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService
|
||||
.createLoanProduct(command);
|
||||
|
||||
return Response.ok().entity(entityIdentifier).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response retrieveAllLoanProducts() {
|
||||
|
||||
Collection<LoanProductData> products = this.loanProductReadPlatformService.retrieveAllLoanProducts();
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllLoanProducts(@Context UriInfo uriInfo) {
|
||||
|
||||
return Response.ok().entity(new LoanProductList(products)).build();
|
||||
}
|
||||
|
||||
/*
|
||||
* see http://stackoverflow.com/questions/5250074/what-uri-can-be-used-to-request-a-default-resource
|
||||
Collection<LoanProductData> products = this.loanProductReadPlatformService
|
||||
.retrieveAllLoanProducts();
|
||||
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(products,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
/*
|
||||
* see
|
||||
* http://stackoverflow.com/questions/5250074/what-uri-can-be-used-to-request
|
||||
* -a-default-resource
|
||||
*/
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON})
|
||||
public Response retrieveNewLoanProductDetails() {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveNewLoanProductDetails(@Context UriInfo uriInfo) {
|
||||
|
||||
LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveNewLoanProductDetails();
|
||||
LoanProductData loanProduct = this.loanProductReadPlatformService
|
||||
.retrieveNewLoanProductDetails();
|
||||
|
||||
return Response.ok().entity(loanProduct).build();
|
||||
String selectedFields = defaultFieldList + "," + allowedFieldList;
|
||||
return this.jsonFormattingService.convertRequest(loanProduct,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("{productId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON})
|
||||
public Response retrieveLoanProductDetails(@PathParam("productId") final Long productId) {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveLoanProductDetails(
|
||||
@PathParam("productId") final Long productId,
|
||||
@Context UriInfo uriInfo) {
|
||||
|
||||
LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId);
|
||||
LoanProductData loanProduct = this.loanProductReadPlatformService
|
||||
.retrieveLoanProduct(productId);
|
||||
|
||||
return Response.ok().entity(loanProduct).build();
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(loanProduct,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{productId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response updateLoanProduct(@PathParam("productId") final Long productId, final LoanProductCommand command) {
|
||||
|
||||
public Response updateLoanProduct(
|
||||
@PathParam("productId") final Long productId,
|
||||
final LoanProductCommand command) {
|
||||
|
||||
// FIXME - pass in locale through query string or in 'request body'
|
||||
Locale clientApplicationLocale = Locale.UK;
|
||||
BigDecimal principal = this.apiDataConversionService.convertFrom(command.getPrincipalFormatted(), "principalFormatted", clientApplicationLocale);
|
||||
BigDecimal interestRatePerPeriod = this.apiDataConversionService.convertFrom(command.getInterestRatePerPeriodFormatted(), "interestRatePerPeriodFormatted", clientApplicationLocale);
|
||||
BigDecimal inArrearsToleranceAmount = this.apiDataConversionService.convertFrom(command.getInArrearsToleranceAmountFormatted(), "inArrearsToleranceAmountFormatted", clientApplicationLocale);
|
||||
BigDecimal principal = this.apiDataConversionService.convertFrom(
|
||||
command.getPrincipalFormatted(), "principalFormatted",
|
||||
clientApplicationLocale);
|
||||
BigDecimal interestRatePerPeriod = this.apiDataConversionService
|
||||
.convertFrom(command.getInterestRatePerPeriodFormatted(),
|
||||
"interestRatePerPeriodFormatted",
|
||||
clientApplicationLocale);
|
||||
BigDecimal inArrearsToleranceAmount = this.apiDataConversionService
|
||||
.convertFrom(command.getInArrearsToleranceAmountFormatted(),
|
||||
"inArrearsToleranceAmountFormatted",
|
||||
clientApplicationLocale);
|
||||
command.setPrincipal(principal);
|
||||
command.setInterestRatePerPeriod(interestRatePerPeriod);
|
||||
command.setInArrearsToleranceAmount(inArrearsToleranceAmount);
|
||||
|
||||
command.setId(productId);
|
||||
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.updateLoanProduct(command);
|
||||
|
||||
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService
|
||||
.updateLoanProduct(command);
|
||||
|
||||
return Response.ok().entity(entityIdentifier).build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user