@@ -57,12 +57,19 @@ public class ChargesApiResource {
|
|||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String retrieveCharge(@PathParam("chargeId") final Long chargeId, @Context final UriInfo uriInfo){
|
public String retrieveCharge(@PathParam("chargeId") final Long chargeId, @Context final UriInfo uriInfo){
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
ChargeData charge = this.chargeReadPlatformService.retrieveCharge(chargeId);
|
ChargeData charge = this.chargeReadPlatformService.retrieveCharge(chargeId);
|
||||||
|
|
||||||
|
if (template){
|
||||||
|
ChargeData templateData = this.chargeReadPlatformService.retrieveNewChargeDetails();
|
||||||
|
|
||||||
|
charge = new ChargeData(charge, templateData);
|
||||||
|
}
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, charge);
|
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, charge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,16 +78,8 @@ public class ChargesApiResource {
|
|||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String retrieveNewChargeDetails(@Context final UriInfo uriInfo) {
|
public String retrieveNewChargeDetails(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
Set<String> typicalResponseParameters = new HashSet<String>(
|
|
||||||
Arrays.asList("id", "name", "amount", "currency", "active", "chargeAppliesTo", "chargeTimeType",
|
|
||||||
"chargeCalculationType", "chargeCalculationTypeOptions", "currencyOptions")
|
|
||||||
);
|
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (responseParameters.isEmpty()) {
|
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
ChargeData chargeData = this.chargeReadPlatformService.retrieveNewChargeDetails();
|
ChargeData chargeData = this.chargeReadPlatformService.retrieveNewChargeDetails();
|
||||||
|
|||||||
@@ -19,16 +19,29 @@ public class ChargeData {
|
|||||||
|
|
||||||
private final List<CurrencyData> currencyOptions;
|
private final List<CurrencyData> currencyOptions;
|
||||||
private final List<EnumOptionData> chargeCalculationTypeOptions;
|
private final List<EnumOptionData> chargeCalculationTypeOptions;
|
||||||
|
private final List<EnumOptionData> chargeAppliesToOptions;
|
||||||
|
private final List<EnumOptionData> chargeTimeTypeOptions;
|
||||||
|
|
||||||
public static ChargeData template(
|
public static ChargeData template(
|
||||||
|
final CurrencyData currency,
|
||||||
final EnumOptionData chargeTimeType,
|
final EnumOptionData chargeTimeType,
|
||||||
final EnumOptionData chargeAppliesToType,
|
final EnumOptionData chargeAppliesToType,
|
||||||
final EnumOptionData chargeCalculationType,
|
final EnumOptionData chargeCalculationType,
|
||||||
final List<CurrencyData> currencyOptions,
|
final List<CurrencyData> currencyOptions,
|
||||||
final List<EnumOptionData> chargeCalculationTypeOptions) {
|
final List<EnumOptionData> chargeCalculationTypeOptions,
|
||||||
return new ChargeData(null, null, null, null, chargeTimeType, chargeAppliesToType, chargeCalculationType, false, currencyOptions, chargeCalculationTypeOptions);
|
final List<EnumOptionData> chargeAppliesToOptions,
|
||||||
|
final List<EnumOptionData> chargeTimeTypeOptions) {
|
||||||
|
return new ChargeData(null, null, null, currency, chargeTimeType, chargeAppliesToType, chargeCalculationType, false,
|
||||||
|
currencyOptions, chargeCalculationTypeOptions, chargeAppliesToOptions, chargeTimeTypeOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChargeData(ChargeData charge, ChargeData template){
|
||||||
|
this(charge.getId(), charge.getName(), charge.getAmount(), charge.getCurrency(), charge.getChargeTimeType(),
|
||||||
|
charge.getChargeAppliesTo(), charge.getChargeCalculationType(), charge.isActive(),
|
||||||
|
template.getCurrencyOptions(), template.getChargeCalculationTypeOptions(),
|
||||||
|
template.getChargeAppliesToOptions(), template.getChargeTimeTypeOptions());
|
||||||
|
}
|
||||||
|
|
||||||
public ChargeData(final Long id, final String name,
|
public ChargeData(final Long id, final String name,
|
||||||
final BigDecimal amount, final CurrencyData currency,
|
final BigDecimal amount, final CurrencyData currency,
|
||||||
final EnumOptionData chargeTimeType,
|
final EnumOptionData chargeTimeType,
|
||||||
@@ -44,6 +57,8 @@ public class ChargeData {
|
|||||||
this.active = active;
|
this.active = active;
|
||||||
this.currencyOptions = null;
|
this.currencyOptions = null;
|
||||||
this.chargeCalculationTypeOptions = null;
|
this.chargeCalculationTypeOptions = null;
|
||||||
|
this.chargeAppliesToOptions = null;
|
||||||
|
this.chargeTimeTypeOptions = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChargeData(final Long id, final String name,
|
public ChargeData(final Long id, final String name,
|
||||||
@@ -52,7 +67,9 @@ public class ChargeData {
|
|||||||
final EnumOptionData chargeAppliesTo,
|
final EnumOptionData chargeAppliesTo,
|
||||||
final EnumOptionData chargeCalculationType, final boolean active,
|
final EnumOptionData chargeCalculationType, final boolean active,
|
||||||
final List<CurrencyData> currencyOptions,
|
final List<CurrencyData> currencyOptions,
|
||||||
final List<EnumOptionData> chargeCalculationTypeOptions) {
|
final List<EnumOptionData> chargeCalculationTypeOptions,
|
||||||
|
final List<EnumOptionData> chargeAppliesToOptions,
|
||||||
|
final List<EnumOptionData> chargeTimeTypeOptions) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
@@ -63,6 +80,8 @@ public class ChargeData {
|
|||||||
this.active = active;
|
this.active = active;
|
||||||
this.currencyOptions = currencyOptions;
|
this.currencyOptions = currencyOptions;
|
||||||
this.chargeCalculationTypeOptions = chargeCalculationTypeOptions;
|
this.chargeCalculationTypeOptions = chargeCalculationTypeOptions;
|
||||||
|
this.chargeAppliesToOptions = chargeAppliesToOptions;
|
||||||
|
this.chargeTimeTypeOptions = chargeTimeTypeOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@@ -104,4 +123,12 @@ public class ChargeData {
|
|||||||
public List<EnumOptionData> getChargeCalculationTypeOptions() {
|
public List<EnumOptionData> getChargeCalculationTypeOptions() {
|
||||||
return chargeCalculationTypeOptions;
|
return chargeCalculationTypeOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<EnumOptionData> getChargeAppliesToOptions() {
|
||||||
|
return chargeAppliesToOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EnumOptionData> getChargeTimeTypeOptions() {
|
||||||
|
return chargeTimeTypeOptions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -159,7 +159,7 @@ public class GoogleGsonApiJsonSerializerService implements
|
|||||||
Arrays.asList("id", "name", "amount", "currency", "active",
|
Arrays.asList("id", "name", "amount", "currency", "active",
|
||||||
"chargeAppliesTo", "chargeTimeType",
|
"chargeAppliesTo", "chargeTimeType",
|
||||||
"chargeCalculationType", "chargeCalculationTypeOptions",
|
"chargeCalculationType", "chargeCalculationTypeOptions",
|
||||||
"currencyOptions"));
|
"chargeAppliesToOptions", "chargeTimeTypeOptions", "currencyOptions"));
|
||||||
|
|
||||||
private final GoogleGsonSerializerHelper helper;
|
private final GoogleGsonSerializerHelper helper;
|
||||||
|
|
||||||
|
|||||||
+13
-5
@@ -75,17 +75,25 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
|
|||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
List<CurrencyData> currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies();
|
List<CurrencyData> currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies();
|
||||||
List<EnumOptionData> allowedChargeCalculationMethods = Arrays.asList(
|
CurrencyData currency = new CurrencyData("", "", 0, "", "");
|
||||||
|
|
||||||
|
EnumOptionData allowedChargeCalculationType = chargeCalculationType(ChargeCalculationMethod.FLAT);
|
||||||
|
List<EnumOptionData> allowedChargeCalculationMethodsOptions = Arrays.asList(
|
||||||
chargeCalculationType(ChargeCalculationMethod.FLAT),
|
chargeCalculationType(ChargeCalculationMethod.FLAT),
|
||||||
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_AMOUNT),
|
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_AMOUNT),
|
||||||
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_AMOUNT_AND_INTEREST),
|
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_AMOUNT_AND_INTEREST),
|
||||||
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_INTEREST)
|
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_INTEREST)
|
||||||
);
|
);
|
||||||
EnumOptionData allowedChargeAppliesTo = chargeAppliesTo(ChargeAppliesTo.LOAN);
|
|
||||||
EnumOptionData allowedChargeTime = chargeTimeType(ChargeTimeType.DISBURSEMENT);
|
|
||||||
EnumOptionData allowedChargeCalculationType = chargeCalculationType(ChargeCalculationMethod.FLAT);
|
|
||||||
|
|
||||||
return ChargeData.template(allowedChargeTime, allowedChargeAppliesTo, allowedChargeCalculationType, currencyOptions, allowedChargeCalculationMethods);
|
EnumOptionData allowedChargeAppliesTo = chargeAppliesTo(ChargeAppliesTo.LOAN);
|
||||||
|
List<EnumOptionData> allowedChargeAppliesToOptions = Arrays.asList(allowedChargeAppliesTo);
|
||||||
|
|
||||||
|
EnumOptionData allowedChargeTime = chargeTimeType(ChargeTimeType.DISBURSEMENT);
|
||||||
|
List<EnumOptionData> allowedChargeTimeOptions = Arrays.asList(allowedChargeTime);
|
||||||
|
|
||||||
|
return ChargeData.template(currency, allowedChargeTime, allowedChargeAppliesTo, allowedChargeCalculationType,
|
||||||
|
currencyOptions, allowedChargeCalculationMethodsOptions,
|
||||||
|
allowedChargeAppliesToOptions, allowedChargeTimeOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ChargeMapper implements RowMapper<ChargeData> {
|
private static final class ChargeMapper implements RowMapper<ChargeData> {
|
||||||
|
|||||||
Reference in New Issue
Block a user