Repository: incubator-fineract
Updated Branches:
  refs/heads/develop 5647ffb96 -> bfad90963


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java
----------------------------------------------------------------------
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 1cc3355..bec5369 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
@@ -27,6 +27,8 @@ import java.util.List;
 import org.apache.commons.lang.StringUtils;
 import org.apache.fineract.infrastructure.codes.data.CodeValueData;
 import 
org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
+import 
org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationPropertyData;
+import 
org.apache.fineract.infrastructure.configuration.service.ConfigurationReadPlatformService;
 import org.apache.fineract.infrastructure.core.api.ApiParameterHelper;
 import org.apache.fineract.infrastructure.core.data.EnumOptionData;
 import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
@@ -39,6 +41,8 @@ import 
org.apache.fineract.organisation.office.data.OfficeData;
 import 
org.apache.fineract.organisation.office.service.OfficeReadPlatformService;
 import org.apache.fineract.organisation.staff.data.StaffData;
 import org.apache.fineract.organisation.staff.service.StaffReadPlatformService;
+import org.apache.fineract.portfolio.address.data.AddressData;
+import 
org.apache.fineract.portfolio.address.service.AddressReadPlatformService;
 import org.apache.fineract.portfolio.client.api.ClientApiConstants;
 import org.apache.fineract.portfolio.client.data.ClientData;
 import org.apache.fineract.portfolio.client.data.ClientNonPersonData;
@@ -74,18 +78,25 @@ public class ClientReadPlatformServiceImpl implements 
ClientReadPlatformService
     private final ClientLookupMapper lookupMapper = new ClientLookupMapper();
     private final ClientMembersOfGroupMapper membersOfGroupMapper = new 
ClientMembersOfGroupMapper();
     private final ParentGroupsMapper clientGroupsMapper = new 
ParentGroupsMapper();
+    
+    private final AddressReadPlatformService addressReadPlatformService;
+    private final ConfigurationReadPlatformService 
configurationReadPlatformService;
 
     @Autowired
     public ClientReadPlatformServiceImpl(final PlatformSecurityContext 
context, final RoutingDataSource dataSource,
             final OfficeReadPlatformService officeReadPlatformService, final 
StaffReadPlatformService staffReadPlatformService,
             final CodeValueReadPlatformService codeValueReadPlatformService,
-            final SavingsProductReadPlatformService 
savingsProductReadPlatformService) {
+            final SavingsProductReadPlatformService 
savingsProductReadPlatformService,
+            final AddressReadPlatformService addressReadPlatformService,
+            final ConfigurationReadPlatformService 
configurationReadPlatformService) {
         this.context = context;
         this.officeReadPlatformService = officeReadPlatformService;
         this.jdbcTemplate = new JdbcTemplate(dataSource);
         this.staffReadPlatformService = staffReadPlatformService;
         this.codeValueReadPlatformService = codeValueReadPlatformService;
         this.savingsProductReadPlatformService = 
savingsProductReadPlatformService;
+        this.addressReadPlatformService=addressReadPlatformService;
+        this.configurationReadPlatformService=configurationReadPlatformService;
     }
 
     @Override
@@ -93,10 +104,21 @@ public class ClientReadPlatformServiceImpl implements 
ClientReadPlatformService
         this.context.authenticatedUser();
 
         final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId);
+        AddressData address=null;
 
         final Collection<OfficeData> offices = 
this.officeReadPlatformService.retrieveAllOfficesForDropdown();
 
         final Collection<SavingsProductData> savingsProductDatas = 
this.savingsProductReadPlatformService.retrieveAllForLookupByType(null);
+        
+        final GlobalConfigurationPropertyData 
configuration=this.configurationReadPlatformService.retrieveGlobalConfiguration("Enable-Address");
+        
+        final Boolean isAddressEnabled=configuration.isEnabled(); 
+        if(isAddressEnabled)
+        {
+                address = this.addressReadPlatformService.retrieveTemplate();
+        }
+        
+       
 
         Collection<StaffData> staffOptions = null;
 
