forked from apache/fineract
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from FITER1/MON-94
MON-94 validate deposit period against frequency
- Loading branch information
Showing
12 changed files
with
256 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
ff4j: | ||
autocreate: false | ||
audit: false | ||
features: | ||
- uid: savings.rd.minimumduration_mon94 | ||
enable: true | ||
description: >- | ||
When frequency is set as daily, minimum duration is 1 month. When set as | ||
weekly, monthly, bi-weekly minimum is 3 months. | ||
custom-properties: | ||
- name: daily | ||
type: org.ff4j.property.PropertyInt | ||
value: 1 | ||
- name: weekly | ||
type: org.ff4j.property.PropertyInt | ||
value: 3 | ||
- name: bi-weekly | ||
type: org.ff4j.property.PropertyInt | ||
value: 3 | ||
- name: monthly | ||
type: org.ff4j.property.PropertyInt | ||
value: 3 | ||
- name: other | ||
type: org.ff4j.property.PropertyInt | ||
value: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
ff4j: | ||
autocreate: false | ||
audit: false | ||
features: | ||
- uid: savings.rd.minimumduration_mon94 | ||
enable: false | ||
description: >- | ||
When frequency is set as daily, minimum duration is 1 month. When set as | ||
weekly, monthly, bi-weekly minimum is 3 months. | ||
custom-properties: | ||
- name: daily | ||
type: org.ff4j.property.PropertyInt | ||
value: 1 | ||
- name: weekly | ||
type: org.ff4j.property.PropertyInt | ||
value: 3 | ||
- name: bi-weekly | ||
type: org.ff4j.property.PropertyInt | ||
value: 3 | ||
- name: monthly | ||
type: org.ff4j.property.PropertyInt | ||
value: 3 | ||
- name: other | ||
type: org.ff4j.property.PropertyInt | ||
value: 3 |
61 changes: 61 additions & 0 deletions
61
fineract-provider/src/main/java/io/fiter/ff4j/FF4JConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.fiter.ff4j; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import lombok.SneakyThrows; | ||
import org.apache.fineract.infrastructure.documentmanagement.contentrepository.FileSystemContentRepository; | ||
import org.ff4j.FF4j; | ||
import org.ff4j.audit.repository.EventRepository; | ||
import org.ff4j.audit.repository.InMemoryEventRepository; | ||
import org.ff4j.conf.FF4jConfiguration; | ||
import org.ff4j.core.FeatureStore; | ||
import org.ff4j.parser.yaml.YamlParser; | ||
import org.ff4j.property.store.InMemoryPropertyStore; | ||
import org.ff4j.property.store.PropertyStore; | ||
import org.ff4j.store.InMemoryFeatureStore; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class FF4JConfig { | ||
|
||
@Value("${fiter.features.ff4j}") | ||
private String ff4jFileName; | ||
|
||
@SneakyThrows | ||
@Bean | ||
public FF4j getFF4j() { | ||
|
||
final String templateRepository = FileSystemContentRepository.FINERACT_BASE_DIR + File.separator + "ff4j" + File.separator | ||
+ this.ff4jFileName; | ||
final File configFile = new File(templateRepository); | ||
InputStream targetStream = null; | ||
try { | ||
targetStream = new FileInputStream(configFile); | ||
} catch (IOException ex) { | ||
throw ex; | ||
} | ||
// We imported ff4j-config-yaml to have this | ||
FF4jConfiguration initConfig = new YamlParser().parseConfigurationFile(targetStream); | ||
// LOGGER.info("Default features have been loaded {}", initConfig.getFeatures().keySet()); | ||
|
||
// 1. Define the store you want for Feature, Properties, Audit among 20 tech | ||
FeatureStore featureStore = new InMemoryFeatureStore(initConfig); | ||
PropertyStore propertyStore = new InMemoryPropertyStore(initConfig); | ||
EventRepository logsAudit = new InMemoryEventRepository(); | ||
|
||
// 2. Build FF4j | ||
FF4j ff4jBean = new FF4j(); | ||
ff4jBean.setPropertiesStore(propertyStore); | ||
ff4jBean.setFeatureStore(featureStore); | ||
ff4jBean.setEventRepository(logsAudit); | ||
|
||
// 3. Complete setup | ||
ff4jBean.setEnableAudit(false); | ||
ff4jBean.setAutocreate(true); | ||
return ff4jBean; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
fineract-provider/src/main/java/io/fiter/ff4j/validators/FeatureList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.fiter.ff4j.validators; | ||
|
||
public class FeatureList { | ||
|
||
private FeatureList() {} | ||
|
||
protected static final String MINIMUM_RD_PERIOD = "savings.rd.minimumduration_mon94"; | ||
} |
72 changes: 72 additions & 0 deletions
72
fineract-provider/src/main/java/io/fiter/ff4j/validators/SavingsAccountFeatureValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.fiter.ff4j.validators; | ||
|
||
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.depositPeriodFrequencyIdParamName; | ||
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.depositPeriodParamName; | ||
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.minDepositTermParamName; | ||
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.minDepositTermTypeIdParamName; | ||
|
||
import com.google.gson.JsonElement; | ||
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; | ||
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; | ||
import org.apache.fineract.portfolio.savings.DepositAccountType; | ||
import org.apache.fineract.portfolio.savings.SavingsPeriodFrequencyType; | ||
import org.ff4j.FF4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SavingsAccountFeatureValidator { | ||
|
||
private final FF4j ff4j; | ||
private final FromJsonHelper fromApiJsonHelper; | ||
|
||
@Autowired | ||
public SavingsAccountFeatureValidator(FF4j ff4j, FromJsonHelper fromApiJsonHelper) { | ||
this.ff4j = ff4j; | ||
this.fromApiJsonHelper = fromApiJsonHelper; | ||
} | ||
|
||
public void validateDepositDetailsForUpdate(final JsonElement element, final DataValidatorBuilder baseDataValidator, | ||
DepositAccountType depositAccountType) { | ||
|
||
if (ff4j.check(FeatureList.MINIMUM_RD_PERIOD) && depositAccountType.equals(DepositAccountType.RECURRING_DEPOSIT)) { | ||
|
||
Integer minDepositTermType = null; | ||
|
||
if (fromApiJsonHelper.parameterExists(minDepositTermTypeIdParamName, element)) { | ||
minDepositTermType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(minDepositTermTypeIdParamName, element); | ||
} | ||
|
||
Integer minTerm = null; | ||
if (fromApiJsonHelper.parameterExists(minDepositTermParamName, element)) { | ||
minTerm = fromApiJsonHelper.extractIntegerSansLocaleNamed(minDepositTermParamName, element); | ||
} | ||
|
||
if (fromApiJsonHelper.parameterExists(depositPeriodParamName, element)) { | ||
minTerm = fromApiJsonHelper.extractIntegerSansLocaleNamed(depositPeriodParamName, element); | ||
|
||
} | ||
|
||
if (fromApiJsonHelper.parameterExists(depositPeriodFrequencyIdParamName, element)) { | ||
minDepositTermType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(depositPeriodFrequencyIdParamName, element); | ||
} | ||
|
||
if (minDepositTermType != null && minTerm != null) { | ||
|
||
Integer minDurationAllowed = 0; | ||
if (minDepositTermType.equals(SavingsPeriodFrequencyType.DAYS.getValue())) { | ||
minDurationAllowed = ff4j.getFeature(FeatureList.MINIMUM_RD_PERIOD).getCustomProperties().get("daily").asInt(); | ||
} else { | ||
minDurationAllowed = ff4j.getFeature(FeatureList.MINIMUM_RD_PERIOD).getCustomProperties().get("other").asInt(); | ||
} | ||
|
||
if (minDurationAllowed > minTerm) { | ||
baseDataValidator.reset().parameter(minDepositTermTypeIdParamName).failWithCodeNoParameterAddedToErrorCode( | ||
"period.not.allowed", "Period less than minimum allowed for term type"); | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters