FINERACT-737: Updated Api Docs to include loan charges paid by

FINERACT-736: Api Docs were updated to include rates documentation
FINERACT-735: Integration test were created for rates creation, retrieval and update

Missing permission READ_RATE
This commit is contained in:
Angel Cajas
2020-03-13 17:15:25 +01:00
committed by Michael Vorburger ⛑️
parent a7d4c83e92
commit c342f5b43d
9 changed files with 535 additions and 29 deletions
@@ -19,6 +19,8 @@
package org.apache.fineract.portfolio.rate.data;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -33,17 +35,17 @@ public class RateData implements Serializable {
private BigDecimal percentage;
private String productApply;
private EnumOptionData productApply;
private boolean active;
public static RateData instance(final Long id, final String name, final BigDecimal percentage,
final String productApply, final boolean active) {
final EnumOptionData productApply, final boolean active) {
return new RateData(id, name, percentage, productApply, active);
}
private RateData(final Long id, final String name, final BigDecimal percentage,
final String productApply, final boolean active) {
final EnumOptionData productApply, final boolean active) {
this.id = id;
this.name = name;
this.percentage = percentage;
@@ -19,11 +19,18 @@
package org.apache.fineract.portfolio.rate.domain;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.portfolio.charge.exception.ChargeParameterUpdateNotSupportedException;
import org.apache.fineract.useradministration.domain.AppUser;
import org.apache.fineract.portfolio.rate.domain.RateAppliesTo;
import javax.persistence.*;
import java.math.BigDecimal;
@@ -45,7 +52,7 @@ public class Rate extends AbstractAuditableCustom<AppUser, Long> {
private BigDecimal percentage;
@Column(name = "product_apply", length = 100)
private String productApply;
private Integer productApply;
@Column(name = "active", nullable = false)
private boolean active;
@@ -59,19 +66,19 @@ public class Rate extends AbstractAuditableCustom<AppUser, Long> {
}
public Rate(String name, BigDecimal percentage, String productApply, boolean active,
public Rate(String name, BigDecimal percentage, RateAppliesTo productApply, boolean active,
AppUser approveUser) {
this.name = name;
this.percentage = percentage;
this.productApply = productApply;
this.productApply = productApply.getValue();
this.active = active;
this.approveUser = approveUser;
}
public Rate(String name, BigDecimal percentage, String productApply, boolean active) {
public Rate(String name, BigDecimal percentage, RateAppliesTo productApply, boolean active) {
this.name = name;
this.percentage = percentage;
this.productApply = productApply;
this.productApply = productApply.getValue();
this.active = active;
}
@@ -107,11 +114,11 @@ public class Rate extends AbstractAuditableCustom<AppUser, Long> {
this.approveUser = approveUser;
}
public String getProductApply() {
public Integer getProductApply() {
return productApply;
}
public void setProductApply(String productApply) {
public void setProductApply(Integer productApply) {
this.productApply = productApply;
}
@@ -126,7 +133,7 @@ public class Rate extends AbstractAuditableCustom<AppUser, Long> {
'}';
}
public static Rate from(String name, BigDecimal percentage, String productApply, Boolean active) {
public static Rate from(String name, BigDecimal percentage, RateAppliesTo productApply, Boolean active) {
return new Rate(name, percentage, productApply, active);
}
@@ -136,8 +143,8 @@ public class Rate extends AbstractAuditableCustom<AppUser, Long> {
final BigDecimal percentage = command.bigDecimalValueOfParameterNamed("percentage");
final String productApply = command.stringValueOfParameterNamed("productApply");
final RateAppliesTo productApply = RateAppliesTo.fromInt(command.integerValueOfParameterNamed("productApply"));
final boolean active = command.booleanPrimitiveValueOfParameterNamed("active");
return new Rate(name, percentage, productApply, active, user);
@@ -162,10 +169,9 @@ public class Rate extends AbstractAuditableCustom<AppUser, Long> {
}
final String productApplyParamName = "productApply";
if (command.isChangeInStringParameterNamed(productApplyParamName, this.productApply)) {
final String newValue = command.stringValueOfParameterNamed(productApplyParamName);
actualChanges.put(productApplyParamName, newValue);
this.productApply = StringUtils.defaultIfEmpty(newValue, null);
if (command.isChangeInIntegerParameterNamed(productApplyParamName, this.productApply)) {
final String errorMessage = "Update of Rate applies to is not supported";
throw new ChargeParameterUpdateNotSupportedException("rate.applies.to", errorMessage);
}
final String activeParamName = "active";
@@ -192,7 +198,7 @@ public class Rate extends AbstractAuditableCustom<AppUser, Long> {
return approveUserId;
}
public void assembleFrom(String name, BigDecimal percentage, String productApply, boolean active){
public void assembleFrom(String name, BigDecimal percentage, Integer productApply, boolean active){
this.name = name;
this.percentage = percentage;
this.productApply = productApply;
@@ -0,0 +1,66 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.rate.domain;
public enum RateAppliesTo {
INVALID(0, "rateAppliesTo.invalid"),
LOAN(1, "rateAppliesTo.loan");
private final Integer value;
private final String code;
private RateAppliesTo(final Integer value, final String code) {
this.value = value;
this.code = code;
}
public Integer getValue() {
return this.value;
}
public String getCode() {
return this.code;
}
public static RateAppliesTo fromInt(final Integer rateAppliesTo) {
RateAppliesTo rateAppliesToType = RateAppliesTo.INVALID;
if (rateAppliesTo != null) {
switch (rateAppliesTo) {
case 1:
rateAppliesToType = LOAN;
break;
default:
rateAppliesToType = INVALID;
break;
}
}
return rateAppliesToType;
}
public boolean isLoanRate() {
return this.value.equals(RateAppliesTo.LOAN.getValue());
}
public static Object[] validValues() {
return new Object[] { RateAppliesTo.LOAN.getValue() };
}
}
@@ -0,0 +1,47 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.rate.service;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.portfolio.rate.domain.RateAppliesTo;
public class RateEnumerations {
public static EnumOptionData rateAppliesTo(final int id) {
return rateAppliesTo(RateAppliesTo.fromInt(id));
}
public static EnumOptionData rateAppliesTo(final RateAppliesTo type) {
EnumOptionData optionData = null;
switch (type) {
case LOAN:
optionData = new EnumOptionData(RateAppliesTo.LOAN.getValue().longValue(), RateAppliesTo.LOAN.getCode(), "Loan");
break;
default:
optionData = new EnumOptionData(RateAppliesTo.INVALID.getValue().longValue(), RateAppliesTo.INVALID.getCode(),
"Invalid");
break;
}
return optionData;
}
}
@@ -19,8 +19,11 @@
package org.apache.fineract.portfolio.rate.service;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.charge.service.ChargeEnumerations;
import org.apache.fineract.portfolio.rate.domain.RateAppliesTo;
import org.apache.fineract.portfolio.rate.exception.RateNotFoundException;
import org.apache.fineract.portfolio.rate.domain.Rate;
import org.apache.fineract.portfolio.rate.data.RateData;
@@ -92,7 +95,7 @@ public class RateReadServiceImpl implements RateReadService {
this.context.authenticatedUser();
final RateMapper rm = new RateMapper();
final String sql = "select " + rm.rateSchema() + " where r.active = ? and product_apply=?";
return this.jdbcTemplate.query(sql, rm, new Object[]{true, "m_loan"});
return this.jdbcTemplate.query(sql, rm, new Object[]{true, RateAppliesTo.LOAN.getValue() });
}
@Override
@@ -133,16 +136,17 @@ public class RateReadServiceImpl implements RateReadService {
final Long id = resultSet.getLong("id");
final String name = resultSet.getString("name");
final BigDecimal percentage = resultSet.getBigDecimal("percentage");
final String productApply = resultSet.getString("productApply");
final Integer productApply = resultSet.getInt("productApply");
final EnumOptionData productAppliesTo = RateEnumerations.rateAppliesTo(productApply);
final boolean active = resultSet.getBoolean("active");
return RateData.instance(id, name, percentage, productApply, active);
return RateData.instance(id, name, percentage, productAppliesTo, active);
}
public RateData mapRow(Rate rateResponse, int i) {
final Long id = rateResponse.getId();
final String name = rateResponse.getName();
final BigDecimal percentage = rateResponse.getPercentage();
final String productApply = rateResponse.getProductApply();
final EnumOptionData productApply = RateEnumerations.rateAppliesTo(rateResponse.getProductApply());;
final boolean active = rateResponse.isActive();
return RateData.instance(id, name, percentage, productApply, active);
}
@@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS `m_rate` (
`name` varchar(250) NOT NULL,
`percentage` decimal(10,2) NOT NULL,
`active` tinyint(1) DEFAULT '0',
`product_apply` varchar(100) NOT NULL,
`product_apply` smallint(5) NOT NULL,
`created_date` datetime NULL DEFAULT NULL,
`createdby_id` bigint(20) NOT NULL,
`lastmodifiedby_id` bigint(20) NOT NULL,
@@ -58,10 +58,10 @@ CREATE TABLE IF NOT EXISTS `m_product_loan_rate` (
INSERT INTO `m_permission`
(`grouping`,`code`,`entity_name`,`action_name`,`can_maker_checker`) VALUES
('organisation', 'READ_RATE', 'RATE', 'CREATE', '1'),
('organisation', 'CREATE_RATE', 'RATE', 'CREATE', '1'),
('organisation', 'UPDATE_RATE', 'RATE', 'UPDATE', '1');
INSERT INTO `c_configuration`
(`name`, `value`, `enabled`, `is_trap_door`, `description`) VALUES
('vat-tax', 12, 0, 0, 'VAT tax'),
('sub-rates', 12, 0, 0, 'Enable Rates Module');;
('sub-rates', 0, 0, 0, 'Enable Rates Module');