@@ -129,7 +151,7 @@ public class ClientReadPlatformServiceImpl implements 
ClientReadPlatformService
 
         return ClientData.template(defaultOfficeId, new LocalDate(), offices, 
staffOptions, null, genderOptions, savingsProductDatas,
                 clientTypeOptions, clientClassificationOptions, 
clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions,
-                clientLegalFormOptions);
+                clientLegalFormOptions,address,isAddressEnabled);
     }
 
     @Override
@@ -760,7 +782,7 @@ public class ClientReadPlatformServiceImpl implements 
ClientReadPlatformService
         final Collection<CodeValueData> clientNonPersonMainBusinessLineOptions 
= null;
         final List<EnumOptionData> clientLegalFormOptions = null;
         return ClientData.template(null, null, null, null, narrations, null, 
null, clientTypeOptions, clientClassificationOptions, 
-                       clientNonPersonConstitutionOptions, 
clientNonPersonMainBusinessLineOptions, clientLegalFormOptions);
+                       clientNonPersonConstitutionOptions, 
clientNonPersonMainBusinessLineOptions, clientLegalFormOptions,null,null);
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
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 26a1d42..038c46d 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
@@ -32,7 +32,9 @@ import 
org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumb
 import 
org.apache.fineract.infrastructure.accountnumberformat.domain.EntityAccountType;
 import org.apache.fineract.infrastructure.codes.domain.CodeValue;
 import 
org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationPropertyData;
 import 
org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
+import 
org.apache.fineract.infrastructure.configuration.service.ConfigurationReadPlatformService;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import 
org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
@@ -44,6 +46,7 @@ import 
org.apache.fineract.organisation.office.domain.OfficeRepository;
 import 
org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
 import org.apache.fineract.organisation.staff.domain.Staff;
 import org.apache.fineract.organisation.staff.domain.StaffRepositoryWrapper;
+import 
org.apache.fineract.portfolio.address.service.AddressWritePlatformService;
 import org.apache.fineract.portfolio.client.api.ClientApiConstants;
 import org.apache.fineract.portfolio.client.data.ClientDataValidator;
 import org.apache.fineract.portfolio.client.domain.AccountNumberGenerator;
@@ -110,6 +113,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl 
implements ClientWriteP
     private final ConfigurationDomainService configurationDomainService;
     private final AccountNumberFormatRepositoryWrapper 
accountNumberFormatRepository;
        private final FromJsonHelper fromApiJsonHelper;
+       private final ConfigurationReadPlatformService 
configurationReadPlatformService;
+       private final AddressWritePlatformService addressWritePlatformService;
 
     @Autowired
     public ClientWritePlatformServiceJpaRepositoryImpl(final 
PlatformSecurityContext context,
@@ -120,7 +125,9 @@ public class ClientWritePlatformServiceJpaRepositoryImpl 
implements ClientWriteP
             final SavingsAccountRepository savingsRepository, final 
SavingsProductRepository savingsProductRepository,
             final SavingsApplicationProcessWritePlatformService 
savingsApplicationProcessWritePlatformService,
             final CommandProcessingService commandProcessingService, final 
ConfigurationDomainService configurationDomainService,
-            final AccountNumberFormatRepositoryWrapper 
accountNumberFormatRepository, final FromJsonHelper fromApiJsonHelper) {
+            final AccountNumberFormatRepositoryWrapper 
accountNumberFormatRepository, final FromJsonHelper fromApiJsonHelper,
+            final ConfigurationReadPlatformService 
configurationReadPlatformService,
+                       final AddressWritePlatformService 
addressWritePlatformService) {
         this.context = context;
         this.clientRepository = clientRepository;
         this.clientNonPersonRepository = clientNonPersonRepository;
@@ -139,6 +146,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl 
implements ClientWriteP
         this.configurationDomainService = configurationDomainService;
         this.accountNumberFormatRepository = accountNumberFormatRepository;
         this.fromApiJsonHelper = fromApiJsonHelper;
+       this.configurationReadPlatformService = 
configurationReadPlatformService;
+               this.addressWritePlatformService = addressWritePlatformService;
     }
 
     @Transactional
