You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "Cocoa-Puffs (via GitHub)" <gi...@apache.org> on 2025/03/12 12:04:44 UTC

[PR] FINERACT-2181: config updater service plus liquibase migration property [fineract]

Cocoa-Puffs opened a new pull request, #4453:
URL: https://github.com/apache/fineract/pull/4453

   ## Description
   
   Describe the changes made and why they were made.
   
   Ignore if these details are present on the associated [Apache Fineract JIRA ticket](https://github.com/apache/fineract/pull/1284).
   
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
   
   - [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   
   - [ ] Create/update unit or integration tests for verifying the changes made.
   
   - [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
   
   - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
   
   - [ ] Submission is not a "code dump".  (Large changes can be made "in repository" via a branch.  Ask on the developer mailing list for guidance, if required.)
   
   FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2181: initial rounding-mode configuration [fineract]

Posted by "Cocoa-Puffs (via GitHub)" <gi...@apache.org>.
Cocoa-Puffs commented on code in PR #4453:
URL: https://github.com/apache/fineract/pull/4453#discussion_r1991402813


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationPropertyUpdateService.java:
##########
@@ -0,0 +1,100 @@
+/**
+ * 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.infrastructure.configuration.service;
+
+import java.time.LocalDate;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
+import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
+import org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.security.exception.ForcePasswordResetException;
+import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
+import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService;
+import org.apache.fineract.portfolio.savings.data.SavingsProductData;
+import org.apache.fineract.portfolio.savings.service.SavingsProductReadPlatformService;
+import org.springframework.stereotype.Service;
+
+@Service
+@AllArgsConstructor
+public class GlobalConfigurationPropertyUpdateService {
+
+    private final LoanProductReadPlatformService loanProductReadPlatformService;
+    private final SavingsProductReadPlatformService savingsProductReadPlatformService;
+
+    public Map<String, Object> update(final GlobalConfigurationProperty property, final JsonCommand command) {
+        final Map<String, Object> actualChanges = new LinkedHashMap<>(7);
+
+        if (property.isTrapDoor() && isAnyProductAlreadyCreated()) {
+            throw new GlobalConfigurationPropertyCannotBeModfied(property.getId());
+        }
+
+        final String enabledParamName = "enabled";
+        if (command.isChangeInBooleanParameterNamed(enabledParamName, property.isEnabled())) {
+            final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(enabledParamName);
+            actualChanges.put(enabledParamName, newValue);
+            property.setEnabled(newValue);
+        }
+
+        final String valueParamName = "value";
+        final Long previousValue = property.getValue();
+        if (command.isChangeInLongParameterNamed(valueParamName, property.getValue())) {
+            final Long newValue = command.longValueOfParameterNamed(valueParamName);
+            actualChanges.put(valueParamName, newValue);
+            property.setValue(newValue);
+        }
+
+        final String dateValueParamName = "dateValue";
+        if (command.isChangeInDateParameterNamed(dateValueParamName, property.getDateValue())) {
+            final LocalDate newDateValue = command.localDateValueOfParameterNamed(dateValueParamName);
+            actualChanges.put(dateValueParamName, newDateValue);
+            property.setDateValue(newDateValue);
+        }
+
+        final String stringValueParamName = "stringValue";
+        if (command.isChangeInStringParameterNamed(stringValueParamName, property.getStringValue())) {
+            final String newStringValue = command.stringValueOfParameterNamed(stringValueParamName);
+            actualChanges.put(stringValueParamName, newStringValue);
+            property.setStringValue(newStringValue);
+        }
+
+        final String passwordPropertyName = GlobalConfigurationConstants.FORCE_PASSWORD_RESET_DAYS;
+        if (property.getName().equalsIgnoreCase(passwordPropertyName)) {
+            if ((property.isEnabled() && command.hasParameter(valueParamName) && (property.getValue() == 0))
+                    || (property.isEnabled() && !command.hasParameter(valueParamName) && (previousValue == 0))) {
+                throw new ForcePasswordResetException();
+            }
+        }
+
+        return actualChanges;
+    }
+
+    private boolean isAnyProductAlreadyCreated() {

Review Comment:
   sure, so I should just take a jdbcTemplate and check the row counts in those tables right?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2181: initial rounding-mode configuration [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4453:
URL: https://github.com/apache/fineract/pull/4453#discussion_r1991383471


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationPropertyUpdateService.java:
##########
@@ -0,0 +1,100 @@
+/**
+ * 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.infrastructure.configuration.service;
+
+import java.time.LocalDate;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
+import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
+import org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.security.exception.ForcePasswordResetException;
+import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
+import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService;
+import org.apache.fineract.portfolio.savings.data.SavingsProductData;
+import org.apache.fineract.portfolio.savings.service.SavingsProductReadPlatformService;
+import org.springframework.stereotype.Service;
+
+@Service
+@AllArgsConstructor
+public class GlobalConfigurationPropertyUpdateService {
+
+    private final LoanProductReadPlatformService loanProductReadPlatformService;
+    private final SavingsProductReadPlatformService savingsProductReadPlatformService;
+
+    public Map<String, Object> update(final GlobalConfigurationProperty property, final JsonCommand command) {
+        final Map<String, Object> actualChanges = new LinkedHashMap<>(7);
+
+        if (property.isTrapDoor() && isAnyProductAlreadyCreated()) {
+            throw new GlobalConfigurationPropertyCannotBeModfied(property.getId());
+        }
+
+        final String enabledParamName = "enabled";
+        if (command.isChangeInBooleanParameterNamed(enabledParamName, property.isEnabled())) {
+            final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(enabledParamName);
+            actualChanges.put(enabledParamName, newValue);
+            property.setEnabled(newValue);
+        }
+
+        final String valueParamName = "value";
+        final Long previousValue = property.getValue();
+        if (command.isChangeInLongParameterNamed(valueParamName, property.getValue())) {
+            final Long newValue = command.longValueOfParameterNamed(valueParamName);
+            actualChanges.put(valueParamName, newValue);
+            property.setValue(newValue);
+        }
+
+        final String dateValueParamName = "dateValue";
+        if (command.isChangeInDateParameterNamed(dateValueParamName, property.getDateValue())) {
+            final LocalDate newDateValue = command.localDateValueOfParameterNamed(dateValueParamName);
+            actualChanges.put(dateValueParamName, newDateValue);
+            property.setDateValue(newDateValue);
+        }
+
+        final String stringValueParamName = "stringValue";
+        if (command.isChangeInStringParameterNamed(stringValueParamName, property.getStringValue())) {
+            final String newStringValue = command.stringValueOfParameterNamed(stringValueParamName);
+            actualChanges.put(stringValueParamName, newStringValue);
+            property.setStringValue(newStringValue);
+        }
+
+        final String passwordPropertyName = GlobalConfigurationConstants.FORCE_PASSWORD_RESET_DAYS;
+        if (property.getName().equalsIgnoreCase(passwordPropertyName)) {
+            if ((property.isEnabled() && command.hasParameter(valueParamName) && (property.getValue() == 0))
+                    || (property.isEnabled() && !command.hasParameter(valueParamName) && (previousValue == 0))) {
+                throw new ForcePasswordResetException();
+            }
+        }
+
+        return actualChanges;
+    }
+
+    private boolean isAnyProductAlreadyCreated() {

Review Comment:
   I would rather like an option where:
   we are checking only the existence of any "loan (m_loan)", "savings (m_savings_account)", or "shares (m_share_account)".
   `SELECT COUNT(1) ...` is more than enough, we dont need to fetch any data!
   
   Any account instead of product!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2181: initial rounding-mode configuration [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4453:
URL: https://github.com/apache/fineract/pull/4453#discussion_r1991383471


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationPropertyUpdateService.java:
##########
@@ -0,0 +1,100 @@
+/**
+ * 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.infrastructure.configuration.service;
+
+import java.time.LocalDate;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
+import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
+import org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.security.exception.ForcePasswordResetException;
+import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
+import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService;
+import org.apache.fineract.portfolio.savings.data.SavingsProductData;
+import org.apache.fineract.portfolio.savings.service.SavingsProductReadPlatformService;
+import org.springframework.stereotype.Service;
+
+@Service
+@AllArgsConstructor
+public class GlobalConfigurationPropertyUpdateService {
+
+    private final LoanProductReadPlatformService loanProductReadPlatformService;
+    private final SavingsProductReadPlatformService savingsProductReadPlatformService;
+
+    public Map<String, Object> update(final GlobalConfigurationProperty property, final JsonCommand command) {
+        final Map<String, Object> actualChanges = new LinkedHashMap<>(7);
+
+        if (property.isTrapDoor() && isAnyProductAlreadyCreated()) {
+            throw new GlobalConfigurationPropertyCannotBeModfied(property.getId());
+        }
+
+        final String enabledParamName = "enabled";
+        if (command.isChangeInBooleanParameterNamed(enabledParamName, property.isEnabled())) {
+            final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(enabledParamName);
+            actualChanges.put(enabledParamName, newValue);
+            property.setEnabled(newValue);
+        }
+
+        final String valueParamName = "value";
+        final Long previousValue = property.getValue();
+        if (command.isChangeInLongParameterNamed(valueParamName, property.getValue())) {
+            final Long newValue = command.longValueOfParameterNamed(valueParamName);
+            actualChanges.put(valueParamName, newValue);
+            property.setValue(newValue);
+        }
+
+        final String dateValueParamName = "dateValue";
+        if (command.isChangeInDateParameterNamed(dateValueParamName, property.getDateValue())) {
+            final LocalDate newDateValue = command.localDateValueOfParameterNamed(dateValueParamName);
+            actualChanges.put(dateValueParamName, newDateValue);
+            property.setDateValue(newDateValue);
+        }
+
+        final String stringValueParamName = "stringValue";
+        if (command.isChangeInStringParameterNamed(stringValueParamName, property.getStringValue())) {
+            final String newStringValue = command.stringValueOfParameterNamed(stringValueParamName);
+            actualChanges.put(stringValueParamName, newStringValue);
+            property.setStringValue(newStringValue);
+        }
+
+        final String passwordPropertyName = GlobalConfigurationConstants.FORCE_PASSWORD_RESET_DAYS;
+        if (property.getName().equalsIgnoreCase(passwordPropertyName)) {
+            if ((property.isEnabled() && command.hasParameter(valueParamName) && (property.getValue() == 0))
+                    || (property.isEnabled() && !command.hasParameter(valueParamName) && (previousValue == 0))) {
+                throw new ForcePasswordResetException();
+            }
+        }
+
+        return actualChanges;
+    }
+
+    private boolean isAnyProductAlreadyCreated() {

Review Comment:
   I would rather like an option where:
   we are checking only the existence of any "loan (m_loan)", "savings (m_savings_account)", or "shares (m_share_account)".
   `SELECT COUNT(1) ...` is more than enough, we dont need to fetch any data!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2181: initial rounding-mode configuration [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4453:
URL: https://github.com/apache/fineract/pull/4453#discussion_r1991416910


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationPropertyUpdateService.java:
##########
@@ -0,0 +1,100 @@
+/**
+ * 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.infrastructure.configuration.service;
+
+import java.time.LocalDate;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
+import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
+import org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.security.exception.ForcePasswordResetException;
+import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
+import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService;
+import org.apache.fineract.portfolio.savings.data.SavingsProductData;
+import org.apache.fineract.portfolio.savings.service.SavingsProductReadPlatformService;
+import org.springframework.stereotype.Service;
+
+@Service
+@AllArgsConstructor
+public class GlobalConfigurationPropertyUpdateService {
+
+    private final LoanProductReadPlatformService loanProductReadPlatformService;
+    private final SavingsProductReadPlatformService savingsProductReadPlatformService;
+
+    public Map<String, Object> update(final GlobalConfigurationProperty property, final JsonCommand command) {
+        final Map<String, Object> actualChanges = new LinkedHashMap<>(7);
+
+        if (property.isTrapDoor() && isAnyProductAlreadyCreated()) {
+            throw new GlobalConfigurationPropertyCannotBeModfied(property.getId());
+        }
+
+        final String enabledParamName = "enabled";
+        if (command.isChangeInBooleanParameterNamed(enabledParamName, property.isEnabled())) {
+            final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(enabledParamName);
+            actualChanges.put(enabledParamName, newValue);
+            property.setEnabled(newValue);
+        }
+
+        final String valueParamName = "value";
+        final Long previousValue = property.getValue();
+        if (command.isChangeInLongParameterNamed(valueParamName, property.getValue())) {
+            final Long newValue = command.longValueOfParameterNamed(valueParamName);
+            actualChanges.put(valueParamName, newValue);
+            property.setValue(newValue);
+        }
+
+        final String dateValueParamName = "dateValue";
+        if (command.isChangeInDateParameterNamed(dateValueParamName, property.getDateValue())) {
+            final LocalDate newDateValue = command.localDateValueOfParameterNamed(dateValueParamName);
+            actualChanges.put(dateValueParamName, newDateValue);
+            property.setDateValue(newDateValue);
+        }
+
+        final String stringValueParamName = "stringValue";
+        if (command.isChangeInStringParameterNamed(stringValueParamName, property.getStringValue())) {
+            final String newStringValue = command.stringValueOfParameterNamed(stringValueParamName);
+            actualChanges.put(stringValueParamName, newStringValue);
+            property.setStringValue(newStringValue);
+        }
+
+        final String passwordPropertyName = GlobalConfigurationConstants.FORCE_PASSWORD_RESET_DAYS;
+        if (property.getName().equalsIgnoreCase(passwordPropertyName)) {
+            if ((property.isEnabled() && command.hasParameter(valueParamName) && (property.getValue() == 0))
+                    || (property.isEnabled() && !command.hasParameter(valueParamName) && (previousValue == 0))) {
+                throw new ForcePasswordResetException();
+            }
+        }
+
+        return actualChanges;
+    }
+
+    private boolean isAnyProductAlreadyCreated() {

Review Comment:
   Alternatively you can use the `CriteriaQueryFactory` to build a query which do the same...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2181: initial rounding-mode configuration [fineract]

Posted by "Cocoa-Puffs (via GitHub)" <gi...@apache.org>.
Cocoa-Puffs commented on code in PR #4453:
URL: https://github.com/apache/fineract/pull/4453#discussion_r1991435845


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationPropertyUpdateService.java:
##########
@@ -0,0 +1,100 @@
+/**
+ * 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.infrastructure.configuration.service;
+
+import java.time.LocalDate;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
+import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
+import org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.security.exception.ForcePasswordResetException;
+import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
+import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService;
+import org.apache.fineract.portfolio.savings.data.SavingsProductData;
+import org.apache.fineract.portfolio.savings.service.SavingsProductReadPlatformService;
+import org.springframework.stereotype.Service;
+
+@Service
+@AllArgsConstructor
+public class GlobalConfigurationPropertyUpdateService {
+
+    private final LoanProductReadPlatformService loanProductReadPlatformService;
+    private final SavingsProductReadPlatformService savingsProductReadPlatformService;
+
+    public Map<String, Object> update(final GlobalConfigurationProperty property, final JsonCommand command) {
+        final Map<String, Object> actualChanges = new LinkedHashMap<>(7);
+
+        if (property.isTrapDoor() && isAnyProductAlreadyCreated()) {
+            throw new GlobalConfigurationPropertyCannotBeModfied(property.getId());
+        }
+
+        final String enabledParamName = "enabled";
+        if (command.isChangeInBooleanParameterNamed(enabledParamName, property.isEnabled())) {
+            final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(enabledParamName);
+            actualChanges.put(enabledParamName, newValue);
+            property.setEnabled(newValue);
+        }
+
+        final String valueParamName = "value";
+        final Long previousValue = property.getValue();
+        if (command.isChangeInLongParameterNamed(valueParamName, property.getValue())) {
+            final Long newValue = command.longValueOfParameterNamed(valueParamName);
+            actualChanges.put(valueParamName, newValue);
+            property.setValue(newValue);
+        }
+
+        final String dateValueParamName = "dateValue";
+        if (command.isChangeInDateParameterNamed(dateValueParamName, property.getDateValue())) {
+            final LocalDate newDateValue = command.localDateValueOfParameterNamed(dateValueParamName);
+            actualChanges.put(dateValueParamName, newDateValue);
+            property.setDateValue(newDateValue);
+        }
+
+        final String stringValueParamName = "stringValue";
+        if (command.isChangeInStringParameterNamed(stringValueParamName, property.getStringValue())) {
+            final String newStringValue = command.stringValueOfParameterNamed(stringValueParamName);
+            actualChanges.put(stringValueParamName, newStringValue);
+            property.setStringValue(newStringValue);
+        }
+
+        final String passwordPropertyName = GlobalConfigurationConstants.FORCE_PASSWORD_RESET_DAYS;
+        if (property.getName().equalsIgnoreCase(passwordPropertyName)) {
+            if ((property.isEnabled() && command.hasParameter(valueParamName) && (property.getValue() == 0))
+                    || (property.isEnabled() && !command.hasParameter(valueParamName) && (previousValue == 0))) {
+                throw new ForcePasswordResetException();
+            }
+        }
+
+        return actualChanges;
+    }
+
+    private boolean isAnyProductAlreadyCreated() {

Review Comment:
   I've pushed the fix, in the end I chose JdbcTemplate as it seemed simpler for this use-case



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2181: initial rounding-mode configuration [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy merged PR #4453:
URL: https://github.com/apache/fineract/pull/4453


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org