josehernandezfintecheandomx commented on code in PR #2783:
URL: https://github.com/apache/fineract/pull/2783#discussion_r1042242044


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientDomainServiceImpl.java:
##########
@@ -0,0 +1,225 @@
+/**
+ * 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.client.domain;
+
+import java.time.LocalDate;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.codes.domain.CodeValue;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.domain.ExternalId;
+import org.apache.fineract.infrastructure.core.service.DateUtils;
+import org.apache.fineract.organisation.office.domain.Office;
+import org.apache.fineract.organisation.staff.domain.Staff;
+import org.apache.fineract.portfolio.client.api.ClientApiConstants;
+import org.apache.fineract.portfolio.group.domain.Group;
+import org.apache.fineract.useradministration.domain.AppUser;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ClientDomainServiceImpl implements ClientDomainService {
+
+    @Override
+    public Client createClient(final AppUser currentUser, final Office 
clientOffice, final Group clientParentGroup, final Staff staff,
+            final Long savingsProductId, final CodeValue gender, final 
CodeValue clientType, final CodeValue clientClassification,
+            final Integer legalForm, final ExternalId externalId, final 
JsonCommand command) {
+
+        final String accountNo = 
command.stringValueOfParameterNamed(ClientApiConstants.accountNoParamName);
+        final String mobileNo = 
command.stringValueOfParameterNamed(ClientApiConstants.mobileNoParamName);
+        final String emailAddress = 
command.stringValueOfParameterNamed(ClientApiConstants.emailAddressParamName);
+
+        final String firstname = 
command.stringValueOfParameterNamed(ClientApiConstants.firstnameParamName);
+        final String middlename = 
command.stringValueOfParameterNamed(ClientApiConstants.middlenameParamName);
+        final String lastname = 
command.stringValueOfParameterNamed(ClientApiConstants.lastnameParamName);
+        final String fullname = 
command.stringValueOfParameterNamed(ClientApiConstants.fullnameParamName);
+
+        final boolean isStaff = 
command.booleanPrimitiveValueOfParameterNamed(ClientApiConstants.isStaffParamName);
+
+        final LocalDate dataOfBirth = 
command.localDateValueOfParameterNamed(ClientApiConstants.dateOfBirthParamName);
+
+        ClientStatus status = ClientStatus.PENDING;
+        boolean active = false;
+        if (command.hasParameter("active")) {
+            active = 
command.booleanPrimitiveValueOfParameterNamed(ClientApiConstants.activeParamName);
+        }
+
+        LocalDate activationDate = null;
+        LocalDate officeJoiningDate = null;
+        if (active) {
+            status = ClientStatus.ACTIVE;
+            activationDate = 
command.localDateValueOfParameterNamed(ClientApiConstants.activationDateParamName);
+            officeJoiningDate = activationDate;
+        }
+
+        LocalDate submittedOnDate = DateUtils.getBusinessLocalDate();
+        if (command.hasParameter(ClientApiConstants.submittedOnDateParamName)) 
{
+            submittedOnDate = 
command.localDateValueOfParameterNamed(ClientApiConstants.submittedOnDateParamName);
+        }
+        if (active && submittedOnDate.isAfter(activationDate)) {
+            submittedOnDate = activationDate;
+        }
+        final Long savingsAccountId = null;
+
+        return Client.instance(currentUser, status, clientOffice, 
clientParentGroup, accountNo, firstname, middlename, lastname, fullname,
+                activationDate, officeJoiningDate, externalId, mobileNo, 
emailAddress, staff, submittedOnDate, savingsProductId,
+                savingsAccountId, dataOfBirth, gender, clientType, 
clientClassification, legalForm, isStaff);
+
+    }
+
+    @Override
+    public Map<String, Object> updateClient(Client client, final ExternalId 
externalId, final JsonCommand command) {
+
+        final Map<String, Object> actualChanges = new LinkedHashMap<>(9);
+
+        if 
(command.isChangeInIntegerParameterNamed(ClientApiConstants.statusParamName, 
client.getStatus())) {
+            final Integer newValue = 
command.integerValueOfParameterNamed(ClientApiConstants.statusParamName);
+            actualChanges.put(ClientApiConstants.statusParamName, 
ClientEnumerations.status(newValue));
+            client.setStatus(ClientStatus.fromInt(newValue).getValue());
+        }
+
+        if 
(command.isChangeInStringParameterNamed(ClientApiConstants.accountNoParamName, 
client.getAccountNumber())) {
+            final String newValue = 
command.stringValueOfParameterNamed(ClientApiConstants.accountNoParamName);
+            actualChanges.put(ClientApiConstants.accountNoParamName, newValue);
+            client.setAccountNumber(StringUtils.defaultIfEmpty(newValue, 
null));
+        }
+
+        if 
(command.isChangeInStringParameterNamed(ClientApiConstants.externalIdParamName, 
externalId.getValue())) {
+            actualChanges.put(ClientApiConstants.externalIdParamName, 
externalId.getValue());
+            client.setExternalId(externalId);
+        }
+
+        if 
(command.isChangeInStringParameterNamed(ClientApiConstants.mobileNoParamName, 
client.getMobileNo())) {
+            final String newValue = 
command.stringValueOfParameterNamed(ClientApiConstants.mobileNoParamName);
+            actualChanges.put(ClientApiConstants.mobileNoParamName, newValue);
+            client.setMobileNo(StringUtils.defaultIfEmpty(newValue, null));
+        }
+
+        if 
(command.isChangeInStringParameterNamed(ClientApiConstants.emailAddressParamName,
 client.getEmailAddress())) {
+            final String newValue = 
command.stringValueOfParameterNamed(ClientApiConstants.emailAddressParamName);
+            actualChanges.put(ClientApiConstants.emailAddressParamName, 
newValue);
+            client.setEmailAddress(StringUtils.defaultIfEmpty(newValue, null));
+        }
+
+        if 
(command.isChangeInStringParameterNamed(ClientApiConstants.firstnameParamName, 
client.getFirstname())) {
+            final String newValue = 
command.stringValueOfParameterNamed(ClientApiConstants.firstnameParamName);
+            actualChanges.put(ClientApiConstants.firstnameParamName, newValue);
+            client.setFirstname(StringUtils.defaultIfEmpty(newValue, null));
+        }
+
+        if 
(command.isChangeInStringParameterNamed(ClientApiConstants.middlenameParamName, 
client.getMiddlename())) {
+            final String newValue = 
command.stringValueOfParameterNamed(ClientApiConstants.middlenameParamName);
+            actualChanges.put(ClientApiConstants.middlenameParamName, 
newValue);
+            client.setMiddlename(StringUtils.defaultIfEmpty(newValue, null));
+        }
+
+        if 
(command.isChangeInStringParameterNamed(ClientApiConstants.lastnameParamName, 
client.getLastname())) {
+            final String newValue = 
command.stringValueOfParameterNamed(ClientApiConstants.lastnameParamName);
+            actualChanges.put(ClientApiConstants.lastnameParamName, newValue);
+            client.setLastname(StringUtils.defaultIfEmpty(newValue, null));
+        }
+
+        if 
(command.isChangeInStringParameterNamed(ClientApiConstants.fullnameParamName, 
client.getFullname())) {
+            final String newValue = 
command.stringValueOfParameterNamed(ClientApiConstants.fullnameParamName);
+            actualChanges.put(ClientApiConstants.fullnameParamName, newValue);
+            client.setFullname(newValue);
+        }
+
+        if 
(command.isChangeInLongParameterNamed(ClientApiConstants.staffIdParamName, 
client.staffId())) {
+            final Long newValue = 
command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
+            actualChanges.put(ClientApiConstants.staffIdParamName, newValue);
+        }
+
+        if 
(command.isChangeInLongParameterNamed(ClientApiConstants.genderIdParamName, 
client.genderId())) {
+            final Long newValue = 
command.longValueOfParameterNamed(ClientApiConstants.genderIdParamName);
+            actualChanges.put(ClientApiConstants.genderIdParamName, newValue);
+        }
+
+        if 
(command.isChangeInLongParameterNamed(ClientApiConstants.savingsProductIdParamName,
 client.savingsProductId())) {
+            final Long newValue = 
command.longValueOfParameterNamed(ClientApiConstants.savingsProductIdParamName);
+            actualChanges.put(ClientApiConstants.savingsProductIdParamName, 
newValue);
+        }
+
+        if 
(command.isChangeInLongParameterNamed(ClientApiConstants.clientTypeIdParamName, 
client.clientTypeId())) {
+            final Long newValue = 
command.longValueOfParameterNamed(ClientApiConstants.clientTypeIdParamName);
+            actualChanges.put(ClientApiConstants.clientTypeIdParamName, 
newValue);
+        }
+
+        if 
(command.isChangeInLongParameterNamed(ClientApiConstants.clientClassificationIdParamName,
 client.clientClassificationId())) {
+            final Long newValue = 
command.longValueOfParameterNamed(ClientApiConstants.clientClassificationIdParamName);
+            
actualChanges.put(ClientApiConstants.clientClassificationIdParamName, newValue);
+        }
+
+        if 
(command.isChangeInIntegerParameterNamed(ClientApiConstants.legalFormIdParamName,
 client.getLegalForm())) {
+            final Integer newValue = 
command.integerValueOfParameterNamed(ClientApiConstants.legalFormIdParamName);
+            if (newValue != null) {
+                LegalForm legalForm = LegalForm.fromInt(newValue);
+                if (legalForm != null) {
+                    actualChanges.put(ClientApiConstants.legalFormIdParamName, 
ClientEnumerations.legalForm(newValue));
+                    client.setLegalForm(legalForm.getValue());
+                    client.resetDerivedNames(legalForm);
+                } else {
+                    actualChanges.put(ClientApiConstants.legalFormIdParamName, 
null);
+                    client.setLegalForm(null);
+                }
+            } else {
+                actualChanges.put(ClientApiConstants.legalFormIdParamName, 
null);
+                client.setLegalForm(null);
+            }
+        }
+
+        final String dateFormatAsInput = command.dateFormat();
+        final String localeAsInput = command.locale();
+
+        if 
(command.isChangeInLocalDateParameterNamed(ClientApiConstants.activationDateParamName,
 client.getActivationDate())) {
+            final String valueAsInput = 
command.stringValueOfParameterNamed(ClientApiConstants.activationDateParamName);
+            actualChanges.put(ClientApiConstants.activationDateParamName, 
valueAsInput);
+            actualChanges.put(ClientApiConstants.dateFormatParamName, 
dateFormatAsInput);
+            actualChanges.put(ClientApiConstants.localeParamName, 
localeAsInput);
+
+            
client.setActivationDate(command.localDateValueOfParameterNamed(ClientApiConstants.activationDateParamName));
+            client.setOfficeJoiningDate(client.getActivationDate());
+        }
+
+        if 
(command.isChangeInLocalDateParameterNamed(ClientApiConstants.dateOfBirthParamName,
 client.getDateOfBirth())) {
+            final String valueAsInput = 
command.stringValueOfParameterNamed(ClientApiConstants.dateOfBirthParamName);
+            actualChanges.put(ClientApiConstants.dateOfBirthParamName, 
valueAsInput);
+            actualChanges.put(ClientApiConstants.dateFormatParamName, 
dateFormatAsInput);
+            actualChanges.put(ClientApiConstants.localeParamName, 
localeAsInput);
+
+            
client.setDateOfBirth(command.localDateValueOfParameterNamed(ClientApiConstants.dateOfBirthParamName));
+        }
+
+        if 
(command.isChangeInLocalDateParameterNamed(ClientApiConstants.submittedOnDateParamName,
 client.getSubmittedOnDate())) {
+            final String valueAsInput = 
command.stringValueOfParameterNamed(ClientApiConstants.submittedOnDateParamName);
+            actualChanges.put(ClientApiConstants.submittedOnDateParamName, 
valueAsInput);
+            actualChanges.put(ClientApiConstants.dateFormatParamName, 
dateFormatAsInput);
+            actualChanges.put(ClientApiConstants.localeParamName, 
localeAsInput);
+
+            
client.setSubmittedOnDate(command.localDateValueOfParameterNamed(ClientApiConstants.submittedOnDateParamName));
+        }
+
+        // validateUpdate();

Review Comment:
   Done



-- 
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-unsubscr...@fineract.apache.org

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

Reply via email to