@@ -200,6 +209,11 @@ public class ClientWritePlatformServiceJpaRepositoryImpl 
implements ClientWriteP
             final AppUser currentUser = this.context.authenticatedUser();
 
             this.fromApiJsonDeserializer.validateForCreate(command.json());
+            
+                       final GlobalConfigurationPropertyData configuration = 
this.configurationReadPlatformService
+                                       
.retrieveGlobalConfiguration("Enable-Address");
+
+                       final Boolean isAddressEnabled = 
configuration.isEnabled();
 
             final Long officeId = 
command.longValueOfParameterNamed(ClientApiConstants.officeIdParamName);
 
@@ -283,10 +297,20 @@ public class ClientWritePlatformServiceJpaRepositoryImpl 
implements ClientWriteP
             CommandProcessingResult result = openSavingsAccount(newClient, 
fmt);
             if (result.getSavingsId() != null) {
                 this.clientRepository.save(newClient);
+                
             }
             
             if(isEntity)            
                extractAndCreateClientNonPerson(newClient, command);
+               
+                       final long clientId = newClient.getId();
+
+                       if (isAddressEnabled) {
+
+                               
this.addressWritePlatformService.addNewClientAddress(newClient, command);
+
+                       }
+
 
             return new CommandProcessingResultBuilder() //
                     .withCommandId(command.commandId()) //
@@ -820,4 +844,4 @@ public class ClientWritePlatformServiceJpaRepositoryImpl 
implements ClientWriteP
                 .withEntityId(entityId) //
                 .build();
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/resources/sql/migrations/core_db/V312__address_module_tables_metadat.sql
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/resources/sql/migrations/core_db/V312__address_module_tables_metadat.sql
 
