From 5a258bde90443fc95350bb2608b34e3a08975a40 Mon Sep 17 00:00:00 2001 From: Ippez Robert Date: Sat, 4 Mar 2017 10:45:17 +0300 Subject: [PATCH] FINERACT-228 --- .../client/api/ClientApiConstants.java | 8 +++---- .../portfolio/client/data/ClientData.java | 23 +++++++++++-------- .../client/data/ClientDataValidator.java | 10 ++++++++ .../portfolio/client/domain/Client.java | 21 +++++++++++++++-- .../ClientReadPlatformServiceImpl.java | 8 +++++-- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- .../V325__add_is_staff_client_data.sql | 20 ++++++++++++++++ 7 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 fineract-provider/src/main/resources/sql/migrations/core_db/V325__add_is_staff_client_data.sql diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java index fe5ec6483..bae61d575 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java @@ -89,6 +89,7 @@ public class ClientApiConstants { public static final String activationDateParamName = "activationDate"; public static final String reactivationDateParamName = "reactivationDate"; public static final String staffIdParamName = "staffId"; + public static final String isStaffParamName = "isStaff"; public static final String closureDateParamName = "closureDate"; public static final String closureReasonIdParamName = "closureReasonId"; public static final String reopenedDateParamName = "reopenedDate"; @@ -184,7 +185,7 @@ public class ClientApiConstants { mobileNoParamName, firstnameParamName, middlenameParamName, lastnameParamName, fullnameParamName, officeIdParamName, activeParamName, activationDateParamName, staffIdParamName, submittedOnDateParamName, savingsProductIdParamName, dateOfBirthParamName, genderIdParamName, clientTypeIdParamName, clientClassificationIdParamName, - clientNonPersonDetailsParamName, displaynameParamName, legalFormIdParamName, datatables)); + clientNonPersonDetailsParamName, displaynameParamName, legalFormIdParamName, datatables, isStaffParamName)); public static final Set CLIENT_NON_PERSON_CREATE_REQUEST_DATA_PARAMETERS = new HashSet<>( Arrays.asList(address,localeParamName, dateFormatParamName, incorpNumberParamName, remarksParamName, incorpValidityTillParamName, @@ -194,8 +195,7 @@ public class ClientApiConstants { dateFormatParamName, accountNoParamName, externalIdParamName, mobileNoParamName, firstnameParamName, middlenameParamName, lastnameParamName, fullnameParamName, activeParamName, activationDateParamName, staffIdParamName, savingsProductIdParamName, - dateOfBirthParamName, genderIdParamName, clientTypeIdParamName, clientClassificationIdParamName, submittedOnDateParamName, - clientNonPersonDetailsParamName, displaynameParamName, legalFormIdParamName)); + dateOfBirthParamName, genderIdParamName, clientTypeIdParamName, clientClassificationIdParamName, submittedOnDateParamName, clientNonPersonDetailsParamName, displaynameParamName, legalFormIdParamName, isStaffParamName)); public static final Set CLIENT_NON_PERSON_UPDATE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName, dateFormatParamName, incorpNumberParamName, remarksParamName, incorpValidityTillParamName, @@ -212,7 +212,7 @@ public class ClientApiConstants { transferToOfficeIdParamName, transferToOfficeNameParamName, hierarchyParamName, imageIdParamName, imagePresentParamName, staffIdParamName, staffNameParamName, timelineParamName, groupsParamName, officeOptionsParamName, staffOptionsParamName, dateOfBirthParamName, genderParamName, clientTypeParamName, clientClassificationParamName, legalFormParamName, - clientNonPersonDetailsParamName)); + clientNonPersonDetailsParamName, isStaffParamName)); public static final Set ACTIVATION_REQUEST_DATA_PARAMETERS = new HashSet<>( Arrays.asList(localeParamName, dateFormatParamName, activationDateParamName)); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java index 913ac1739..5d7e5003e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java @@ -62,6 +62,7 @@ final public class ClientData implements Comparable { private final CodeValueData gender; private final CodeValueData clientType; private final CodeValueData clientClassification; + private final Boolean isStaff; private final Long officeId; private final String officeName; @@ -138,13 +139,14 @@ final public class ClientData implements Comparable { final CodeValueData clientType = null; final CodeValueData clientClassification = null; final EnumOptionData legalForm = null; + final Boolean isStaff = false; final ClientNonPersonData clientNonPersonDetails = null; return new ClientData(accountNo, status, subStatus, officeId, officeName, transferToOfficeId, transferToOfficeName, id, firstname, middlename, lastname, fullname, displayName, externalId, mobileNo, dateOfBirth, gender, joinedDate, imageId, staffId, staffName, officeOptions, groups, staffOptions, narrations, genderOptions, timeline, savingProductOptions, savingsProductId, savingsProductName, savingsAccountId, savingAccountOptions, clientType, clientClassification, clientTypeOptions, clientClassificationOptions, clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions, - clientNonPersonDetails, clientLegalFormOptions, legalForm,address, isAddressEnabled, datatables); + clientNonPersonDetails, clientLegalFormOptions, legalForm,address, isAddressEnabled, datatables, isStaff); } @@ -159,7 +161,7 @@ final public class ClientData implements Comparable { clientData.savingsProductName, clientData.savingsAccountId, clientData.savingAccountOptions, clientData.clientType, clientData.clientClassification, templateData.clientTypeOptions, templateData.clientClassificationOptions, templateData.clientNonPersonConstitutionOptions, templateData.clientNonPersonMainBusinessLineOptions, clientData.clientNonPersonDetails, - templateData.clientLegalFormOptions, clientData.legalForm, clientData.address,clientData.isAddressEnabled, null); + templateData.clientLegalFormOptions, clientData.legalForm, clientData.address,clientData.isAddressEnabled, null, clientData.isStaff); } @@ -175,7 +177,7 @@ final public class ClientData implements Comparable { clientData.savingsProductName, clientData.savingsAccountId, savingAccountOptions, clientData.clientType, clientData.clientClassification, clientData.clientTypeOptions, clientData.clientClassificationOptions, clientData.clientNonPersonConstitutionOptions, clientData.clientNonPersonMainBusinessLineOptions, clientData.clientNonPersonDetails, - clientData.clientLegalFormOptions, clientData.legalForm,clientData.address, clientData.isAddressEnabled, null); + clientData.clientLegalFormOptions, clientData.legalForm,clientData.address, clientData.isAddressEnabled, null, clientData.isStaff); } @@ -189,7 +191,7 @@ final public class ClientData implements Comparable { clientData.savingAccountOptions, clientData.clientType, clientData.clientClassification, clientData.clientTypeOptions, clientData.clientClassificationOptions, clientData.clientNonPersonConstitutionOptions, clientData.clientNonPersonMainBusinessLineOptions, clientData.clientNonPersonDetails, clientData.clientLegalFormOptions, clientData.legalForm,clientData.address, - clientData.isAddressEnabled, null); + clientData.isAddressEnabled, null, clientData.isStaff); } @@ -227,13 +229,14 @@ final public class ClientData implements Comparable { final EnumOptionData status = null; final CodeValueData subStatus = null; final EnumOptionData legalForm = null; + final Boolean isStaff = false; final ClientNonPersonData clientNonPerson = null; return new ClientData(accountNo, status, subStatus, officeId, officeName, transferToOfficeId, transferToOfficeName, id, firstname, middlename, lastname, fullname, displayName, externalId, mobileNo, dateOfBirth, gender, activationDate, imageId, staffId, staffName, allowedOffices, groups, staffOptions, closureReasons, genderOptions, timeline, savingProductOptions, savingsProductId, savingsProductName, savingsAccountId, savingAccountOptions, clientType, clientClassification, clientTypeOptions, clientClassificationOptions, clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions, - clientNonPerson, clientLegalFormOptions, legalForm,null,null, null); + clientNonPerson, clientLegalFormOptions, legalForm,null,null, null, isStaff); } public static ClientData lookup(final Long id, final String displayName, final Long officeId, final String officeName) { @@ -273,13 +276,14 @@ final public class ClientData implements Comparable { final Collection clientNonPersonMainBusinessLineOptions = null; final List clientLegalFormOptions = null; final EnumOptionData legalForm = null; + final Boolean isStaff = false; final ClientNonPersonData clientNonPerson = null; return new ClientData(accountNo, status, subStatus, officeId, officeName, transferToOfficeId, transferToOfficeName, id, firstname, middlename, lastname, fullname, displayName, externalId, mobileNo, dateOfBirth, gender, activationDate, imageId, staffId, staffName, allowedOffices, groups, staffOptions, closureReasons, genderOptions, timeline, savingProductOptions, savingsProductId, savingsProductName, savingsAccountId, savingAccountOptions, clientType, clientClassification, clientTypeOptions, clientClassificationOptions, clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions, - clientNonPerson, clientLegalFormOptions, legalForm,null,null, null); + clientNonPerson, clientLegalFormOptions, legalForm,null,null, null, isStaff); } @@ -289,7 +293,7 @@ final public class ClientData implements Comparable { final String externalId, final String mobileNo, final LocalDate dateOfBirth, final CodeValueData gender, final LocalDate activationDate, final Long imageId, final Long staffId, final String staffName, final ClientTimelineData timeline, final Long savingsProductId, final String savingsProductName, final Long savingsAccountId, - final CodeValueData clientType, final CodeValueData clientClassification, final EnumOptionData legalForm, final ClientNonPersonData clientNonPerson) { + final CodeValueData clientType, final CodeValueData clientClassification, final EnumOptionData legalForm, final ClientNonPersonData clientNonPerson, final Boolean isStaff) { final Collection allowedOffices = null; final Collection groups = null; @@ -307,7 +311,7 @@ final public class ClientData implements Comparable { staffName, allowedOffices, groups, staffOptions, closureReasons, genderOptions, timeline, savingProductOptions, savingsProductId, savingsProductName, savingsAccountId, null, clientType, clientClassification, clientTypeOptions, clientClassificationOptions, clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions, clientNonPerson, - clientLegalFormOptions, legalForm,null,null, null); + clientLegalFormOptions, legalForm,null,null, null, isStaff); } @@ -325,7 +329,7 @@ final public class ClientData implements Comparable { final Collection clientClassificationOptions, final Collection clientNonPersonConstitutionOptions, final Collection clientNonPersonMainBusinessLineOptions, final ClientNonPersonData clientNonPerson, final List clientLegalFormOptions, final EnumOptionData legalForm, final AddressData address, - final Boolean isAddressEnabled, final List datatables) { + final Boolean isAddressEnabled, final List datatables, final Boolean isStaff) { this.accountNo = accountNo; this.status = status; if (status != null) { @@ -383,6 +387,7 @@ final public class ClientData implements Comparable { this.savingsAccountId = savingsAccountId; this.savingAccountOptions = savingAccountOptions; this.legalForm = legalForm; + this.isStaff = isStaff; this.clientNonPersonDetails = clientNonPerson; this.address = address; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientDataValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientDataValidator.java index 4c2f538c8..585c22246 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientDataValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientDataValidator.java @@ -211,6 +211,11 @@ public final class ClientDataValidator { baseDataValidator.reset().parameter(ClientApiConstants.datatables).value(datatables).notNull().jsonArrayNotEmpty(); } + if (this.fromApiJsonHelper.parameterExists("isStaff", element)) { + final Boolean isStaffFlag = this.fromApiJsonHelper.extractBooleanNamed("isStaff", element); + baseDataValidator.reset().parameter("isStaff").value(isStaffFlag).notNull(); + } + List dataValidationErrorsForClientNonPerson = getDataValidationErrorsForCreateOnClientNonPerson(element.getAsJsonObject().get(ClientApiConstants.clientNonPersonDetailsParamName)); dataValidationErrors.addAll(dataValidationErrorsForClientNonPerson); @@ -478,6 +483,11 @@ public final class ClientDataValidator { baseDataValidator.reset().parameter(ClientApiConstants.legalFormIdParamName).value(legalFormId).ignoreIfNull().inMinMaxRange(1, 2); } + if (this.fromApiJsonHelper.parameterExists("isStaff", element)) { + final Boolean isStaffFlag = this.fromApiJsonHelper.extractBooleanNamed("isStaff", element); + baseDataValidator.reset().parameter("isStaff").value(isStaffFlag).notNull(); + } + Map parameterUpdateStatusDetails = getParameterUpdateStatusAndDataValidationErrorsForUpdateOnClientNonPerson(element.getAsJsonObject().get(ClientApiConstants.clientNonPersonDetailsParamName)); boolean atLeastOneParameterPassedForClientNonPersonUpdate = (boolean) parameterUpdateStatusDetails.get("parameterUpdateStatus"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java index 5e829707e..ce0e0f9fc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java @@ -115,6 +115,9 @@ public final class Client extends AbstractPersistableCustom { @Column(name = "mobile_no", length = 50, nullable = false, unique = true) private String mobileNo; + @Column(name = "is_staff", nullable = false) + private boolean isStaff; + @Column(name = "external_id", length = 100, nullable = true, unique = true) private String externalId; @@ -238,6 +241,8 @@ public final class Client extends AbstractPersistableCustom { 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); @@ -265,7 +270,7 @@ public final class Client extends AbstractPersistableCustom { final Long savingsAccountId = null; return new Client(currentUser, status, clientOffice, clientParentGroup, accountNo, firstname, middlename, lastname, fullname, activationDate, officeJoiningDate, externalId, mobileNo, staff, submittedOnDate, savingsProductId, savingsAccountId, dataOfBirth, - gender, clientType, clientClassification, legalForm); + gender, clientType, clientClassification, legalForm, isStaff); } protected Client() { @@ -276,7 +281,7 @@ public final class Client extends AbstractPersistableCustom { final String accountNo, final String firstname, final String middlename, final String lastname, final String fullname, final LocalDate activationDate, final LocalDate officeJoiningDate, final String externalId, final String mobileNo, final Staff staff, final LocalDate submittedOnDate, final Long savingsProductId, final Long savingsAccountId, - final LocalDate dateOfBirth, final CodeValue gender, final CodeValue clientType, final CodeValue clientClassification, final Integer legalForm) { + final LocalDate dateOfBirth, final CodeValue gender, final CodeValue clientType, final CodeValue clientClassification, final Integer legalForm, final Boolean isStaff) { if (StringUtils.isBlank(accountNo)) { this.accountNumber = new RandomPasswordGenerator(19).generate(); @@ -763,6 +768,18 @@ public final class Client extends AbstractPersistableCustom { this.mobileNo = mobileNo; } + public boolean isNotStaff() { + return !isStaff(); + } + + public boolean isStaff() { + return this.isStaff; + } + + public String getExternalId() { + return this.externalId; + } + public String getDisplayName() { return this.displayName; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java index cab88f716..c5217297c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java @@ -351,6 +351,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService sqlBuilder.append("c.firstname as firstname, c.middlename as middlename, c.lastname as lastname, "); sqlBuilder.append("c.fullname as fullname, c.display_name as displayName, "); sqlBuilder.append("c.mobile_no as mobileNo, "); + sqlBuilder.append("c.is_staff as isStaff, "); sqlBuilder.append("c.date_of_birth as dateOfBirth, "); sqlBuilder.append("c.gender_cv_id as genderId, "); sqlBuilder.append("cv.code_value as genderValue, "); @@ -439,6 +440,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService final String displayName = rs.getString("displayName"); final String externalId = rs.getString("externalId"); final String mobileNo = rs.getString("mobileNo"); + final boolean isStaff = rs.getBoolean("isStaff"); final LocalDate dateOfBirth = JdbcSupport.getLocalDate(rs, "dateOfBirth"); final Long genderId = JdbcSupport.getLong(rs, "genderId"); final String genderValue = rs.getString("genderValue"); @@ -500,7 +502,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService return ClientData.instance(accountNo, status, subStatus, officeId, officeName, transferToOfficeId, transferToOfficeName, id, firstname, middlename, lastname, fullname, displayName, externalId, mobileNo, dateOfBirth, gender, activationDate, imageId, staffId, staffName, timeline, savingsProductId, savingsProductName, savingsAccountId, clienttype, - classification, legalForm, clientNonPerson); + classification, legalForm, clientNonPerson, isStaff); } } @@ -533,6 +535,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService builder.append("c.firstname as firstname, c.middlename as middlename, c.lastname as lastname, "); builder.append("c.fullname as fullname, c.display_name as displayName, "); builder.append("c.mobile_no as mobileNo, "); + builder.append("c.is_staff as isStaff, "); builder.append("c.date_of_birth as dateOfBirth, "); builder.append("c.gender_cv_id as genderId, "); builder.append("cv.code_value as genderValue, "); @@ -620,6 +623,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService final String displayName = rs.getString("displayName"); final String externalId = rs.getString("externalId"); final String mobileNo = rs.getString("mobileNo"); + final boolean isStaff = rs.getBoolean("isStaff"); final LocalDate dateOfBirth = JdbcSupport.getLocalDate(rs, "dateOfBirth"); final Long genderId = JdbcSupport.getLong(rs, "genderId"); final String genderValue = rs.getString("genderValue"); @@ -680,7 +684,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService return ClientData.instance(accountNo, status, subStatus, officeId, officeName, transferToOfficeId, transferToOfficeName, id, firstname, middlename, lastname, fullname, displayName, externalId, mobileNo, dateOfBirth, gender, activationDate, imageId, staffId, staffName, timeline, savingsProductId, savingsProductName, savingsAccountId, clienttype, - classification, legalForm, clientNonPerson); + classification, legalForm, clientNonPerson, isStaff); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index 4941e3e6d..cd334fa40 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -229,6 +229,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP .retrieveGlobalConfiguration("Enable-Address"); final Boolean isAddressEnabled = configuration.isEnabled(); + + final Boolean isStaff = command.booleanObjectValueOfParameterNamed(ClientApiConstants.isStaffParamName); final Long officeId = command.longValueOfParameterNamed(ClientApiConstants.officeIdParamName); @@ -298,7 +300,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP final CommandWrapper commandWrapper = new CommandWrapperBuilder().activateClient(null).build(); rollbackTransaction = this.commandProcessingService.validateCommand(commandWrapper, currentUser); } - + this.clientRepository.save(newClient); if (newClient.isActive()) { this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.CLIENTS_ACTIVATE, @@ -334,7 +336,6 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP this.entityDatatableChecksWritePlatformService.runTheCheck(newClient.getId(), EntityTables.CLIENT.getName(), StatusEnum.CREATE.getCode().longValue(), EntityTables.CLIENT.getForeignKeyColumnNameOnDatatable()); - return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withOfficeId(clientOffice.getId()) // diff --git a/fineract-provider/src/main/resources/sql/migrations/core_db/V325__add_is_staff_client_data.sql b/fineract-provider/src/main/resources/sql/migrations/core_db/V325__add_is_staff_client_data.sql new file mode 100644 index 000000000..ef9854bcb --- /dev/null +++ b/fineract-provider/src/main/resources/sql/migrations/core_db/V325__add_is_staff_client_data.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- +ALTER TABLE `m_client` + ADD COLUMN `is_staff` TINYINT(1) NOT NULL DEFAULT '0' AFTER `mobile_no`;