b/fineract-provider/src/main/resources/sql/migrations/core_db/V312__address_module_tables_metadat.sql
new file mode 100644
index 0000000..3e85e93
--- /dev/null
+++ 
b/fineract-provider/src/main/resources/sql/migrations/core_db/V312__address_module_tables_metadat.sql
@@ -0,0 +1,122 @@
+--
+-- 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.
+
+
+
+-- code inserts
+INSERT INTO `m_code` (`code_name`, `is_system_defined`) VALUES ('STATE',1);
+INSERT INTO `m_code` (`code_name`, `is_system_defined`) VALUES ('COUNTRY',1);
+INSERT INTO `m_code` (`code_name`, `is_system_defined`) VALUES 
('ADDRESS_TYPE',1);
+
+
+-- configuration
+INSERT INTO `c_configuration` (`name`, `value`, `date_value`, `enabled`, 
`is_trap_door`, `description`) VALUES ('Enable-Address', NULL, NULL, 1, 0, 
NULL);
+
+-- add address table
+CREATE TABLE `m_address` (
+       `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
+       `street` VARCHAR(100) NULL DEFAULT NULL,
+       `address_line_1` VARCHAR(100) NULL DEFAULT NULL,
+       `address_line_2` VARCHAR(100) NULL DEFAULT NULL,
+       `address_line_3` VARCHAR(100) NULL DEFAULT NULL,
+       `town_village` VARCHAR(100) NULL DEFAULT NULL,
+       `city` VARCHAR(100) NULL DEFAULT NULL,
+       `county_district` VARCHAR(100) NULL DEFAULT NULL,
+       `state_province_id` INT(11) NULL DEFAULT NULL,
+       `country_id` INT(11) NULL DEFAULT NULL,
+       `postal_code` VARCHAR(10) NULL DEFAULT NULL,
+       `latitude` DECIMAL(10,8) UNSIGNED NULL DEFAULT '0.00000000',
+       `longitude` DECIMAL(10,8) UNSIGNED NULL DEFAULT '0.00000000',
+       `created_by` VARCHAR(100) NULL DEFAULT NULL,
+       `created_on` DATE NULL DEFAULT NULL,
+       `updated_by` VARCHAR(100) NULL DEFAULT NULL,
+       `updated_on` DATE NULL DEFAULT NULL,
+       PRIMARY KEY (`id`),
+       INDEX `address_fields_codefk1` (`state_province_id`),
+       INDEX `address_fields_codefk2` (`country_id`),
+       CONSTRAINT `address_fields_codefk1` FOREIGN KEY (`state_province_id`) 
REFERENCES `m_code_value` (`id`),
+       CONSTRAINT `address_fields_codefk2` FOREIGN KEY (`country_id`) 
REFERENCES `m_code_value` (`id`)
+)
+ENGINE=InnoDB
+AUTO_INCREMENT=1
+;
+
+
+-- entity address table
+CREATE TABLE `m_client_address` (
+       `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
+       `client_id` BIGINT(20) NOT NULL DEFAULT '0',
+       `address_id` BIGINT(20) NOT NULL DEFAULT '0',
+       `address_type_id` INT(11) NOT NULL DEFAULT '0',
+       `is_active` TINYINT(4) NOT NULL DEFAULT '0',
+       PRIMARY KEY (`id`),
+       INDEX `addressIdFk` (`address_id`),
+       INDEX `address_codefk` (`address_type_id`),
+       INDEX `clientaddressfk` (`client_id`),
+       CONSTRAINT `address_codefk` FOREIGN KEY (`address_type_id`) REFERENCES 
`m_code_value` (`id`),
+       CONSTRAINT `clientaddressfk` FOREIGN KEY (`client_id`) REFERENCES 
`m_client` (`id`)
+)
+ENGINE=InnoDB
+AUTO_INCREMENT=1
+;
+
+
+-- field configuration
+CREATE TABLE `m_field_configuration` (
+       `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
+       `entity` VARCHAR(100) NOT NULL,
+       `subentity` VARCHAR(100) NOT NULL,
+       `field` VARCHAR(100) NOT NULL,
+       `is_enabled` TINYINT(4) NOT NULL,
+       `is_mandatory` TINYINT(4) NOT NULL,
+       `validation_regex` VARCHAR(50) NULL DEFAULT NULL,
+       PRIMARY KEY (`id`)
+)
+ENGINE=InnoDB
+AUTO_INCREMENT=1
+;
+
+
+INSERT INTO `m_field_configuration` ( `entity`, `subentity`, `field`, 
`is_enabled`, `is_mandatory`, `validation_regex`) VALUES
+       ('ADDRESS', 'CLIENT', 'addressType', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'street', 1, 1, ''),
+       ('ADDRESS', 'CLIENT', 'addressLine1', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'addressLine2', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'addressLine3', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'townVillage', 0, 0, ''),
+       ('ADDRESS', 'CLIENT', 'city', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'countyDistrict', 0, 0, ''),
+       ('ADDRESS', 'CLIENT', 'stateProvinceId', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'countryId', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'postalCode', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'latitude', 0, 0, ''),
+       ('ADDRESS', 'CLIENT', 'longitude', 0, 0, ''),
+       ('ADDRESS', 'CLIENT', 'createdBy', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'createdOn', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'updatedBy', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'updatedOn', 1, 0, ''),
+       ('ADDRESS', 'CLIENT', 'isActive', 1, 0, '');
+
+-- inserts for permission
+INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, 
`can_maker_checker`) VALUES ('portfolio', 'CREATE_ADDRESS', 'ADDRESS', 
'CREATE', 0);
+INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, 
`can_maker_checker`) VALUES ('portfolio', 'CREATE_ADDRESS_CHECKER', 'ADDRESS', 
'CREATE_CHECKER', 1);
+INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, 
`can_maker_checker`) VALUES ('portfolio', 'UPDATE_ADDRESS', 'ADDRESS', 
'UPDATE', 0);
+INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, 
`can_maker_checker`) VALUES ('portfolio', 'UPDATE_ADDRESS_CHECKER', 'ADDRESS', 
'UPDATE_CHECKER', 1);
+INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, 
`can_maker_checker`) VALUES ('portfolio', 'READ_ADDRESS', 'ADDRESS', 'READ', 0);
+INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, 
`can_maker_checker`) VALUES ('portfolio', 'DELETE_ADDRESS', 'ADDRESS', 
'DELETE', 0);
+INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, 
`can_maker_checker`) VALUES ('portfolio', 'DELETE_ADDRESS_CHECKER', 'ADDRESS', 
'DELETE_CHECKER', 1);

Reply via email to