Merge DIT branch

This commit is contained in:
Avik Ganguly
2017-12-13 14:31:55 +05:30
182 changed files with 19656 additions and 257 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ dependencies {
[group: 'net.sf.ehcache', name: 'ehcache', version: '2.7.2'],
[group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.12'],
[group: 'com.jayway.jsonpath', name: 'json-path', version: '0.9.1'],
[group: 'org.apache.tika', name: 'tika-core', version :'1.9'],
// Although fineract (at the time of writing) doesn't have any compile time dep. on this,
// it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility
[group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'],
+1 -1
View File
@@ -84,7 +84,7 @@ dependencies {
[group: 'net.sf.ehcache', name: 'ehcache', version: '2.7.2'],
[group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.12'],
[group: 'com.jayway.jsonpath', name: 'json-path', version: '0.9.1'],
[group: 'org.apache.tika', name: 'tika-core', version :'1.9'],
// Although fineract (at the time of writing) doesn't have any compile time dep. on this,
// it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility
[group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'],
@@ -0,0 +1,147 @@
/**
* 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.integrationtests.bulkimport.importhandler.client;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.apache.fineract.integrationtests.common.system.CodeHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ClientEntityImportHandlerTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testClientImport() throws InterruptedException, IOException, ParseException {
//in order to populate helper sheets
StaffHelper staffHelper=new StaffHelper();
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec);
Assert.assertNotNull("Could not create staff",outcome_staff_creation);
//in order to populate helper sheets
OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec);
Integer outcome_office_creation=officeHelper.createOffice("02 May 2000");
Assert.assertNotNull("Could not create office" ,outcome_office_creation);
//in order to populate helper columns in client entity sheet
CodeHelper codeHelper=new CodeHelper();
//create constitution
codeHelper.retrieveOrCreateCodeValue(24,requestSpec,responseSpec);
//create client classification
codeHelper.retrieveOrCreateCodeValue(17,requestSpec,responseSpec);
//create client types
codeHelper.retrieveOrCreateCodeValue(16,requestSpec,responseSpec);
//create Address types
codeHelper.retrieveOrCreateCodeValue(29,requestSpec,responseSpec);
//create State
codeHelper.retrieveOrCreateCodeValue(27,requestSpec,responseSpec);
//create Country
codeHelper.retrieveOrCreateCodeValue(28,requestSpec,responseSpec);
//create Main business line
codeHelper.retrieveOrCreateCodeValue(25,requestSpec,responseSpec);
ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec);
Workbook workbook=clientHelper.getClientEntityWorkbook(GlobalEntityType.CLIENTS_ENTTTY,"dd MMMM yyyy");
//insert dummy data into client entity sheet
Sheet clientEntitySheet = workbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME);
Row firstClientRow=clientEntitySheet.getRow(1);
firstClientRow.createCell(ClientEntityConstants.NAME_COL).setCellValue(Utils.randomNameGenerator("C_E_",6));
Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
firstClientRow.createCell(ClientEntityConstants.OFFICE_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(0).getStringCellValue());
firstClientRow.createCell(ClientEntityConstants.STAFF_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue());
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy");
Date incoporationDate=simpleDateFormat.parse("14 May 2001");
firstClientRow.createCell(ClientEntityConstants.INCOPORATION_DATE_COL).setCellValue(incoporationDate);
Date validTill=simpleDateFormat.parse("14 May 2019");
firstClientRow.createCell(ClientEntityConstants.INCOPORATION_VALID_TILL_COL).setCellValue(validTill);
firstClientRow.createCell(ClientEntityConstants.MOBILE_NO_COL).setCellValue(Utils.randomNumberGenerator(7));
firstClientRow.createCell(ClientEntityConstants.CLIENT_TYPE_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CLIENT_TYPES).getStringCellValue());
firstClientRow.createCell(ClientEntityConstants.CLIENT_CLASSIFICATION_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION).getStringCellValue());
firstClientRow.createCell(ClientEntityConstants.INCOPORATION_NUMBER_COL).setCellValue(Utils.randomNumberGenerator(6));
firstClientRow.createCell(ClientEntityConstants.MAIN_BUSINESS_LINE).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE).getStringCellValue());
firstClientRow.createCell(ClientEntityConstants.CONSTITUTION_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CONSTITUTION_COL).getStringCellValue());
firstClientRow.createCell(ClientEntityConstants.ACTIVE_COL).setCellValue("False");
Date submittedDate=simpleDateFormat.parse("28 September 2017");
firstClientRow.createCell(ClientEntityConstants.SUBMITTED_ON_COL).setCellValue(submittedDate);
firstClientRow.createCell(ClientEntityConstants.ADDRESS_ENABLED).setCellValue("False");
String currentdirectory = new File("").getAbsolutePath();
File directory=new File(currentdirectory+"\\src\\integrationTest\\" +
"resources\\bulkimport\\importhandler\\client");
if (!directory.exists())
directory.mkdirs();
File file= new File(directory+"\\ClientEntity.xls");
OutputStream outputStream=new FileOutputStream(file);
workbook.write(outputStream);
outputStream.close();
String importDocumentId=clientHelper.importClientEntityTemplate(file);
file.delete();
Assert.assertNotNull(importDocumentId);
//Wait for the creation of output excel
Thread.sleep(3000);
//check status column of output excel
String location=clientHelper.getOutputTemplateLocation(importDocumentId);
FileInputStream fileInputStream = new FileInputStream(location);
Workbook outputWorkbook=new HSSFWorkbook(fileInputStream);
Sheet outputClientEntitySheet = outputWorkbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME);
Row row= outputClientEntitySheet.getRow(1);
Assert.assertEquals("Imported",row.getCell(ClientEntityConstants.STATUS_COL).getStringCellValue());
}
}
@@ -0,0 +1,177 @@
/**
* 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.integrationtests.bulkimport.importhandler.loan;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.integrationtests.common.*;
import org.apache.fineract.integrationtests.common.funds.FundsResourceHandler;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class LoanImportHandlerTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testLoanImport() throws InterruptedException, IOException, ParseException {
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
//in order to populate helper sheets
OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec);
Integer outcome_office_creation=officeHelper.createOffice("02 May 2000");
Assert.assertNotNull("Could not create office" ,outcome_office_creation);
//in order to populate helper sheets
ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec);
Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec);
Assert.assertNotNull("Could not create client" ,outcome_client_creation);
//in order to populate helper sheets
GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec);
Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true);
Assert.assertNotNull("Could not create group" ,outcome_group_creation);
//in order to populate helper sheets
StaffHelper staffHelper=new StaffHelper();
Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec);
Assert.assertNotNull("Could not create staff",outcome_staff_creation);
LoanTransactionHelper loanTransactionHelper=new LoanTransactionHelper(requestSpec,responseSpec);
LoanProductTestBuilder loanProductTestBuilder=new LoanProductTestBuilder();
String jsonLoanProduct=loanProductTestBuilder.build(null);
Integer outcome_lp_creaion=loanTransactionHelper.getLoanProductId(jsonLoanProduct);
Assert.assertNotNull("Could not create Loan Product" ,outcome_lp_creaion);
FundsResourceHandler fundsResourceHandler=new FundsResourceHandler();
String jsonFund="{\n" +
"\t\"name\": \""+Utils.randomNameGenerator("Fund_Name",9)+"\"\n" +
"}";
Integer outcome_fund_creation=fundsResourceHandler.createFund(jsonFund,requestSpec,responseSpec);
Assert.assertNotNull("Could not create Fund" ,outcome_fund_creation);
PaymentTypeHelper paymentTypeHelper=new PaymentTypeHelper();
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
Boolean isCashPayment = true;
Integer position = 1;
Integer outcome_payment_creation= paymentTypeHelper.createPaymentType(requestSpec, responseSpec,name,description,isCashPayment,position);
Assert.assertNotNull("Could not create payment type" ,outcome_payment_creation);
Workbook workbook=loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy");
//insert dummy data into loan Sheet
Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
Row firstLoanRow=loanSheet.getRow(1);
Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
firstLoanRow.createCell(LoanConstants.OFFICE_NAME_COL).setCellValue(officeSheet.getRow(1).getCell(1).getStringCellValue());
firstLoanRow.createCell(LoanConstants.LOAN_TYPE_COL).setCellValue("Individual");
firstLoanRow.createCell(LoanConstants.CLIENT_NAME_COL).setCellValue(loanSheet.getRow(1).getCell(LoanConstants.LOOKUP_CLIENT_NAME_COL).getStringCellValue());
firstLoanRow.createCell(LoanConstants.CLIENT_EXTERNAL_ID).setCellValue(loanSheet.getRow(1).getCell(LoanConstants.LOOKUP_CLIENT_EXTERNAL_ID).getStringCellValue());
Sheet loanProductSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
firstLoanRow.createCell(LoanConstants.PRODUCT_COL).setCellValue(loanProductSheet.getRow(1).getCell(1).getStringCellValue());
Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
firstLoanRow.createCell(LoanConstants.LOAN_OFFICER_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue());
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy");
Date date=simpleDateFormat.parse("13 May 2017");
firstLoanRow.createCell(LoanConstants.SUBMITTED_ON_DATE_COL).setCellValue(date);
firstLoanRow.createCell(LoanConstants.APPROVED_DATE_COL).setCellValue(date);
firstLoanRow.createCell(LoanConstants.DISBURSED_DATE_COL).setCellValue(date);
Sheet extrasSheet=workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME);
firstLoanRow.createCell(LoanConstants.DISBURSED_PAYMENT_TYPE_COL).setCellValue(extrasSheet.getRow(1).getCell(3).getStringCellValue());
firstLoanRow.createCell(LoanConstants.FUND_NAME_COL).setCellValue(extrasSheet.getRow(1).getCell(1).getStringCellValue());
firstLoanRow.createCell(LoanConstants.PRINCIPAL_COL).setCellValue(loanProductSheet.getRow(1).getCell(3).getNumericCellValue());
firstLoanRow.createCell(LoanConstants.NO_OF_REPAYMENTS_COL).setCellValue(loanProductSheet.getRow(1).getCell(6).getNumericCellValue());
firstLoanRow.createCell(LoanConstants.REPAID_EVERY_COL).setCellValue(loanProductSheet.getRow(1).getCell(9).getNumericCellValue());
firstLoanRow.createCell(LoanConstants.REPAID_EVERY_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(10).getStringCellValue());
firstLoanRow.createCell(LoanConstants.LOAN_TERM_COL).setCellValue(loanProductSheet.getRow(1).getCell(8).getNumericCellValue());
firstLoanRow.createCell(LoanConstants.LOAN_TERM_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(10).getStringCellValue());
firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_COL).setCellValue(loanProductSheet.getRow(1).getCell(11).getNumericCellValue());
firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(14).getStringCellValue());
firstLoanRow.createCell(LoanConstants.AMORTIZATION_COL).setCellValue(loanProductSheet.getRow(1).getCell(15).getStringCellValue());
firstLoanRow.createCell(LoanConstants.INTEREST_METHOD_COL).setCellValue(loanProductSheet.getRow(1).getCell(16).getStringCellValue());
firstLoanRow.createCell(LoanConstants.INTEREST_CALCULATION_PERIOD_COL).setCellValue(loanProductSheet.getRow(1).getCell(17).getStringCellValue());
firstLoanRow.createCell(LoanConstants.ARREARS_TOLERANCE_COL).setCellValue(0);
firstLoanRow.createCell(LoanConstants.REPAYMENT_STRATEGY_COL).setCellValue(loanProductSheet.getRow(1).getCell(19).getStringCellValue());
firstLoanRow.createCell(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL).setCellValue(0);
firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL).setCellValue(0);
firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL).setCellValue(0);
firstLoanRow.createCell(LoanConstants.FIRST_REPAYMENT_COL).setCellValue(date);
firstLoanRow.createCell(LoanConstants.TOTAL_AMOUNT_REPAID_COL).setCellValue(6000);
firstLoanRow.createCell(LoanConstants.LAST_REPAYMENT_DATE_COL).setCellValue(date);
firstLoanRow.createCell(LoanConstants.REPAYMENT_TYPE_COL).setCellValue(extrasSheet.getRow(1).getCell(3).getStringCellValue());
String currentdirectory = new File("").getAbsolutePath();
File directory=new File(currentdirectory+"\\src\\integrationTest\\" +
"resources\\bulkimport\\importhandler\\loan");
if (!directory.exists())
directory.mkdirs();
File file= new File(directory+"\\Loan.xls");
OutputStream outputStream=new FileOutputStream(file);
workbook.write(outputStream);
outputStream.close();
String importDocumentId=loanTransactionHelper.importLoanTemplate(file);
file.delete();
Assert.assertNotNull(importDocumentId);
//Wait for the creation of output excel
Thread.sleep(3000);
//check status column of output excel
String location=loanTransactionHelper.getOutputTemplateLocation(importDocumentId);
FileInputStream fileInputStream = new FileInputStream(location);
Workbook Outputworkbook=new HSSFWorkbook(fileInputStream);
Sheet outputLoanSheet = Outputworkbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
Row row= outputLoanSheet.getRow(1);
Assert.assertEquals("Imported",row.getCell(LoanConstants.STATUS_COL).getStringCellValue());
}
}
@@ -0,0 +1,102 @@
/**
* 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.integrationtests.bulkimport.importhandler.office;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.organisation.office.domain.Office;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.*;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class OfficeImportHandlerTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup(){
Utils.initializeRESTAssured();
this.requestSpec=new RequestSpecBuilder().build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testOfficeImport() throws IOException, InterruptedException, NoSuchFieldException, ParseException {
OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec);
Workbook workbook=officeHelper.getOfficeWorkBook("dd MMMM yyyy");
//insert dummy data into excel
Sheet sheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
Row firstOfficeRow= sheet.getRow(1);
firstOfficeRow.createCell(OfficeConstants.OFFICE_NAME_COL).setCellValue(Utils.randomNameGenerator("Test_Off_",6));
firstOfficeRow.createCell(OfficeConstants.PARENT_OFFICE_NAME_COL).setCellValue(firstOfficeRow.getCell(OfficeConstants.LOOKUP_OFFICE_COL).getStringCellValue());
firstOfficeRow.createCell(OfficeConstants.PARENT_OFFICE_ID_COL).setCellValue(firstOfficeRow.getCell(OfficeConstants.LOOKUP_OFFICE_ID_COL).getNumericCellValue());
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy");
Date date=simpleDateFormat.parse("14 May 2001");
firstOfficeRow.createCell(OfficeConstants.OPENED_ON_COL).setCellValue(date);
String currentdirectory = new File("").getAbsolutePath();
File directory=new File(currentdirectory+"\\src\\integrationTest\\" +
"resources\\bulkimport\\importhandler\\office");
if (!directory.exists())
directory.mkdirs();
File file= new File(directory+"\\Office.xls");
OutputStream outputStream=new FileOutputStream(file);
workbook.write(outputStream);
outputStream.close();
String importDocumentId=officeHelper.importOfficeTemplate(file);
file.delete();
Assert.assertNotNull(importDocumentId);
// Wait for the creation of output excel
Thread.sleep(3000);
//check status column of output excel
String location=officeHelper.getOutputTemplateLocation(importDocumentId);
FileInputStream fileInputStream = new FileInputStream(location);
Workbook outputWorkbook=new HSSFWorkbook(fileInputStream);
Sheet officeSheet = outputWorkbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
Row row= officeSheet.getRow(1);
Assert.assertEquals("Imported",row.getCell(OfficeConstants.STATUS_COL).getStringCellValue());
}
}
@@ -0,0 +1,156 @@
/**
* 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.integrationtests.bulkimport.importhandler.savings;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.SavingsConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.GroupHelper;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
import org.apache.fineract.template.domain.Template;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SavingsImportHandlerTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testSavingsImport() throws InterruptedException, IOException, ParseException {
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
//in order to populate helper sheets
OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec);
Integer outcome_office_creation=officeHelper.createOffice("02 May 2000");
Assert.assertNotNull("Could not create office" ,outcome_office_creation);
//in order to populate helper sheets
ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec);
Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec);
Assert.assertNotNull("Could not create client" ,outcome_client_creation);
//in order to populate helper sheets
GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec);
Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true);
Assert.assertNotNull("Could not create group" ,outcome_group_creation);
//in order to populate helper sheets
StaffHelper staffHelper=new StaffHelper();
Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec);
Assert.assertNotNull("Could not create staff",outcome_staff_creation);
SavingsProductHelper savingsProductHelper=new SavingsProductHelper();
String jsonSavingsProduct=savingsProductHelper.build();
Integer outcome_sp_creaction=savingsProductHelper.createSavingsProduct(jsonSavingsProduct,requestSpec,responseSpec);
Assert.assertNotNull("Could not create Savings product",outcome_sp_creaction);
SavingsAccountHelper savingsAccountHelper=new SavingsAccountHelper(requestSpec,responseSpec);
Workbook workbook=savingsAccountHelper.getSavingsWorkbook("dd MMMM yyyy");
//insert dummy data into Savings sheet
Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME);
Row firstSavingsRow=savingsSheet.getRow(1);
Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
firstSavingsRow.createCell(SavingsConstants.OFFICE_NAME_COL).setCellValue(officeSheet.getRow(1).getCell(1).getStringCellValue());
firstSavingsRow.createCell(SavingsConstants.SAVINGS_TYPE_COL).setCellValue("Individual");
firstSavingsRow.createCell(SavingsConstants.CLIENT_NAME_COL).setCellValue(savingsSheet.getRow(1).getCell(SavingsConstants.LOOKUP_CLIENT_NAME_COL).getStringCellValue());
Sheet savingsProductSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
firstSavingsRow.createCell(SavingsConstants.PRODUCT_COL).setCellValue(savingsProductSheet.getRow(1).getCell(1).getStringCellValue());
Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
firstSavingsRow.createCell(SavingsConstants.FIELD_OFFICER_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue());
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy");
Date date=simpleDateFormat.parse("13 May 2017");
firstSavingsRow.createCell(SavingsConstants.SUBMITTED_ON_DATE_COL).setCellValue(date);
firstSavingsRow.createCell(SavingsConstants.APPROVED_DATE_COL).setCellValue(date);
firstSavingsRow.createCell(SavingsConstants.ACTIVATION_DATE_COL).setCellValue(date);
firstSavingsRow.createCell(SavingsConstants.CURRENCY_COL).setCellValue(savingsProductSheet.getRow(1).getCell(10).getStringCellValue());
firstSavingsRow.createCell(SavingsConstants.DECIMAL_PLACES_COL).setCellValue(savingsProductSheet.getRow(1).getCell(11).getNumericCellValue());
firstSavingsRow.createCell(SavingsConstants.IN_MULTIPLES_OF_COL).setCellValue(savingsProductSheet.getRow(1).getCell(12).getNumericCellValue());
firstSavingsRow.createCell(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL).setCellValue(savingsProductSheet.getRow(1).getCell(2).getNumericCellValue());
firstSavingsRow.createCell(SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(3).getStringCellValue());
firstSavingsRow.createCell(SavingsConstants.INTEREST_POSTING_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(4).getStringCellValue());
firstSavingsRow.createCell(SavingsConstants.INTEREST_CALCULATION_COL).setCellValue(savingsProductSheet.getRow(1).getCell(5).getStringCellValue());
firstSavingsRow.createCell(SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL).setCellValue(savingsProductSheet.getRow(1).getCell(6).getStringCellValue());
firstSavingsRow.createCell(SavingsConstants.MIN_OPENING_BALANCE_COL).setCellValue(savingsProductSheet.getRow(1).getCell(7).getNumericCellValue());
firstSavingsRow.createCell(SavingsConstants.LOCKIN_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(8).getNumericCellValue());
firstSavingsRow.createCell(SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL).setCellValue(savingsProductSheet.getRow(1).getCell(9).getStringCellValue());
firstSavingsRow.createCell(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS).setCellValue("False");
firstSavingsRow.createCell(SavingsConstants.ALLOW_OVER_DRAFT_COL).setCellValue("False");
firstSavingsRow.createCell(SavingsConstants.OVER_DRAFT_LIMIT_COL).setCellValue(savingsProductSheet.getRow(1).getCell(15).getNumericCellValue());
String currentdirectory = new File("").getAbsolutePath();
File directory=new File(currentdirectory+"\\src\\integrationTest\\" +
"resources\\bulkimport\\importhandler\\savings");
if (!directory.exists())
directory.mkdirs();
File file= new File(directory+"\\Savings.xls");
OutputStream outputStream=new FileOutputStream(file);
workbook.write(outputStream);
outputStream.close();
String importDocumentId=savingsAccountHelper.importSavingsTemplate(file);
file.delete();
Assert.assertNotNull(importDocumentId);
//Wait for the creation of output excel
Thread.sleep(3000);
//check status column of output excel
String location=savingsAccountHelper.getOutputTemplateLocation(importDocumentId);
FileInputStream fileInputStream = new FileInputStream(location);
Workbook Outputworkbook=new HSSFWorkbook(fileInputStream);
Sheet OutputSavingsSheet = Outputworkbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME);
Row row= OutputSavingsSheet.getRow(1);
Assert.assertEquals("Imported",row.getCell(SavingsConstants.STATUS_COL).getStringCellValue());
}
}
@@ -0,0 +1,83 @@
/**
* 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.integrationtests.bulkimport.populator.client;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
public class ClientEntityWorkbookPopulatorTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup(){
Utils.initializeRESTAssured();
this.requestSpec=new RequestSpecBuilder().build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testClientEntityWorkbookPopulate() throws IOException {
//in order to populate helper sheets
StaffHelper staffHelper=new StaffHelper();
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec);
Assert.assertNotNull("Could not create staff",outcome_staff_creation);
//in order to populate helper sheets
OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec);
Integer outcome_office_creation=officeHelper.createOffice("02 May 2000");
Assert.assertNotNull("Could not create office" ,outcome_office_creation);
ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec);
Workbook workbook=clientHelper.getClientEntityWorkbook(GlobalEntityType.CLIENTS_ENTTTY,"dd MMMM yyyy");
Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
Row firstOfficeRow=officeSheet.getRow(1);
Assert.assertNotNull("No offices found for given OfficeId ",firstOfficeRow.getCell(1));
Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
Row firstStaffRow=staffSheet.getRow(1);
Assert.assertNotNull("No staff found for given staffId",firstStaffRow.getCell(1));
}
}
@@ -0,0 +1,129 @@
/**
* 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.integrationtests.bulkimport.populator.loan;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.integrationtests.common.*;
import org.apache.fineract.integrationtests.common.funds.FundsResourceHandler;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
public class LoanWorkbookPopulatorTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup(){
Utils.initializeRESTAssured();
this.requestSpec=new RequestSpecBuilder().build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testLoanWorkbookPopulate() throws IOException {
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
//in order to populate helper sheets
OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec);
Integer outcome_office_creation=officeHelper.createOffice("02 May 2000");
Assert.assertNotNull("Could not create office" ,outcome_office_creation);
//in order to populate helper sheets
ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec);
Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec);
Assert.assertNotNull("Could not create client" ,outcome_client_creation);
//in order to populate helper sheets
GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec);
Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true);
Assert.assertNotNull("Could not create group" ,outcome_group_creation);
//in order to populate helper sheets
StaffHelper staffHelper=new StaffHelper();
Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec);
Assert.assertNotNull("Could not create staff",outcome_staff_creation);
LoanTransactionHelper loanTransactionHelper=new LoanTransactionHelper(requestSpec,responseSpec);
LoanProductTestBuilder loanProductTestBuilder=new LoanProductTestBuilder();
String jsonLoanProduct=loanProductTestBuilder.build(null);
Integer outcome_lp_creaion=loanTransactionHelper.getLoanProductId(jsonLoanProduct);
Assert.assertNotNull("Could not create Loan Product" ,outcome_lp_creaion);
FundsResourceHandler fundsResourceHandler=new FundsResourceHandler();
String jsonFund="{\n" +
"\t\"name\": \""+Utils.randomNameGenerator("Fund_Name",9)+"\"\n" +
"}";
Integer outcome_fund_creation=fundsResourceHandler.createFund(jsonFund,requestSpec,responseSpec);
Assert.assertNotNull("Could not create Fund" ,outcome_fund_creation);
PaymentTypeHelper paymentTypeHelper=new PaymentTypeHelper();
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
Boolean isCashPayment = true;
Integer position = 1;
Integer outcome_payment_creation= paymentTypeHelper.createPaymentType(requestSpec, responseSpec,name,description,isCashPayment,position);
Assert.assertNotNull("Could not create payment type" ,outcome_payment_creation);
Workbook workbook=loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy");
Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
Row firstOfficeRow=officeSheet.getRow(1);
Assert.assertNotNull("No offices found ",firstOfficeRow.getCell(1));
Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME);
Row firstClientRow=clientSheet.getRow(1);
Assert.assertNotNull("No clients found ",firstClientRow.getCell(1));
Sheet groupSheet=workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME);
Row firstGroupRow=groupSheet.getRow(1);
Assert.assertNotNull("No groups found ",firstGroupRow.getCell(1));
Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
Row firstStaffRow=staffSheet.getRow(1);
Assert.assertNotNull("No staff found ",firstStaffRow.getCell(1));
Sheet productSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
Row firstProductRow=productSheet.getRow(1);
Assert.assertNotNull("No products found ",firstProductRow.getCell(1));
Sheet extrasSheet=workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME);
Row firstExtrasRow=extrasSheet.getRow(1);
Assert.assertNotNull("No Extras found ",firstExtrasRow.getCell(1));
}
}
@@ -0,0 +1,64 @@
/**
* 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.integrationtests.bulkimport.populator.office;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
public class OfficeWorkBookPopulatorTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup(){
Utils.initializeRESTAssured();
this.requestSpec=new RequestSpecBuilder().build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testOfficeWorkbookPopulate() throws IOException {
OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec);
Workbook workbook=officeHelper.getOfficeWorkBook("dd MMMM yyyy");
Sheet sheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
Row firstRow= sheet.getRow(1);
Assert.assertNotNull("No parent offices found",firstRow.getCell(OfficeConstants.LOOKUP_OFFICE_COL).getStringCellValue());
Assert.assertEquals(1,firstRow.getCell(OfficeConstants.LOOKUP_OFFICE_ID_COL).getNumericCellValue(),0.0);
}
}
@@ -0,0 +1,112 @@
/**
* 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.integrationtests.bulkimport.populator.savings;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.GroupHelper;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
public class SavingsWorkbookPopulateTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup(){
Utils.initializeRESTAssured();
this.requestSpec=new RequestSpecBuilder().build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testSavingsWorkbookPopulate() throws IOException {
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
//in order to populate helper sheets
OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec);
Integer outcome_office_creation=officeHelper.createOffice("02 May 2000");
Assert.assertNotNull("Could not create office" ,outcome_office_creation);
//in order to populate helper sheets
ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec);
Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec);
Assert.assertNotNull("Could not create client" ,outcome_client_creation);
//in order to populate helper sheets
GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec);
Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true);
Assert.assertNotNull("Could not create group" ,outcome_group_creation);
//in order to populate helper sheets
StaffHelper staffHelper=new StaffHelper();
Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec);
Assert.assertNotNull("Could not create staff",outcome_staff_creation);
SavingsProductHelper savingsProductHelper=new SavingsProductHelper();
String jsonSavingsProduct=savingsProductHelper.build();
Integer outcome_sp_creaction=savingsProductHelper.createSavingsProduct(jsonSavingsProduct,requestSpec,responseSpec);
Assert.assertNotNull("Could not create Savings product",outcome_sp_creaction);
SavingsAccountHelper savingsAccountHelper=new SavingsAccountHelper(requestSpec,responseSpec);
Workbook workbook=savingsAccountHelper.getSavingsWorkbook("dd MMMM yyyy");
Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
Row firstOfficeRow=officeSheet.getRow(1);
Assert.assertNotNull("No offices found ",firstOfficeRow.getCell(1));
Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME);
Row firstClientRow=clientSheet.getRow(1);
Assert.assertNotNull("No clients found ",firstClientRow.getCell(1));
Sheet groupSheet=workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME);
Row firstGroupRow=groupSheet.getRow(1);
Assert.assertNotNull("No groups found ",firstGroupRow.getCell(1));
Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
Row firstStaffRow=staffSheet.getRow(1);
Assert.assertNotNull("No staff found ",firstStaffRow.getCell(1));
Sheet productSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
Row firstProductRow=productSheet.getRow(1);
Assert.assertNotNull("No products found ",firstProductRow.getCell(1));
}
}
@@ -20,15 +20,25 @@ package org.apache.fineract.integrationtests.common;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.integrationtests.common.system.CodeHelper;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
public class ClientHelper {
@@ -591,4 +601,27 @@ public class ClientHelper {
return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL, "reversed");
}
public Workbook getClientEntityWorkbook(GlobalEntityType clientsEntity, String dateFormat) throws IOException {
requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel");
byte [] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,CLIENT_URL+"/downloadtemplate"+"?"+
Utils.TENANT_IDENTIFIER+"&legalFormType="+clientsEntity+"&dateFormat="+dateFormat);
InputStream inputStream= new ByteArrayInputStream(byteArray);
Workbook workbook=new HSSFWorkbook(inputStream);
return workbook;
}
public String getOutputTemplateLocation(final String importDocumentId){
requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN);
return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?"
+Utils.TENANT_IDENTIFIER,importDocumentId);
}
public String importClientEntityTemplate(File file){
String locale="en";
String dateFormat="dd MMMM yyyy";
String legalFormType=GlobalEntityType.CLIENTS_ENTTTY.toString();
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA);
return Utils.performServerTemplatePost(requestSpec,responseSpec,CLIENT_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER,
legalFormType,file,locale,dateFormat);
}
}
@@ -18,6 +18,10 @@
*/
package org.apache.fineract.integrationtests.common;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import com.google.common.reflect.TypeToken;
@@ -25,6 +29,12 @@ import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
public class OfficeHelper {
private static final String OFFICE_URL = "/fineract-provider/api/v1/offices";
@@ -77,4 +87,27 @@ public class OfficeHelper {
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public String importOfficeTemplate(File file){
String locale="en";
String dateFormat="dd MMMM yyyy";
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA);
return Utils.performServerTemplatePost(requestSpec,responseSpec,OFFICE_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER,
null,file,locale,dateFormat);
}
public String getOutputTemplateLocation(final String importDocumentId){
requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN);
return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?"
+Utils.TENANT_IDENTIFIER,importDocumentId);
}
public Workbook getOfficeWorkBook(final String dateFormat) throws IOException {
requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel");
byte[] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,OFFICE_URL+"/downloadtemplate"+"?"+
Utils.TENANT_IDENTIFIER+"&dateFormat="+dateFormat);
InputStream inputStream= new ByteArrayInputStream(byteArray);
Workbook workbook=new HSSFWorkbook(inputStream);
return workbook;
}
}
@@ -24,13 +24,11 @@ import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.io.File;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
import java.util.*;
import org.apache.commons.lang.StringUtils;
import org.apache.http.conn.HttpHostConnectException;
@@ -41,7 +39,6 @@ import com.jayway.restassured.RestAssured;
import com.jayway.restassured.path.json.JsonPath;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
/**
* Util for RestAssured tests. This class here in src/integrationTest is
* copy/pasted to src/test; please keep them in sync.
@@ -145,6 +142,16 @@ public class Utils {
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
return randomStringGenerator(prefix, lenOfRandomSuffix);
}
public static Long randomNumberGenerator(final int expectedLength){
final String source="1234567890";
final int lengthofSource=source.length();
final Random random=new Random();
StringBuilder stringBuilder=new StringBuilder(expectedLength);
for (int i = 0; i < expectedLength; i++) {
stringBuilder.append(source.charAt(random.nextInt(lengthofSource)));
}
return Long.parseLong(stringBuilder.toString());
}
public static String convertDateToURLFormat(final Calendar dateToBeConvert) {
DateFormat dateFormat = new SimpleDateFormat("dd MMMMMM yyyy");
@@ -165,4 +172,27 @@ public class Utils {
return TimeZone.getTimeZone(TENANT_TIME_ZONE);
}
public static String performServerTemplatePost(final RequestSpecification requestSpec,final ResponseSpecification responseSpec,
final String postURL,final String legalFormType,final File file,final String locale,final String dateFormat) {
final String importDocumentId=given().spec(requestSpec)
.queryParam("legalFormType",legalFormType)
.multiPart("file",file)
.formParam("locale",locale)
.formParam("dateFormat",dateFormat)
.expect().spec(responseSpec).
log().ifError().when().post(postURL)
.andReturn().asString();
return importDocumentId;
}
public static String performServerOutputTemplateLocationGet(final RequestSpecification requestSpec,final ResponseSpecification responseSpec,
final String getURL,final String importDocumentId){
final String templateLocation=given().spec(requestSpec).
queryParam("importDocumentId",importDocumentId)
.expect().spec(responseSpec)
.log().ifError().when().get(getURL)
.andReturn().asString();
return templateLocation.substring(1,templateLocation.length()-1);
}
}
@@ -21,18 +21,28 @@ package org.apache.fineract.integrationtests.common.loans;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.joda.time.LocalDate;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@SuppressWarnings({ "rawtypes", "unchecked" })
public class LoanTransactionHelper {
@@ -41,6 +51,7 @@ public class LoanTransactionHelper {
private static final String CREATE_LOAN_PRODUCT_URL = "/fineract-provider/api/v1/loanproducts?" + Utils.TENANT_IDENTIFIER;
private static final String APPLY_LOAN_URL = "/fineract-provider/api/v1/loans?" + Utils.TENANT_IDENTIFIER;
private static final String LOAN_ACCOUNT_URL="/fineract-provider/api/v1/loans";
private static final String APPROVE_LOAN_COMMAND = "approve";
private static final String UNDO_APPROVAL_LOAN_COMMAND = "undoApproval";
private static final String DISBURSE_LOAN_COMMAND = "disburse";
@@ -694,4 +705,29 @@ public class LoanTransactionHelper {
datatablesListMap.add(datatableMap);
return datatablesListMap;
}
public Workbook getLoanWorkbook(String dateFormat) throws IOException {
requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel");
byte[] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,LOAN_ACCOUNT_URL+"/downloadtemplate"+"?"+
Utils.TENANT_IDENTIFIER+"&dateFormat="+dateFormat);
InputStream inputStream= new ByteArrayInputStream(byteArray);
Workbook workbook=new HSSFWorkbook(inputStream);
return workbook;
}
public String importLoanTemplate(File file) {
String locale="en";
String dateFormat="dd MMMM yyyy";
String legalFormType= null;
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA);
return Utils.performServerTemplatePost(requestSpec,responseSpec,LOAN_ACCOUNT_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER,
legalFormType,file,locale,dateFormat);
}
public String getOutputTemplateLocation(final String importDocumentId){
requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN);
return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?"
+Utils.TENANT_IDENTIFIER,importDocumentId);
}
}
@@ -18,6 +18,10 @@
*/
package org.apache.fineract.integrationtests.common.savings;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -27,12 +31,17 @@ import java.util.Locale;
import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@SuppressWarnings({ "rawtypes" })
public class SavingsAccountHelper {
@@ -642,4 +651,28 @@ public class SavingsAccountHelper {
datatablesListMap.add(datatableMap);
return datatablesListMap;
}
public Workbook getSavingsWorkbook(String dateFormat) throws IOException {
requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel");
byte[] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,SAVINGS_ACCOUNT_URL+"/downloadtemplate"+"?"+
Utils.TENANT_IDENTIFIER+"&dateFormat="+dateFormat);
InputStream inputStream= new ByteArrayInputStream(byteArray);
Workbook workbook=new HSSFWorkbook(inputStream);
return workbook;
}
public String importSavingsTemplate(File file) {
String locale="en";
String dateFormat="dd MMMM yyyy";
String legalFormType= null;
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA);
return Utils.performServerTemplatePost(requestSpec,responseSpec,SAVINGS_ACCOUNT_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER,
legalFormType,file,locale,dateFormat);
}
public String getOutputTemplateLocation(final String importDocumentId){
requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN);
return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?"
+Utils.TENANT_IDENTIFIER,importDocumentId);
}
}
@@ -60,7 +60,7 @@ public class SavingsProductHelper {
private String nameOfSavingsProduct = Utils.randomNameGenerator("SAVINGS_PRODUCT_", 6);
private String shortName = Utils.randomNameGenerator("", 4);
private String description = Utils.randomNameGenerator("", 20);
private String interestCompoundingPeriodType = "2";
private String interestCompoundingPeriodType = "4";
private String interestPostingPeriodType = "4";
private String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE;
private String nominalAnnualInterestRate = "10.0";
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.accounting.glaccount.api;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -35,8 +36,11 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
import org.apache.fineract.accounting.common.AccountingConstants;
import org.apache.fineract.accounting.common.AccountingDropdownReadPlatformService;
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
@@ -46,6 +50,9 @@ import org.apache.fineract.accounting.journalentry.data.JournalEntryAssociationP
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService;
import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService;
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
@@ -78,13 +85,19 @@ public class GLAccountsApiResource {
private final PlatformSecurityContext context;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final CodeValueReadPlatformService codeValueReadPlatformService;
private final BulkImportWorkbookService bulkImportWorkbookService;
private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService;
@Autowired
public GLAccountsApiResource(final PlatformSecurityContext context, final GLAccountReadPlatformService glAccountReadPlatformService,
final DefaultToApiJsonSerializer<GLAccountData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final AccountingDropdownReadPlatformService dropdownReadPlatformService,
final CodeValueReadPlatformService codeValueReadPlatformService) {
final CodeValueReadPlatformService codeValueReadPlatformService,
final BulkImportWorkbookService bulkImportWorkbookService,
final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) {
this.context = context;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
@@ -92,6 +105,8 @@ public class GLAccountsApiResource {
this.glAccountReadPlatformService = glAccountReadPlatformService;
this.dropdownReadPlatformService = dropdownReadPlatformService;
this.codeValueReadPlatformService = codeValueReadPlatformService;
this.bulkImportWorkbookService=bulkImportWorkbookService;
this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService;
}
@GET
@@ -219,4 +234,22 @@ public class GLAccountsApiResource {
}
return returnList;
}
@GET
@Path("downloadtemplate")
@Produces("application/vnd.ms-excel")
public Response getGlAccountsTemplate(@QueryParam("dateFormat") final String dateFormat) {
return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.CHART_OF_ACCOUNTS.toString(),null,null,dateFormat);
}
@POST
@Path("uploadtemplate")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String postGlAccountsTemplate(@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail,
@FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){
Long importDocumentId= bulkImportWorkbookService.importWorkbook(GlobalEntityType.CHART_OF_ACCOUNTS.toString(), uploadedInputStream,fileDetail,
locale,dateFormat);
return this.apiJsonSerializerService.serialize(importDocumentId);
}
}
@@ -62,6 +62,55 @@ public class GLAccountData {
final Collection<CodeValueData> allowedIncomeTagOptions;
final Collection<CodeValueData> allowedExpensesTagOptions;
//import fields
private transient Integer rowIndex;
public static GLAccountData importInstance(String name, Long parentId, String glCode, Boolean manualEntriesAllowed,
EnumOptionData type, EnumOptionData usage, String description, CodeValueData tagId,
Integer rowIndex){
return new GLAccountData(name,parentId,glCode,manualEntriesAllowed,type,
usage,description,tagId,rowIndex);
}
private GLAccountData(String name, Long parentId, String glCode, Boolean manualEntriesAllowed,
EnumOptionData type, EnumOptionData usage, String description, CodeValueData tagId,
Integer rowIndex) {
this.name = name;
this.parentId = parentId;
this.glCode = glCode;
this.manualEntriesAllowed = manualEntriesAllowed;
this.type = type;
this.usage = usage;
this.description = description;
this.tagId = tagId;
this.rowIndex = rowIndex;
this.id = null;
this.disabled = null;
this.nameDecorated = null;
this.organizationRunningBalance = null;
this.accountTypeOptions = null;
this.usageOptions = null;
this.assetHeaderAccountOptions = null;
this.liabilityHeaderAccountOptions = null;
this.equityHeaderAccountOptions = null;
this.incomeHeaderAccountOptions = null;
this.expenseHeaderAccountOptions = null;
this.allowedAssetsTagOptions = null;
this.allowedLiabilitiesTagOptions = null;
this.allowedEquityTagOptions = null;
this.allowedIncomeTagOptions = null;
this.allowedExpensesTagOptions = null;
}
public Integer getRowIndex() {
return rowIndex;
}
public CodeValueData getTagId() {
return tagId;
}
public GLAccountData(final Long id, final String name, final Long parentId, final String glCode, final boolean disabled,
final boolean manualEntriesAllowed, final EnumOptionData type, final EnumOptionData usage, final String description,
final String nameDecorated, final CodeValueData tagId, final Long organizationRunningBalance) {
@@ -195,4 +244,5 @@ public class GLAccountData {
return null;
}
}
@@ -18,6 +18,8 @@
*/
package org.apache.fineract.accounting.glaccount.domain;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import java.util.HashMap;
import java.util.Map;
@@ -60,6 +62,27 @@ public enum GLAccountType {
i = i + 1;
}
}
public static EnumOptionData fromString(String accountType){
Long accountTypeId=null;
if (accountType!=null && accountType.equalsIgnoreCase(ASSET.toString())){
accountTypeId=1L;
return new EnumOptionData(accountTypeId,null,null);
}else if(accountType!=null && accountType.equalsIgnoreCase(LIABILITY.toString())) {
accountTypeId = 2L;
return new EnumOptionData(accountTypeId, null, null);
}else if(accountType!=null && accountType.equalsIgnoreCase(EQUITY.toString())){
accountTypeId=3L;
return new EnumOptionData(accountTypeId,null,null);
}else if(accountType!=null && accountType.equalsIgnoreCase(INCOME.toString())) {
accountTypeId = 4L;
return new EnumOptionData(accountTypeId, null, null);
}else if(accountType!=null && accountType.equalsIgnoreCase(EXPENSE.toString())){
accountTypeId=5L;
return new EnumOptionData(accountTypeId,null,null);
}else {
return null;
}
}
public static GLAccountType fromInt(final int i) {
final GLAccountType type = intToEnumMap.get(Integer.valueOf(i));
@@ -123,11 +123,13 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
final GLAccountMapper rm = new GLAccountMapper(associationParametersData);
String sql = "select " + rm.schema();
// append SQL statement for fetching account totals
if (associationParametersData.isRunningBalanceRequired()) {
sql = sql + " and gl_j.id in (select t1.id from (select t2.account_id, max(t2.id) as id from "
+ "(select id, max(entry_date) as entry_date, account_id from acc_gl_journal_entry where is_running_balance_calculated = 1 "
+ "group by account_id desc) t3 inner join acc_gl_journal_entry t2 on t2.account_id = t3.account_id and t2.entry_date = t3.entry_date "
+ "group by t2.account_id desc) t1)";
if (associationParametersData!=null) {
if (associationParametersData.isRunningBalanceRequired()) {
sql = sql + " and gl_j.id in (select t1.id from (select t2.account_id, max(t2.id) as id from "
+ "(select id, max(entry_date) as entry_date, account_id from acc_gl_journal_entry where is_running_balance_calculated = 1 "
+ "group by account_id desc) t3 inner join acc_gl_journal_entry t2 on t2.account_id = t3.account_id and t2.entry_date = t3.entry_date "
+ "group by t2.account_id desc) t1)";
}
}
final Object[] paramaterArray = new Object[3];
int arrayPos = 0;
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.accounting.journalentry.api;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
@@ -32,8 +33,11 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
import org.apache.commons.lang.StringUtils;
import org.apache.fineract.accounting.journalentry.data.JournalEntryAssociationParametersData;
import org.apache.fineract.accounting.journalentry.data.JournalEntryData;
@@ -43,6 +47,9 @@ import org.apache.fineract.accounting.producttoaccountmapping.domain.PortfolioPr
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService;
import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService;
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamException;
@@ -72,17 +79,24 @@ public class JournalEntriesApiResource {
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PlatformSecurityContext context;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final BulkImportWorkbookService bulkImportWorkbookService;
private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService;
@Autowired
public JournalEntriesApiResource(final PlatformSecurityContext context,
final JournalEntryReadPlatformService journalEntryReadPlatformService,
final DefaultToApiJsonSerializer<Object> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final BulkImportWorkbookService bulkImportWorkbookService,
final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) {
this.context = context;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.apiJsonSerializerService = toApiJsonSerializer;
this.journalEntryReadPlatformService = journalEntryReadPlatformService;
this.bulkImportWorkbookService=bulkImportWorkbookService;
this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService;
}
@GET
@@ -208,4 +222,25 @@ public class JournalEntriesApiResource {
private boolean is(final String commandParam, final String commandValue) {
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
}
@GET
@Path("downloadtemplate")
@Produces("application/vnd.ms-excel")
public Response getJournalEntriesTemplate(@QueryParam("officeId") final Long officeId,
@QueryParam("dateFormat") final String dateFormat) {
return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.GL_JOURNAL_ENTRIES.toString(),
officeId,null,dateFormat);
}
@POST
@Path("uploadtemplate")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String postJournalEntriesTemplate(@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail,
@FormDataParam("locale") final String locale,
@FormDataParam("dateFormat") final String dateFormat){
final Long importDocumentId =this.bulkImportWorkbookService.importWorkbook(GlobalEntityType.GL_JOURNAL_ENTRIES.toString(),
uploadedInputStream,fileDetail, locale,dateFormat);
return this.apiJsonSerializerService.serialize(importDocumentId);
}
}
@@ -0,0 +1,31 @@
/**
* 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.accounting.journalentry.data;
import java.math.BigDecimal;
public class CreditDebit {
private final Long glAccountId;
private final BigDecimal amount;
public CreditDebit(Long glAccountId, BigDecimal amount) {
this.glAccountId = glAccountId;
this.amount = amount;
}
}
@@ -19,8 +19,10 @@
package org.apache.fineract.accounting.journalentry.data;
import java.math.BigDecimal;
import java.util.List;
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.joda.time.LocalDate;
@@ -78,6 +80,91 @@ public class JournalEntryData {
@SuppressWarnings("unused")
private final TransactionDetailData transactionDetails;
//import fields
private transient Integer rowIndex;
private String dateFormat;
private String locale;
private List<CreditDebit> credits;
private List<CreditDebit> debits;
private Long paymentTypeId;
private String currencyCode;
private String accountNumber;
private String checkNumber;
private String routingCode;
private String receiptNumber;
private String bankNumber;
public static JournalEntryData importInstance(Long officeId,LocalDate transactionDate,String currencyCode, Long paymentTypeId,
Integer rowIndex,List<CreditDebit> credits, List<CreditDebit>debits,
String accountNumber,String checkNumber,String routingCode,String receiptNumber,String bankNumber,
String comments,String locale,String dateFormat){
return new JournalEntryData(officeId, transactionDate, currencyCode,
paymentTypeId, rowIndex, credits, debits,accountNumber,checkNumber,routingCode,
receiptNumber,bankNumber,comments,locale,dateFormat);
}
private JournalEntryData(Long officeId,LocalDate transactionDate,String currencyCode, Long paymentTypeId,
Integer rowIndex,List<CreditDebit> credits, List<CreditDebit>debits,
String accountNumber,String checkNumber,String routingCode,String receiptNumber,
String bankNumber,String comments,String locale,String dateFormat) {
this.officeId = officeId;
this.dateFormat= dateFormat;
this.locale= locale;
this.transactionDate = transactionDate;
this.currencyCode=currencyCode;
this.rowIndex = rowIndex;
this.credits = credits;
this.debits = debits;
this.paymentTypeId = paymentTypeId;
this.accountNumber=accountNumber;
this.checkNumber=checkNumber;
this.routingCode=routingCode;
this.receiptNumber=receiptNumber;
this.bankNumber=bankNumber;
this.comments=comments;
this.id = null;
this.officeName = null;
this.glAccountName = null;
this.glAccountId = null;
this.glAccountCode = null;
this.glAccountType = null;
this.entryType = null;
this.amount = null;
this.currency = null;
this.transactionId = null;
this.manualEntry = null;
this.entityType = null;
this.entityId = null;
this.createdByUserId = null;
this.createdDate = null;
this.createdByUserName = null;
this.reversed = null;
this.referenceNumber = null;
this.officeRunningBalance = null;
this.organizationRunningBalance = null;
this.runningBalanceComputed = null;
this.transactionDetails = null;
}
public Integer getRowIndex() {
return rowIndex;
}
public LocalDate getTransactionDate() {
return transactionDate;
}
public void addDebits(CreditDebit debit) {
this.debits.add(debit);
}
public void addCredits(CreditDebit credit) {
this.credits.add(credit);
}
public JournalEntryData(final Long id, final Long officeId, final String officeName, final String glAccountName,
final Long glAccountId, final String glAccountCode, final EnumOptionData glAccountClassification,
final LocalDate transactionDate, final EnumOptionData entryType, final BigDecimal amount, final String transactionId,
@@ -0,0 +1,114 @@
/**
* 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.bulkimport.api;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.infrastructure.bulkimport.data.ImportData;
import org.apache.fineract.infrastructure.bulkimport.exceptions.ImportTypeNotFoundException;
import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService;
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Path("/imports")
@Component
@Scope("singleton")
public class BulkImportApiResource {
private final String resourceNameForPermissions = "IMPORT";
private final PlatformSecurityContext context;
private final BulkImportWorkbookService bulkImportWorkbookService;
private final DefaultToApiJsonSerializer<ImportData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
@Autowired
public BulkImportApiResource(final PlatformSecurityContext context,
final BulkImportWorkbookService bulkImportWorkbookService,
final DefaultToApiJsonSerializer<ImportData> toApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper) {
this.context = context;
this.bulkImportWorkbookService = bulkImportWorkbookService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.apiRequestParameterHelper = apiRequestParameterHelper;
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveImportDocuments(@Context final UriInfo uriInfo,
@QueryParam("entityType") final String entityType) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
Collection<ImportData> importData=new ArrayList<>();
if (entityType.equals(GlobalEntityType.CLIENT.getCode())){
final Collection<ImportData> importForClientEntity = this.bulkImportWorkbookService.getImports(GlobalEntityType.CLIENTS_ENTTTY);
final Collection<ImportData> importForClientPerson=this.bulkImportWorkbookService.getImports(GlobalEntityType.CLIENTS_PERSON);
if (importForClientEntity!=null)
importData.addAll(importForClientEntity);
if (importForClientPerson!=null)
importData.addAll(importForClientPerson);
}else {
final GlobalEntityType type = GlobalEntityType.fromCode(entityType);
if (type == null)
throw new ImportTypeNotFoundException(entityType);
importData = this.bulkImportWorkbookService.getImports(type);
}
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, importData);
}
@GET
@Path("getOutputTemplateLocation")
public String retriveOutputTemplateLocation(@QueryParam("importDocumentId")final String importDocumentId ){
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
final DocumentData documentData =this.bulkImportWorkbookService.getOutputTemplateLocation(importDocumentId);
return this.toApiJsonSerializer.serialize(documentData.fileLocation());
}
@GET
@Path("downloadOutputTemplate")
@Produces("application/vnd.ms-excel")
public Response getOutputTemplate(@QueryParam("importDocumentId") final String importDocumentId) {
return bulkImportWorkbookService.getOutputTemplate(importDocumentId);
}
}
@@ -0,0 +1,51 @@
/**
* 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.bulkimport.constants;
public class CenterConstants {
//Column indices
public static final int CENTER_NAME_COL = 0;//A
public static final int OFFICE_NAME_COL = 1;//B
public static final int STAFF_NAME_COL = 2;//C
public static final int EXTERNAL_ID_COL = 3;//D
public static final int ACTIVE_COL = 4;//E
public static final int ACTIVATION_DATE_COL = 5;//F
public static final int SUBMITTED_ON_DATE_COL=6;//G
public static final int MEETING_START_DATE_COL = 7;//H
public static final int IS_REPEATING_COL = 8;//I
public static final int FREQUENCY_COL = 9;//J
public static final int INTERVAL_COL = 10;//K
public static final int REPEATS_ON_DAY_COL = 11;//L
public static final int STATUS_COL = 12;//M
public static final int CENTER_ID_COL = 13;//N
public static final int FAILURE_COL = 14;//O
public static final int GROUP_NAMES_STARTING_COL = 15;//P
public static final int GROUP_NAMES_ENDING_COL = 250;//IQ
public static final int LOOKUP_OFFICE_NAME_COL = 251;
public static final int LOOKUP_OFFICE_OPENING_DATE_COL = 252;
public static final int LOOKUP_REPEAT_NORMAL_COL = 253;
public static final int LOOKUP_REPEAT_MONTHLY_COL = 254;
public static final int LOOKUP_IF_REPEAT_WEEKLY_COL = 255;
}
@@ -0,0 +1,38 @@
/**
* 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.bulkimport.constants;
public class ChartOfAcountsConstants {
public static final int ACCOUNT_TYPE_COL=0;//A
public static final int ACCOUNT_NAME_COL=1;//B
public static final int ACCOUNT_USAGE_COL=2;//C
public static final int MANUAL_ENTRIES_ALLOWED_COL=3;//D
public static final int PARENT_COL=4;//E
public static final int PARENT_ID_COL=5;//F
public static final int GL_CODE_COL=6;//G
public static final int TAG_COL=7;//H
public static final int TAG_ID_COL=8;//I
public static final int DESCRIPTION_COL=9;//J
public static final int LOOKUP_ACCOUNT_TYPE_COL=15;// P
public static final int LOOKUP_ACCOUNT_NAME_COL=16; //Q
public static final int LOOKUP_ACCOUNT_ID_COL=17;//R
public static final int LOOKUP_TAG_COL=18; //S
public static final int LOOKUP_TAG_ID_COL=19; //T
public static final int STATUS_COL=20;
}
@@ -0,0 +1,61 @@
/**
* 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.bulkimport.constants;
public class ClientEntityConstants {
public static final int NAME_COL = 0;//A
public static final int OFFICE_NAME_COL = 1;//B
public static final int STAFF_NAME_COL = 2;//C
public static final int INCOPORATION_DATE_COL = 3;//D
public static final int INCOPORATION_VALID_TILL_COL = 4; //E
public static final int MOBILE_NO_COL=5;//F
public static final int CLIENT_TYPE_COL=6;//G
public static final int CLIENT_CLASSIFICATION_COL=7;//H
public static final int INCOPORATION_NUMBER_COL=8;//I
public static final int MAIN_BUSINESS_LINE=9;//J
public static final int CONSTITUTION_COL=10;//K
public static final int REMARKS_COL=11;//L
public static final int EXTERNAL_ID_COL=12;//M
public static final int ACTIVE_COL = 13;//N
public static final int ACTIVATION_DATE_COL = 14;//O
public static final int SUBMITTED_ON_COL=15; //P
public static final int ADDRESS_ENABLED=16;//Q
public static final int ADDRESS_TYPE_COL=17;//R
public static final int STREET_COL=18;//S
public static final int ADDRESS_LINE_1_COL=19;//T
public static final int ADDRESS_LINE_2_COL=20;//U
public static final int ADDRESS_LINE_3_COL=21;//V
public static final int CITY_COL =22;//W
public static final int STATE_PROVINCE_COL=23;//X
public static final int COUNTRY_COL=24;//Y
public static final int POSTAL_CODE_COL=25;//Z
public static final int IS_ACTIVE_ADDRESS_COL=26;//AA
public static final int WARNING_COL = 26;//AA
public static final int STATUS_COL = 27;//AB
public static final int RELATIONAL_OFFICE_NAME_COL = 35;//AJ
public static final int RELATIONAL_OFFICE_OPENING_DATE_COL = 36;//AK
public static final int LOOKUP_CONSTITUTION_COL = 37;//AL
public static final int LOOKUP_CLIENT_CLASSIFICATION = 38;//AM
public static final int LOOKUP_CLIENT_TYPES = 39;//AN
public static final int LOOKUP_ADDRESS_TYPE = 40;//AO
public static final int LOOKUP_STATE_PROVINCE = 41;//AP
public static final int LOOKUP_COUNTRY = 42;//AQ
public static final int LOOKUP_MAIN_BUSINESS_LINE=43;//AR
}
@@ -0,0 +1,58 @@
/**
* 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.bulkimport.constants;
public class ClientPersonConstants {
public static final int FIRST_NAME_COL = 0;//A
public static final int LAST_NAME_COL = 1;//B
public static final int MIDDLE_NAME_COL = 2;//C
public static final int OFFICE_NAME_COL = 3;//D
public static final int STAFF_NAME_COL = 4;//E
public static final int EXTERNAL_ID_COL = 5;//F
public static final int ACTIVE_COL = 6;//G
public static final int ACTIVATION_DATE_COL = 7;//H
public static final int SUBMITTED_ON_COL=8; //I
public static final int MOBILE_NO_COL=9;//J
public static final int DOB_COL=10;//K
public static final int CLIENT_TYPE_COL=11;//L
public static final int GENDER_COL=12;//M
public static final int CLIENT_CLASSIFICATION_COL=13;//N
public static final int IS_STAFF_COL=14;//O
public static final int ADDRESS_ENABLED_COL=15;// P
public static final int ADDRESS_TYPE_COL=16;//Q
public static final int STREET_COL=17;//R
public static final int ADDRESS_LINE_1_COL=18;//S
public static final int ADDRESS_LINE_2_COL=19;//T
public static final int ADDRESS_LINE_3_COL=20;//U
public static final int CITY_COL=21;//V
public static final int STATE_PROVINCE_COL=22;//W
public static final int COUNTRY_COL=23;//X
public static final int POSTAL_CODE_COL=24;//Y
public static final int IS_ACTIVE_ADDRESS_COL=25;//Z
public static final int WARNING_COL = 26;//AA
public static final int STATUS_COL = 27;//AB
public static final int RELATIONAL_OFFICE_NAME_COL = 35;//AJ
public static final int RELATIONAL_OFFICE_OPENING_DATE_COL = 36;//AK
public static final int LOOKUP_GENDER_COL = 37;//AL
public static final int LOOKUP_CLIENT_CLASSIFICATION_COL = 38;//AM
public static final int LOOKUP_CLIENT_TYPES_COL = 39;//AN
public static final int LOOKUP_ADDRESS_TYPE_COL = 40;//AO
public static final int LOOKUP_STATE_PROVINCE_COL = 41;//AP
public static final int LOOKUP_COUNTRY_COL = 42;//AQ
}
@@ -0,0 +1,55 @@
/**
* 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.bulkimport.constants;
public class FixedDepositConstants {
public static final int OFFICE_NAME_COL = 0;
public static final int CLIENT_NAME_COL = 1;
public static final int PRODUCT_COL = 2;
public static final int FIELD_OFFICER_NAME_COL = 3;
public static final int SUBMITTED_ON_DATE_COL = 4;
public static final int APPROVED_DATE_COL = 5;
public static final int ACTIVATION_DATE_COL = 6;
public static final int INTEREST_COMPOUNDING_PERIOD_COL = 7;
public static final int INTEREST_POSTING_PERIOD_COL = 8;
public static final int INTEREST_CALCULATION_COL = 9;
public static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 10;
public static final int LOCKIN_PERIOD_COL = 11;
public static final int LOCKIN_PERIOD_FREQUENCY_COL = 12;
public static final int DEPOSIT_AMOUNT_COL = 13;
public static final int DEPOSIT_PERIOD_COL = 14;
public static final int DEPOSIT_PERIOD_FREQUENCY_COL = 15;
public static final int EXTERNAL_ID_COL = 16;
public static final int CHARGE_ID_1 = 18;
public static final int CHARGE_AMOUNT_1 = 19;
public static final int CHARGE_DUE_DATE_1 = 20;
public static final int CHARGE_ID_2 = 21;
public static final int CHARGE_AMOUNT_2 = 22;
public static final int CHARGE_DUE_DATE_2 = 23;
public static final int CLOSED_ON_DATE = 24;
public static final int ON_ACCOUNT_CLOSURE_ID = 25;
public static final int TO_SAVINGS_ACCOUNT_ID = 26;
public static final int STATUS_COL = 27;
public static final int SAVINGS_ID_COL = 28;
public static final int FAILURE_REPORT_COL = 29;
public static final int LOOKUP_CLIENT_NAME_COL = 31;
public static final int LOOKUP_ACTIVATION_DATE_COL = 32;
}
@@ -0,0 +1,47 @@
/**
* 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.bulkimport.constants;
public class GroupConstants {
public static final int NAME_COL = 0; //A
public static final int OFFICE_NAME_COL = 1; //B
public static final int STAFF_NAME_COL = 2;//C
public static final int CENTER_NAME_COL = 3;//D
public static final int EXTERNAL_ID_COL = 4;//E
public static final int ACTIVE_COL = 5;//F
public static final int ACTIVATION_DATE_COL = 6;//G
public static final int SUBMITTED_ON_DATE_COL=7;//H
public static final int MEETING_START_DATE_COL = 8;//I
public static final int IS_REPEATING_COL = 9;//J
public static final int FREQUENCY_COL = 10;//K
public static final int INTERVAL_COL = 11;//L
public static final int REPEATS_ON_DAY_COL = 12;//M
public static final int STATUS_COL = 13;//N
public static final int GROUP_ID_COL = 14;//O
public static final int FAILURE_COL = 15;//P
public static final int CLIENT_NAMES_STARTING_COL = 16;//Q
public static final int CLIENT_NAMES_ENDING_COL = 250;//IQ
public static final int LOOKUP_OFFICE_NAME_COL = 251;//IR
public static final int LOOKUP_OFFICE_OPENING_DATE_COL = 252;//IS
public static final int LOOKUP_REPEAT_NORMAL_COL = 253;//IT
public static final int LOOKUP_REPEAT_MONTHLY_COL = 254;//IU
public static final int LOOKUP_IF_REPEAT_WEEKLY_COL = 255;//IV
}
@@ -0,0 +1,45 @@
/**
* 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.bulkimport.constants;
public class GuarantorConstants {
public static final int OFFICE_NAME_COL = 0;
public static final int CLIENT_NAME_COL = 1;
public static final int LOAN_ACCOUNT_NO_COL = 2;
public static final int GUARANTO_TYPE_COL =3;
public static final int CLIENT_RELATIONSHIP_TYPE_COL =4;
public static final int ENTITY_OFFICE_NAME_COL = 5;
public static final int ENTITY_ID_COL = 6;
public static final int FIRST_NAME_COL = 7;
public static final int LAST_NAME_COL = 8;
public static final int ADDRESS_LINE_1_COL= 9;
public static final int ADDRESS_LINE_2_COL = 10;
public static final int CITY_COL = 11;
public static final int DOB_COL = 12;
public static final int ZIP_COL = 13;
public static final int SAVINGS_ID_COL=14;
public static final int AMOUNT=15;
public static final int STATUS_COL = 18;
public static final int LOOKUP_CLIENT_NAME_COL=81;
public static final int LOOKUP_ACCOUNT_NO_COL=82;
public static final int LOOKUP_SAVINGS_CLIENT_NAME_COL=83;
public static final int LOOKUP_SAVINGS_ACCOUNT_NO_COL=84;
public static final int LOOKUP_GUARANTOR_RELATIONSHIPS=85;
}
@@ -0,0 +1,49 @@
/**
* 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.bulkimport.constants;
public class JournalEntryConstants {
public static final int OFFICE_NAME_COL = 0;
public static final int TRANSACION_ON_DATE_COL = 1;
public static final int CURRENCY_NAME_COL = 2;
public static final int PAYMENT_TYPE_ID_COL = 3;
public static final int TRANSACTION_ID_COL = 4;
public static final int GL_ACCOUNT_ID_CREDIT_COL = 5;
public static final int AMOUNT_CREDIT_COL = 6;
public static final int GL_ACCOUNT_ID_DEBIT_COL = 7;
public static final int AMOUNT_DEBIT_COL = 8;
public static final int STATUS_COL = 9;
public static final int ACCOUNT_NO_COL = 10;
public static final int CHECK_NO_COL = 11;
public static final int ROUTING_CODE_COL = 12;
public static final int RECEIPT_NO_COL = 13;
public static final int BANK_NO_COL = 14;
public static final int COMMENTS_COL=15;
}
@@ -0,0 +1,75 @@
/**
* 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.bulkimport.constants;
public class LoanConstants {
public static final int OFFICE_NAME_COL = 0;//A
public static final int LOAN_TYPE_COL = 1;//B
public static final int CLIENT_NAME_COL = 2;//C
public static final int CLIENT_EXTERNAL_ID=3;//D
public static final int PRODUCT_COL = 4;//E
public static final int LOAN_OFFICER_NAME_COL = 5;//F
public static final int SUBMITTED_ON_DATE_COL = 6;//G
public static final int APPROVED_DATE_COL = 7;//H
public static final int DISBURSED_DATE_COL = 8;//I
public static final int DISBURSED_PAYMENT_TYPE_COL = 9;//J
public static final int FUND_NAME_COL = 10;//K
public static final int PRINCIPAL_COL = 11;//L
public static final int NO_OF_REPAYMENTS_COL = 12;//M
public static final int REPAID_EVERY_COL = 13;//N
public static final int REPAID_EVERY_FREQUENCY_COL = 14;//O
public static final int LOAN_TERM_COL = 15;//P
public static final int LOAN_TERM_FREQUENCY_COL = 16;//Q
public static final int NOMINAL_INTEREST_RATE_COL = 17;//R
public static final int NOMINAL_INTEREST_RATE_FREQUENCY_COL = 18;//S
public static final int AMORTIZATION_COL = 19;//T
public static final int INTEREST_METHOD_COL = 20;//U
public static final int INTEREST_CALCULATION_PERIOD_COL = 21;//V
public static final int ARREARS_TOLERANCE_COL = 22;//W
public static final int REPAYMENT_STRATEGY_COL = 23;//X
public static final int GRACE_ON_PRINCIPAL_PAYMENT_COL = 24;//Y
public static final int GRACE_ON_INTEREST_PAYMENT_COL = 25;//Z
public static final int GRACE_ON_INTEREST_CHARGED_COL = 26;//AA
public static final int INTEREST_CHARGED_FROM_COL = 27;//AB
public static final int FIRST_REPAYMENT_COL = 28;//AC
public static final int TOTAL_AMOUNT_REPAID_COL = 29;//AD
public static final int LAST_REPAYMENT_DATE_COL = 30;//AE
public static final int REPAYMENT_TYPE_COL = 31;//AF
public static final int STATUS_COL = 32;//AG
public static final int LOAN_ID_COL = 33;//AH
public static final int FAILURE_REPORT_COL = 34;//AI
public static final int EXTERNAL_ID_COL = 35;//AJ
public static final int CHARGE_ID_1 = 36;//AK
public static final int CHARGE_AMOUNT_1 = 37;//AL
public static final int CHARGE_DUE_DATE_1 = 38;//AM
public static final int CHARGE_ID_2 = 39;//AN
public static final int CHARGE_AMOUNT_2 = 40;//AO
public static final int CHARGE_DUE_DATE_2 = 41;//AP
public static final int GROUP_ID = 42;//AQ
public static final int LOOKUP_CLIENT_NAME_COL = 43;//AR
public static final int LOOKUP_CLIENT_EXTERNAL_ID=44;//AS
public static final int LOOKUP_ACTIVATION_DATE_COL = 45;//AT
public static final int LINK_ACCOUNT_ID = 46;//AU
public static final String LOAN_TYPE_INDIVIDUAL="Individual";
public static final String LOAN_TYPE_GROUP="Group";
public static final String LOAN_TYPE_JLG="JLG" ;
}
@@ -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.
*/
package org.apache.fineract.infrastructure.bulkimport.constants;
public class LoanRepaymentConstants {
public static final int OFFICE_NAME_COL = 0;//A
public static final int CLIENT_NAME_COL = 1;//B
public static final int CLIENT_EXTERNAL_ID=2;//C
public static final int LOAN_ACCOUNT_NO_COL = 3;//D
public static final int PRODUCT_COL = 4;//E
public static final int PRINCIPAL_COL = 5;//F
public static final int AMOUNT_COL = 6;//G
public static final int REPAID_ON_DATE_COL = 7;//H
public static final int REPAYMENT_TYPE_COL = 8;//I
public static final int ACCOUNT_NO_COL = 9;//J
public static final int CHECK_NO_COL = 10;//K
public static final int ROUTING_CODE_COL = 11;//L
public static final int RECEIPT_NO_COL = 12;//M
public static final int BANK_NO_COL = 13;//N
public static final int STATUS_COL = 14;//O
public static final int LOOKUP_CLIENT_NAME_COL = 15;//P
public static final int LOOKUP_CLIENT_EXTERNAL_ID = 16;//Q
public static final int LOOKUP_ACCOUNT_NO_COL = 17;//R
public static final int LOOKUP_PRODUCT_COL = 18;//S
public static final int LOOKUP_PRINCIPAL_COL = 19;//T
public static final int LOOKUP_LOAN_DISBURSEMENT_DATE_COL = 20;//U
}
@@ -0,0 +1,33 @@
/**
* 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.bulkimport.constants;
public class OfficeConstants {
//Column indices
public static final int OFFICE_NAME_COL = 0;
public static final int PARENT_OFFICE_NAME_COL = 1;
public static final int PARENT_OFFICE_ID_COL=2;
public static final int OPENED_ON_COL = 3;
public static final int EXTERNAL_ID_COL = 4;
public static final int LOOKUP_OFFICE_COL=7;
public static final int LOOKUP_OFFICE_ID_COL=8;
public static final int STATUS_COL=10;
}
@@ -0,0 +1,60 @@
/**
* 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.bulkimport.constants;
public class RecurringDepositConstants {
public static final int OFFICE_NAME_COL = 0;
public static final int CLIENT_NAME_COL = 1;
public static final int PRODUCT_COL = 2;
public static final int FIELD_OFFICER_NAME_COL = 3;
public static final int SUBMITTED_ON_DATE_COL = 4;
public static final int APPROVED_DATE_COL = 5;
public static final int ACTIVATION_DATE_COL = 6;
public static final int INTEREST_COMPOUNDING_PERIOD_COL = 7;
public static final int INTEREST_POSTING_PERIOD_COL = 8;
public static final int INTEREST_CALCULATION_COL = 9;
public static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 10;
public static final int LOCKIN_PERIOD_COL = 11;
public static final int LOCKIN_PERIOD_FREQUENCY_COL = 12;
public static final int RECURRING_DEPOSIT_AMOUNT_COL = 13;
public static final int DEPOSIT_PERIOD_COL = 14;
public static final int DEPOSIT_PERIOD_FREQUENCY_COL = 15;
public static final int DEPOSIT_FREQUENCY_COL = 16;
public static final int DEPOSIT_FREQUENCY_TYPE_COL = 17;
public static final int DEPOSIT_START_DATE_COL = 18;
public static final int IS_MANDATORY_DEPOSIT_COL = 19;
public static final int ALLOW_WITHDRAWAL_COL = 20;
public static final int FREQ_SAME_AS_GROUP_CENTER_COL = 21;
public static final int ADJUST_ADVANCE_PAYMENTS_COL = 22;
public static final int EXTERNAL_ID_COL = 23;
public static final int STATUS_COL = 24;
public static final int SAVINGS_ID_COL = 25;
public static final int FAILURE_REPORT_COL = 26;
public static final int CHARGE_ID_1 = 28;
public static final int CHARGE_AMOUNT_1 = 29;
public static final int CHARGE_DUE_DATE_1 = 30;
public static final int CHARGE_ID_2 = 33;
public static final int CHARGE_AMOUNT_2 = 34;
public static final int CHARGE_DUE_DATE_2 = 35;
public static final int LOOKUP_CLIENT_NAME_COL = 31;
public static final int LOOKUP_ACTIVATION_DATE_COL = 32;
}
@@ -0,0 +1,57 @@
/**
* 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.bulkimport.constants;
public class SavingsConstants {
public static final int OFFICE_NAME_COL = 0;
public static final int SAVINGS_TYPE_COL = 1;
public static final int CLIENT_NAME_COL = 2;
public static final int PRODUCT_COL = 3;
public static final int FIELD_OFFICER_NAME_COL = 4;
public static final int SUBMITTED_ON_DATE_COL = 5;
public static final int APPROVED_DATE_COL = 6;
public static final int ACTIVATION_DATE_COL = 7;
public static final int CURRENCY_COL = 8;
public static final int DECIMAL_PLACES_COL = 9;
public static final int IN_MULTIPLES_OF_COL = 10;
public static final int NOMINAL_ANNUAL_INTEREST_RATE_COL = 11;
public static final int INTEREST_COMPOUNDING_PERIOD_COL = 12;
public static final int INTEREST_POSTING_PERIOD_COL = 13;
public static final int INTEREST_CALCULATION_COL = 14;
public static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 15;
public static final int MIN_OPENING_BALANCE_COL = 16;
public static final int LOCKIN_PERIOD_COL = 17;
public static final int LOCKIN_PERIOD_FREQUENCY_COL = 18;
public static final int APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS = 19;
public static final int ALLOW_OVER_DRAFT_COL = 20;
public static final int OVER_DRAFT_LIMIT_COL= 21;
public static final int EXTERNAL_ID_COL = 22;
public static final int STATUS_COL = 23;
public static final int SAVINGS_ID_COL = 24;
public static final int FAILURE_REPORT_COL = 25;
public static final int LOOKUP_CLIENT_NAME_COL = 31;
public static final int LOOKUP_ACTIVATION_DATE_COL = 32;
public static final int CHARGE_ID_1 = 34;
public static final int CHARGE_AMOUNT_1 = 35;
public static final int CHARGE_DUE_DATE_1 = 36;
public static final int CHARGE_ID_2 = 37;
public static final int CHARGE_AMOUNT_2 = 38;
public static final int CHARGE_DUE_DATE_2 = 39;
}
@@ -0,0 +1,45 @@
/**
* 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.bulkimport.constants;
public class SharedAccountsConstants {
public static final int CLIENT_NAME_COL=0;
public static final int PRODUCT_COL=1;
public static final int SUBMITTED_ON_COL=2;
public static final int EXTERNAL_ID_COL=3;
public static final int CURRENCY_COL=4;
public static final int DECIMAL_PLACES_COL=5;
public static final int TOTAL_NO_SHARES_COL=6;
public static final int TODAYS_PRICE_COL=7;
public static final int CURRENCY_IN_MULTIPLES_COL=8;
public static final int DEFAULT_SAVINGS_AC_COL=9;
public static final int MINIMUM_ACTIVE_PERIOD_IN_DAYS_COL=10;
public static final int LOCK_IN_PERIOD_COL=11;
public static final int LOCK_IN_PERIOD_FREQUENCY_TYPE=12;
public static final int APPLICATION_DATE_COL=13;
public static final int ALLOW_DIVIDEND_CALCULATION_FOR_INACTIVE_CLIENTS_COL=14;
public static final int CHARGES_NAME_1_COL=15;
public static final int CHARGES_AMOUNT_1_COL=16;
public static final int CHARGES_NAME_2_COL=17;
public static final int CHARGES_AMOUNT_2_COL=18;
public static final int CHARGES_NAME_3_COL=19;
public static final int CHARGES_AMOUNT_3_COL=20;
public static final int STATUS_COL=25;
}
@@ -0,0 +1,32 @@
/**
* 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.bulkimport.constants;
public class StaffConstants {
public static final int OFFICE_NAME_COL = 0;//A
public static final int FIRST_NAME_COL = 1;//B
public static final int LAST_NAME_COL = 2;//C
public static final int IS_LOAN_OFFICER = 3;//D
public static final int MOBILE_NO_COL=4;//E
public static final int JOINED_ON_COL =5;//F
public static final int EXTERNAL_ID_COL =6;//G
public static final int IS_ACTIVE_COL =7;//h
public static final int STATUS_COL=8;//H
}
@@ -0,0 +1,143 @@
/**
* 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.bulkimport.constants;
public class TemplatePopulateImportConstants {
//columns sizes
public final static int SMALL_COL_SIZE =4000;
public final static int MEDIUM_COL_SIZE =6000;
public final static int LARGE_COL_SIZE=8000;
public final static int EXTRALARGE_COL_SIZE=10000;
//Sheet names
public static final String OFFICE_SHEET_NAME ="Offices";
public static final String CENTER_SHEET_NAME="Centers";
public static final String STAFF_SHEET_NAME="Staff";
public static final String GROUP_SHEET_NAME="Groups";
public static final String CHART_OF_ACCOUNTS_SHEET_NAME="ChartOfAccounts";
public static final String CLIENT_ENTITY_SHEET_NAME="ClientEntity";
public static final String CLIENT_PERSON_SHEET_NAME="ClientPerson";
public static final String CLIENT_SHEET_NAME="Clients";
public static final String FIXED_DEPOSIT_SHEET_NAME="FixedDeposit";
public static final String FIXED_DEPOSIT_TRANSACTION_SHEET_NAME="FixedDepositTransactions";
public static final String PRODUCT_SHEET_NAME="Products";
public static final String GUARANTOR_SHEET_NAME="guarantor";
public static final String EXTRAS_SHEET_NAME="Extras";
public static final String GL_ACCOUNTS_SHEET_NAME="GlAccounts";
public static final String SAVINGS_ACCOUNTS_SHEET_NAME="SavingsAccounts";
public static final String SHARED_PRODUCTS_SHEET_NAME="SharedProducts";
public static final String JOURNAL_ENTRY_SHEET_NAME="AddJournalEntries";
public static final String LOANS_SHEET_NAME="Loans";
public static final String LOAN_REPAYMENT_SHEET_NAME="LoanRepayment";
public static final String RECURRING_DEPOSIT_SHEET_NAME="RecurringDeposit";
public static final String SAVINGS_TRANSACTION_SHEET_NAME="SavingsTransaction";
public static final String SHARED_ACCOUNTS_SHEET_NAME="SharedAccounts";
public static final String EMPLOYEE_SHEET_NAME="Employee";
public static final String ROLES_SHEET_NAME="Roles";
public static final String USER_SHEET_NAME="Users";
public final static int ROWHEADER_INDEX=0;
public final static short ROW_HEADER_HEIGHT =500;
public final static int FIRST_COLUMN_INDEX=0;
//Status column
public final static String STATUS_CELL_IMPORTED="Imported";
public final static String STATUS_CREATION_FAILED="Creation failed";
public final static String STATUS_APPROVAL_FAILED="Approval failed";
public final static String STATUS_ACTIVATION_FAILED="Activation failed";
public final static String STATUS_MEETING_FAILED="Meeting failed";
public final static String STATUS_DISBURSAL_FAILED="Disbursal failed";
public final static String STATUS_DISBURSAL_REPAYMENT_FAILED="Repayment failed";
public final static String STATUS_COLUMN_HEADER="Status";
//Frequency Calender
public static final String FREQUENCY_DAILY="Daily";
public static final String FREQUENCY_WEEKLY="Weekly";
public static final String FREQUENCY_MONTHLY="Monthly";
public static final String FREQUENCY_YEARLY= "Yearly";
//InterestCompoundingPeriod
public static final String INTEREST_COMPOUNDING_PERIOD_DAILY="Daily";
public static final String INTEREST_COMPOUNDING_PERIOD_MONTHLY="Monthly";
public static final String INTEREST_COMPOUNDING_PERIOD_QUARTERLY="Quarterly";
public static final String INTEREST_COMPOUNDING_PERIOD_SEMI_ANNUALLY="Semi-Annual";
public static final String INTEREST_COMPOUNDING_PERIOD_ANNUALLY="Annually";
//InterestPostingPeriod
public static final String INTEREST_POSTING_PERIOD_MONTHLY="Monthly";
public static final String INTEREST_POSTING_PERIOD_QUARTERLY="Quarterly";
public static final String INTEREST_POSTING_PERIOD_BIANUALLY="BiAnnual";
public static final String INTEREST_POSTING_PERIOD_ANNUALLY="Annually";
//InterestCalculation
public static final String INTEREST_CAL_DAILY_BALANCE="Daily Balance";
public static final String INTEREST_CAL_AVG_BALANCE="Average Daily Balance";
//InterestCalculation Day in Year
public static final String INTEREST_CAL_DAYS_IN_YEAR_360="360 Days";
public static final String INTEREST_CAL_DAYS_IN_YEAR_365="365 Days";
//Frequency
public static final String FREQUENCY_DAYS="Days";
public static final String FREQUENCY_WEEKS="Weeks";
public static final String FREQUENCY_MONTHS="Months";
public static final String FREQUENCY_YEARS="Years";
//Day Of Week
public static final String MONDAY ="Mon";
public static final String TUESDAY ="Tue";
public static final String WEDNESDAY ="Wed";
public static final String THURSDAY ="Thu";
public static final String FRIDAY ="Fri";
public static final String SATURDAY ="Sat";
public static final String SUNDAY ="Sun";
//Entity types
public static final String CENTER_ENTITY_TYPE="CENTER";
public static final String OFFICE_ENTITY_TYPE="OFFICE";
public static final String STAFF_ENTITY_TYPE="STAFF";
public static final String USER_ENTITY_TYPE="USER";
public static final String GROUP_ENTITY_TYPE="GROUP";
public static final String CLIENT_ENTITY_TYPE="CLIENT";
public static final String LOAN_PRODUCT_ENTITY_TYPE="LOANPRODUCT";
public static final String FUNDS_ENTITY_TYPE="FUNDS";
public static final String PAYMENT_TYPE_ENTITY_TYPE="PAYMENTTYPE";
public static final String CURRENCY_ENTITY_TYPE="CURRENCY";
public static final String GL_ACCOUNT_ENTITY_TYPE="GLACCOUNT";
public static final String SHARED_ACCOUNT_ENTITY_TYPE="SHAREDACCOUNT";
public static final String SAVINGS_PRODUCT_ENTITY_TYPE="SAVINGSPRODUCT";
public static final String RECURRING_DEPOSIT_PRODUCT_ENTITY_TYPE="RECURRINGDEPOSITPRODUCT";
public static final String FIXED_DEPOSIT_PRODUCT_ENTITY_TYPE="FIXEDDEPOSITPRODUCT";
//ReportHeader Values
public static final String STATUS_COL_REPORT_HEADER="Status";
public static final String CENTERID_COL_REPORT_HEADER="Center Id";
public static final String SAVINGS_ID_COL_REPORT_HEADER="Savings ID";
public static final String GROUP_ID_COL_REPORT_HEADER="Group ID";
public static final String FAILURE_COL_REPORT_HEADER="Failure Report";
//Guarantor Types
public static final String GUARANTOR_INTERNAL="Internal";
public static final String GUARANTOR_EXTERNAL="External";
//Loan Account/Loan repayment Client External Id
public static final Boolean CONTAINS_CLIENT_EXTERNAL_ID=true;
}
@@ -0,0 +1,43 @@
/**
* 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.bulkimport.constants;
public class TransactionConstants {
public static final int OFFICE_NAME_COL = 0;
public static final int CLIENT_NAME_COL = 1;
public static final int SAVINGS_ACCOUNT_NO_COL = 2;
public static final int PRODUCT_COL = 3;
public static final int OPENING_BALANCE_COL = 4;
public static final int TRANSACTION_TYPE_COL = 5;
public static final int AMOUNT_COL = 6;
public static final int TRANSACTION_DATE_COL = 7;
public static final int PAYMENT_TYPE_COL = 8;
public static final int ACCOUNT_NO_COL = 9;
public static final int CHECK_NO_COL = 10;
public static final int ROUTING_CODE_COL = 11;
public static final int RECEIPT_NO_COL = 12;
public static final int BANK_NO_COL = 13;
public static final int STATUS_COL = 14;
public static final int LOOKUP_CLIENT_NAME_COL = 15;
public static final int LOOKUP_ACCOUNT_NO_COL = 16;
public static final int LOOKUP_PRODUCT_COL = 17;
public static final int LOOKUP_OPENING_BALANCE_COL = 18;
public static final int LOOKUP_SAVINGS_ACTIVATION_DATE_COL = 19;
}
@@ -0,0 +1,34 @@
/**
* 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.bulkimport.constants;
public class UserConstants {
public static final int OFFICE_NAME_COL=0;
public static final int STAFF_NAME_COL=1;
public static final int USER_NAME_COL=2;
public static final int FIRST_NAME_COL=3;
public static final int LAST_NAME_COL=4;
public static final int EMAIL_COL=5;
public static final int AUTO_GEN_PW_COL=6;
public static final int OVERRIDE_PW_EXPIRY_POLICY_COL=7;
public static final int STATUS_COL=8;
public static final int ROLE_NAME_START_COL=9;
public static final int ROLE_NAME_END_COL=14;
}
@@ -0,0 +1,71 @@
/**
* 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.bulkimport.data;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.context.ApplicationEvent;
public class BulkImportEvent extends ApplicationEvent {
private final String tenantIdentifier;
private final Workbook workbook;
private final Long importId;
private final String locale;
private final String dateFormat;
private BulkImportEvent(final String tenantIdentifier, final Workbook workbook,
final Long importId, final String locale, final String dateFormat) {
super(BulkImportEvent.class);
this.tenantIdentifier = tenantIdentifier;
this.workbook = workbook;
this.importId = importId;
this.locale = locale;
this.dateFormat = dateFormat;
}
public static BulkImportEvent instance(final String tenantIdentifier, final Workbook workbook,
final Long importId, final String locale, final String dateFormat) {
return new BulkImportEvent(tenantIdentifier, workbook, importId, locale, dateFormat);
}
public String getTenantIdentifier() {
return tenantIdentifier;
}
public Workbook getWorkbook() {
return workbook;
}
public Long getImportId() {
return importId;
}
public String getDateFormat() {
return dateFormat;
}
public String getLocale() {
return locale;
}
}
@@ -0,0 +1,45 @@
/**
* 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.bulkimport.data;
public class Count {
private Integer successCount;
private Integer errorCount;
public static Count instance(final Integer successCount,
final Integer errorCount) {
return new Count(successCount, errorCount);
}
private Count(final Integer successCount,
final Integer errorCount) {
this.successCount = successCount;
this.errorCount = errorCount;
}
public Integer getSuccessCount() {
return successCount;
}
public Integer getErrorCount() {
return errorCount;
}
}
@@ -0,0 +1,118 @@
/**
* 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.bulkimport.data;
import java.util.HashMap;
import java.util.Map;
public enum GlobalEntityType {
INVALID(0, "invalid"),
CLIENTS_PERSON(1, "clients.person"),
CLIENTS_ENTTTY(2,"clients.entity"),
GROUPS(3, "groups"),
CENTERS(4, "centers"),
OFFICES(5, "offices"),
STAFF(6, "staff"),
USERS(7, "users"),
SMS(8, "sms"),
DOCUMENTS(9, "documents"),
TEMPLATES(10, "templates"),
NOTES(11, "templates"),
CALENDAR(12, "calendar"),
MEETINGS(13, "meetings"),
HOLIDAYS(14, "holidays"),
LOANS(15, "loans"),
LOAN_PRODUCTS(16,"loancharges"),
LOAN_TRANSACTIONS(18, "loantransactions"),
GUARANTORS(19, "guarantors"),
COLLATERALS(20, "collaterals"),
FUNDS(21, "funds"),
CURRENCY(22, "currencies"),
SAVINGS_ACCOUNT(23, "savingsaccount"),
SAVINGS_CHARGES(24, "savingscharges"),
SAVINGS_TRANSACTIONS(25, "savingstransactions"),
SAVINGS_PRODUCTS(26, "savingsproducts"),
GL_JOURNAL_ENTRIES(27, "gljournalentries"),
CODE_VALUE(28, "codevalue"),
CODE(29, "code"),
CHART_OF_ACCOUNTS(30,"chartofaccounts"),
FIXED_DEPOSIT_ACCOUNTS(31,"fixeddepositaccounts"),
FIXED_DEPOSIT_TRANSACTIONS(32,"fixeddeposittransactions"),
SHARE_ACCOUNTS(33,"shareaccounts"),
RECURRING_DEPOSIT_ACCOUNTS(34,"recurringdeposits"),
RECURRING_DEPOSIT_ACCOUNTS_TRANSACTIONS(35,"recurringdepositstransactions"),
CLIENT(36,"client");
private final Integer value;
private final String code;
private static final Map<Integer, GlobalEntityType> intToEnumMap = new HashMap<>();
private static final Map<String, GlobalEntityType> stringToEnumMap = new HashMap<>();
private static int minValue;
private static int maxValue;
static {
int i = 0;
for (final GlobalEntityType entityType : GlobalEntityType.values()) {
if (i == 0) {
minValue = entityType.value;
}
intToEnumMap.put(entityType.value, entityType);
stringToEnumMap.put(entityType.code, entityType);
if (minValue >= entityType.value) {
minValue = entityType.value;
}
if (maxValue < entityType.value) {
maxValue = entityType.value;
}
i = i + 1;
}
}
private GlobalEntityType(final Integer value, final String code) {
this.value = value;
this.code = code;
}
public Integer getValue() {
return this.value;
}
public String getCode() {
return this.code;
}
public static GlobalEntityType fromInt(final int i) {
final GlobalEntityType entityType = intToEnumMap.get(Integer.valueOf(i));
return entityType;
}
public static GlobalEntityType fromCode(final String key) {
final GlobalEntityType entityType = stringToEnumMap.get(key);
return entityType;
}
@Override
public String toString() {
return name().toString();
}
}
@@ -0,0 +1,80 @@
/**
* 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.bulkimport.data;
import org.joda.time.LocalDate;
public class ImportData {
@SuppressWarnings("unused")
private Long importId;
@SuppressWarnings("unused")
private Long documentId;
@SuppressWarnings("unused")
private String name;
@SuppressWarnings("unused")
private LocalDate importTime;
@SuppressWarnings("unused")
private LocalDate endTime;
@SuppressWarnings("unused")
private Boolean completed;
@SuppressWarnings("unused")
private Long createdBy;
@SuppressWarnings("unused")
private Integer totalRecords;
@SuppressWarnings("unused")
private Integer successCount;
@SuppressWarnings("unused")
private Integer failureCount;
public static ImportData instance(final Long importId, final Long documentId,
final LocalDate importTime, final LocalDate endTime,
final Boolean completed, final String name,
final Long createdBy, final Integer totalRecords, final Integer successCount,
final Integer failureCount) {
return new ImportData(importId, documentId, importTime, endTime,
completed, name, createdBy, totalRecords, successCount,
failureCount);
}
public static ImportData instance(final Long importId){
return new ImportData(importId,null,null,
null,null,null,null,null,
null,null);
}
private ImportData(final Long importId, final Long documentId,
final LocalDate importTime, final LocalDate endTime,
final Boolean completed, final String name,
final Long createdBy, final Integer totalRecords, final Integer successCount,
final Integer failureCount) {
this.importId = importId;
this.documentId = documentId;
this.name = name;
this.importTime = importTime;
this.endTime = endTime;
this.completed = completed;
this.createdBy = createdBy;
this.totalRecords = totalRecords;
this.successCount = successCount;
this.failureCount = failureCount;
}
}
@@ -0,0 +1,49 @@
/**
* 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.bulkimport.data;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
public enum ImportFormatType {
XLSX ("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
XLS ("application/vnd.ms-excel"),
ODS ("application/vnd.oasis.opendocument.spreadsheet");
private final String format;
private ImportFormatType(String format) {
this.format= format;
}
public String getFormat() {
return format;
}
public static ImportFormatType of(String name) {
for(ImportFormatType type : ImportFormatType.values()) {
if(type.name().equalsIgnoreCase(name)) {
return type;
}
}
throw new GeneralPlatformDomainRuleException("error.msg.invalid.file.extension",
"Uploaded file extension is not recognized.");
}
}
@@ -0,0 +1,124 @@
/**
* 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.bulkimport.domain;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.documentmanagement.domain.Document;
import org.apache.fineract.useradministration.domain.AppUser;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
@Entity
@Table(name = "m_import_document")
public class ImportDocument extends AbstractPersistableCustom<Long>{
@OneToOne
@JoinColumn(name = "document_id")
private Document document;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "import_time")
private Date importTime;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "end_time")
private Date endTime;
@Column(name = "completed", nullable = false)
private Boolean completed;
@Column(name = "entity_type")
private Integer entity_type;
@ManyToOne
@JoinColumn(name = "createdby_id")
private AppUser createdBy;
@Column(name = "total_records", nullable = true)
private Integer totalRecords;
@Column(name = "success_count", nullable = true)
private Integer successCount;
@Column(name = "failure_count", nullable = true)
private Integer failureCount;
protected ImportDocument() {
}
public static ImportDocument instance(final Document document, final LocalDateTime importTime,
final Integer entity_type, final AppUser createdBy, final Integer totalRecords) {
final Boolean completed = Boolean.FALSE;
final Integer successCount = 0;
final Integer failureCount = 0;
final LocalDateTime endTime = LocalDateTime.now();
return new ImportDocument(document, importTime, endTime, completed, entity_type,
createdBy, totalRecords, successCount, failureCount);
}
private ImportDocument(final Document document, final LocalDateTime importTime,
final LocalDateTime endTime, Boolean completed, final Integer entity_type,
final AppUser createdBy, final Integer totalRecords, final Integer successCount,
final Integer failureCount) {
this.document = document;
this.importTime = importTime.toDate();
this.endTime = endTime.toDate();
this.completed = completed;
this.entity_type = entity_type;
this.createdBy = createdBy;
this.totalRecords = totalRecords;
this.successCount = successCount;
this.failureCount = failureCount;
}
public void update(final LocalDateTime endTime, final Integer successCount,
final Integer errorCount) {
this.endTime = endTime.toDate();
this.completed = Boolean.TRUE;
this.successCount = successCount;
this.failureCount = errorCount;
}
public Document getDocument() {
return this.document;
}
public Integer getEntityType() {
return this.entity_type;
}
}
@@ -0,0 +1,27 @@
/**
* 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.bulkimport.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface ImportDocumentRepository
extends JpaRepository<ImportDocument, Long>, JpaSpecificationExecutor<ImportDocument> {
// no added behaviour
}
@@ -0,0 +1,29 @@
/**
* 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.bulkimport.exceptions;
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class ImportTypeNotFoundException extends AbstractPlatformResourceNotFoundException {
public ImportTypeNotFoundException(final String entityType) {
super("error.msg.entity.type.invalid", "Entity type " + entityType + " does not exist", entityType);
}
}
@@ -0,0 +1,27 @@
/**
* 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.bulkimport.importhandler;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.poi.ss.usermodel.Workbook;
public interface ImportHandler {
public Count process(Workbook workbook, String locale, String dateFormat);
}
@@ -0,0 +1,355 @@
/**
* 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.bulkimport.importhandler;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public class ImportHandlerUtils {
public static Integer getNumberOfRows(Sheet sheet, int primaryColumn) {
Integer noOfEntries = 0;
// getLastRowNum and getPhysicalNumberOfRows showing false values
// sometimes
while (sheet.getRow(noOfEntries+1) !=null && sheet.getRow(noOfEntries+1).getCell(primaryColumn) != null) {
noOfEntries++;
}
return noOfEntries;
}
public static boolean isNotImported(Row row, int statusColumn) {
if (readAsString(statusColumn,row)!=null) {
return !readAsString(statusColumn, row).equals(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
}else {
return true;
}
}
public static Long readAsLong(int colIndex, Row row) {
Cell c = row.getCell(colIndex);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK)
return null;
FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
if(eval!=null) {
CellValue val = eval.evaluate(c);
return ((Double) val.getNumberValue()).longValue();
}
}
else if (c.getCellType()==Cell.CELL_TYPE_NUMERIC){
return ((Double) c.getNumericCellValue()).longValue();
}
else {
return Long.parseLong(row.getCell(colIndex).getStringCellValue());
}
return null;
}
public static String readAsString(int colIndex, Row row) {
Cell c = row.getCell(colIndex);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK)
return null;
FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
if (eval!=null) {
CellValue val = eval.evaluate(c);
String res = trimEmptyDecimalPortion(val.getStringValue());
if (res!=null) {
if (!res.equals("")) {
return res.trim();
} else {
return null;
}
}else {
return null;
}
}else {
return null;
}
}else if(c.getCellType()==Cell.CELL_TYPE_STRING) {
String res = trimEmptyDecimalPortion(c.getStringCellValue().trim());
return res.trim();
}else if(c.getCellType()==Cell.CELL_TYPE_NUMERIC) {
return ((Double) row.getCell(colIndex).getNumericCellValue()).intValue() + "";
}else if (c.getCellType()==Cell.CELL_TYPE_BOOLEAN){
return c.getBooleanCellValue()+"";
}else {
return null;
}
}
public static String trimEmptyDecimalPortion(String result) {
if(result != null && result.endsWith(".0"))
return result.split("\\.")[0];
else
return result;
}
public static LocalDate readAsDate(int colIndex, Row row) {
Cell c = row.getCell(colIndex);
if(c == null || c.getCellType() == Cell.CELL_TYPE_BLANK)
return null;
LocalDate localDate=new LocalDate(c.getDateCellValue());
return localDate;
}
public static Boolean readAsBoolean(int colIndex, Row row) {
Cell c = row.getCell(colIndex);
if(c == null || c.getCellType() == Cell.CELL_TYPE_BLANK)
return false;
FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
if(eval!=null) {
CellValue val = eval.evaluate(c);
return val.getBooleanValue();
}
return false;
}else if(c.getCellType()==Cell.CELL_TYPE_BOOLEAN)
return c.getBooleanCellValue();
else {
String booleanString = row.getCell(colIndex).getStringCellValue().trim();
if (booleanString.equalsIgnoreCase("TRUE"))
return true;
else
return false;
}
}
public static Integer readAsInt(int colIndex, Row row) {
Cell c = row.getCell(colIndex);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK)
return null;
FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
if(eval!=null) {
CellValue val = eval.evaluate(c);
return ((Double) val.getNumberValue()).intValue();
}
return null;
}else if (c.getCellType()==Cell.CELL_TYPE_NUMERIC) {
return ((Double) c.getNumericCellValue()).intValue();
}else {
return Integer.parseInt(row.getCell(colIndex).getStringCellValue());
}
}
public static Double readAsDouble(int colIndex, Row row) {
Cell c = row.getCell(colIndex);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK)
return 0.0;
FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
if (eval!=null) {
CellValue val = eval.evaluate(c);
return val.getNumberValue();
}else {
return 0.0;
}
} else if (c.getCellType()==Cell.CELL_TYPE_NUMERIC) {
return row.getCell(colIndex).getNumericCellValue();
}else {
return Double.parseDouble(row.getCell(colIndex).getStringCellValue());
}
}
public static void writeString(int colIndex, Row row, String value) {
if(value!=null)
row.createCell(colIndex).setCellValue(value);
}
public static CellStyle getCellStyle(Workbook workbook, IndexedColors color) {
CellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(color.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
return style;
}
public static String getDefaultUserMessages(List<ApiParameterError> ApiParameterErrorList){
StringBuffer defaultUserMessages=new StringBuffer();
for (ApiParameterError error:ApiParameterErrorList) {
defaultUserMessages=defaultUserMessages.append(error.getDefaultUserMessage()+'\t');
}
return defaultUserMessages.toString();
}
public static String getErrorList(List<String> errorList){
StringBuffer errors=new StringBuffer();
for (String error: errorList) {
errors=errors.append(error);
}
return errors.toString();
}
public static void writeErrorMessage(Sheet sheet,Integer rowIndex,String errorMessage,int statusColumn){
Cell statusCell = sheet.getRow(rowIndex).createCell(statusColumn);
statusCell.setCellValue(errorMessage);
statusCell.setCellStyle(getCellStyle(sheet.getWorkbook(), IndexedColors.RED));
}
public static String getErrorMessage(RuntimeException re) {
if (re instanceof AbstractPlatformDomainRuleException){
AbstractPlatformDomainRuleException abstractPlatformDomainRuleException= (AbstractPlatformDomainRuleException) re;
return abstractPlatformDomainRuleException.getDefaultUserMessage();
}else if (re instanceof AbstractPlatformResourceNotFoundException){
AbstractPlatformResourceNotFoundException abstractPlatformResourceNotFoundException= (AbstractPlatformResourceNotFoundException) re;
return abstractPlatformResourceNotFoundException.getDefaultUserMessage();
}else if (re instanceof AbstractPlatformServiceUnavailableException) {
AbstractPlatformServiceUnavailableException abstractPlatformServiceUnavailableException = (AbstractPlatformServiceUnavailableException) re;
return abstractPlatformServiceUnavailableException.getDefaultUserMessage();
}else if (re instanceof PlatformDataIntegrityException){
PlatformDataIntegrityException platformDataIntegrityException= (PlatformDataIntegrityException) re;
return platformDataIntegrityException.getDefaultUserMessage();
}else if (re instanceof PlatformApiDataValidationException){
PlatformApiDataValidationException platformApiDataValidationException=(PlatformApiDataValidationException) re;
return getDefaultUserMessages(platformApiDataValidationException.getErrors());
}else if (re instanceof UnsupportedParameterException ){
UnsupportedParameterException unsupportedParameterException= (UnsupportedParameterException) re;
return getErrorList(unsupportedParameterException.getUnsupportedParameters());
}else {
if (re.getMessage()!=null) {
return re.getMessage();
}else {
return re.getClass().getCanonicalName();
}
}
}
public static Long getIdByName (Sheet sheet, String name) {
String sheetName = sheet.getSheetName();
if(!sheetName.equals(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME)) {
for (Row row : sheet) {
for (Cell cell : row) {
if(name!=null) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getRichStringCellValue().getString().trim().equals(name)) {
if (sheetName.equals(TemplatePopulateImportConstants.OFFICE_SHEET_NAME) ||
sheetName.equals(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME) ||
sheetName.equals(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME) ||
sheetName.equals(TemplatePopulateImportConstants.SHARED_PRODUCTS_SHEET_NAME)||
sheetName.equals(TemplatePopulateImportConstants.ROLES_SHEET_NAME)) {
if (row.getCell(cell.getColumnIndex() - 1).getCellType() == Cell.CELL_TYPE_NUMERIC)
return ((Double) row.getCell(cell.getColumnIndex() - 1).getNumericCellValue()).longValue();
return 0L;
} else if (sheetName.equals(TemplatePopulateImportConstants.CLIENT_SHEET_NAME) ||
sheetName.equals(TemplatePopulateImportConstants.CENTER_SHEET_NAME) ||
sheetName.equals(TemplatePopulateImportConstants.GROUP_SHEET_NAME) ||
sheetName.equals(TemplatePopulateImportConstants.STAFF_SHEET_NAME))
if (row.getCell(cell.getColumnIndex() + 1).getCellType() == Cell.CELL_TYPE_NUMERIC)
return ((Double) row.getCell(cell.getColumnIndex() + 1).getNumericCellValue()).longValue();
return 0L;
}
}else {
return 0L;
}
}
}
} else if (sheetName.equals(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME)) {
for(Row row : sheet) {
for(int i = 0; i < 2; i++) {
if (name != null) {
Cell cell = row.getCell(i);
if (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getRichStringCellValue().getString().trim().equals(name)) {
return ((Double) row.getCell(cell.getColumnIndex() - 1).getNumericCellValue()).longValue();
}
}else {
return 0L;
}
}
}
}
return 0L;
}
public static String getCodeByName(Sheet sheet, String name) {
String sheetName = sheet.getSheetName();
sheetName.equals(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME);
{
for (Row row : sheet) {
for (Cell cell : row) {
if (name!=null) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING
&& cell.getRichStringCellValue().getString().trim()
.equals(name)) {
return row.getCell(cell.getColumnIndex() - 1)
.getStringCellValue().toString();
}
}
}
}
}
return "";
}
public static String getFrequencyId(String frequency) {
if (frequency!=null) {
if (frequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_DAILY))
frequency = "1";
else if (frequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_WEEKLY))
frequency = "2";
else if (frequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_MONTHLY))
frequency = "3";
else if (frequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_YEARLY))
frequency = "4";
return frequency;
}else {
return null;
}
}
public static String getRepeatsOnDayId(String repeatsOnDay) {
if (repeatsOnDay!=null) {
if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.MONDAY))
repeatsOnDay = "1";
else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.TUESDAY))
repeatsOnDay = "2";
else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.WEDNESDAY))
repeatsOnDay = "3";
else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.THURSDAY))
repeatsOnDay = "4";
else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.FRIDAY))
repeatsOnDay = "5";
else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.SATURDAY))
repeatsOnDay = "6";
else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.SUNDAY))
repeatsOnDay = "7";
return repeatsOnDay;
}else {
return null;
}
}
}
@@ -0,0 +1,259 @@
/**
* 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.bulkimport.importhandler.center;
import com.google.common.reflect.TypeToken;
import com.google.gson.GsonBuilder;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.CenterConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataValueSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.GroupIdSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.calendar.data.CalendarData;
import org.apache.fineract.portfolio.group.data.CenterData;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Service
public class CenterImportHandler implements ImportHandler {
private List<CenterData> centers;
private List<CalendarData> meetings;
private List<String>statuses;
private Workbook workbook;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public CenterImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.centers=new ArrayList<>();
this.meetings=new ArrayList<>();
this.statuses=new ArrayList<>();
this.workbook=workbook;
readExcelFile(locale, dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
Sheet centersSheet = workbook.getSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(centersSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex = 1; rowIndex <=noOfEntries; rowIndex++) {
Row row;
row = centersSheet.getRow(rowIndex);
if(ImportHandlerUtils.isNotImported(row, CenterConstants.STATUS_COL)) {
centers.add(readCenter(row,locale,dateFormat));
meetings.add(readMeeting(row,locale,dateFormat));
}
}
}
private CalendarData readMeeting(Row row,final String locale, final String dateFormat) {
LocalDate meetingStartDate = ImportHandlerUtils.readAsDate(CenterConstants.MEETING_START_DATE_COL, row);
Boolean isRepeating = ImportHandlerUtils.readAsBoolean(CenterConstants.IS_REPEATING_COL, row);
String frequency = ImportHandlerUtils.readAsString(CenterConstants.FREQUENCY_COL, row);
EnumOptionData frequencyEnum=new EnumOptionData(null,null,ImportHandlerUtils.getFrequencyId(frequency));
Integer interval = ImportHandlerUtils.readAsInt(CenterConstants.INTERVAL_COL, row);
String repeatsOnDay = ImportHandlerUtils.readAsString(CenterConstants.REPEATS_ON_DAY_COL, row);
EnumOptionData repeatsOnDayEnum=new EnumOptionData(null,null,ImportHandlerUtils.getRepeatsOnDayId(repeatsOnDay));
if(meetingStartDate==null)
return null;
else {
if(repeatsOnDay==null)
return CalendarData.importInstanceNoRepeatsOnDay(meetingStartDate, isRepeating,
frequencyEnum, interval, row.getRowNum(),locale,dateFormat);
else
return CalendarData.importInstanceWithRepeatsOnDay(meetingStartDate, isRepeating,
frequencyEnum, interval, repeatsOnDayEnum, row.getRowNum(),locale,dateFormat);
}
}
private CenterData readCenter(Row row,final String locale, final String dateFormat) {
String status = ImportHandlerUtils.readAsString(CenterConstants.STATUS_COL, row);
String officeName = ImportHandlerUtils.readAsString(CenterConstants.OFFICE_NAME_COL, row);
Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName);
String staffName = ImportHandlerUtils.readAsString(CenterConstants.STAFF_NAME_COL, row);
Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName);
String externalId = ImportHandlerUtils.readAsString(CenterConstants.EXTERNAL_ID_COL, row);
Boolean active = ImportHandlerUtils.readAsBoolean(CenterConstants.ACTIVE_COL, row);
LocalDate submittedOn=ImportHandlerUtils.readAsDate(CenterConstants.SUBMITTED_ON_DATE_COL,row);
LocalDate activationDate = null;
if (active){
activationDate=ImportHandlerUtils.readAsDate(CenterConstants.ACTIVATION_DATE_COL, row);
}else {
activationDate=submittedOn;
}
String centerName = ImportHandlerUtils.readAsString(CenterConstants.CENTER_NAME_COL, row);
if(centerName==null||centerName.equals("")) {
throw new IllegalArgumentException("Name is blank");
}
List<GroupGeneralData> groupMembers = new ArrayList<GroupGeneralData>();
for (int cellNo =CenterConstants. GROUP_NAMES_STARTING_COL; cellNo < CenterConstants.GROUP_NAMES_ENDING_COL; cellNo++) {
String groupName = ImportHandlerUtils.readAsString(cellNo, row);
if (groupName==null||groupName.equals(""))
break;
Long groupId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME), groupName);
GroupGeneralData group = new GroupGeneralData(groupId);
if (!containsGroupId(groupMembers,groupId)) {
groupMembers.add(group);
}
}
statuses.add(status);
return CenterData.importInstance(centerName,groupMembers,activationDate, active,submittedOn, externalId,
officeId, staffId, row.getRowNum(),dateFormat,locale);
}
private boolean containsGroupId(List<GroupGeneralData> groupMembers,Long groupId){
for (GroupGeneralData group: groupMembers) {
if (group.getId()==groupId){
return true;
}
}
return false;
}
public Count importEntity(String dateFormat) {
Sheet centerSheet = workbook.getSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME);
int progressLevel = 0;
String centerId = "";
int successCount = 0;
int errorCount = 0;
String errorMessage = "";
for (int i = 0; i < centers.size(); i++) {
Row row = centerSheet.getRow(centers.get(i).getRowIndex());
Cell errorReportCell = row.createCell(CenterConstants.FAILURE_COL);
Cell statusCell = row.createCell(CenterConstants.STATUS_COL);
CommandProcessingResult result = null;
try {
String status = statuses.get(i);
progressLevel = getProgressLevel(status);
if (progressLevel == 0) {
result = importCenter(i, dateFormat);
centerId = result.getGroupId().toString();
progressLevel = 1;
} else
centerId = ImportHandlerUtils.readAsInt(CenterConstants.CENTER_ID_COL, centerSheet.getRow(centers.get(i).getRowIndex())).toString();
if (meetings.get(i) != null)
progressLevel = importCenterMeeting(result, i, dateFormat);
successCount++;
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
writeCenterErrorMessage(centerId,errorMessage,progressLevel,statusCell,errorReportCell,row);
}
}
setReportHeaders(centerSheet);
return Count.instance(successCount, errorCount);
}
private void writeCenterErrorMessage(String centerId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){
String status = "";
if (progressLevel == 0)
status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED;
else if (progressLevel == 1)
status = TemplatePopulateImportConstants.STATUS_MEETING_FAILED;
statusCell.setCellValue(status);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED));
if (progressLevel > 0)
row.createCell(CenterConstants.CENTER_ID_COL).setCellValue(Integer.parseInt(centerId));
errorReportCell.setCellValue(errorMessage);
}
private int getProgressLevel(String status) {
if(status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED))
return 0;
else if(status.equals(TemplatePopulateImportConstants.STATUS_MEETING_FAILED))
return 1;
return 0;
}
private CommandProcessingResult importCenter(int rowIndex,String dateFormat) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
Type groupCollectionType = new TypeToken<Collection<GroupGeneralData>>() {}.getType();
gsonBuilder.registerTypeAdapter(groupCollectionType,new GroupIdSerializer());
String payload= gsonBuilder.create().toJson(centers.get(rowIndex));;
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createCenter() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return result;
}
private void setReportHeaders(Sheet sheet) {
ImportHandlerUtils.writeString(CenterConstants.STATUS_COL, sheet.getRow(0), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
ImportHandlerUtils.writeString(CenterConstants.CENTER_ID_COL, sheet.getRow(0), TemplatePopulateImportConstants.CENTERID_COL_REPORT_HEADER);
ImportHandlerUtils.writeString(CenterConstants.FAILURE_COL, sheet.getRow(0), TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER);
}
private Integer importCenterMeeting(CommandProcessingResult result, int rowIndex,String dateFormat) {
CalendarData calendarData=meetings.get(rowIndex);
calendarData.setTitle("centers_" + result.getGroupId().toString() + "_CollectionMeeting");
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataValueSerializer());
String payload = gsonBuilder.create().toJson(calendarData);
CommandWrapper commandWrapper=new CommandWrapper(result.getOfficeId(),result.getGroupId(),result.getClientId(),
result.getLoanId(),result.getSavingsId(),null,null,null,null,
null,payload,result.getTransactionId(),result.getProductId(),null,null,
null);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createCalendar(commandWrapper,TemplatePopulateImportConstants.CENTER_ENTITY_TYPE,result.getGroupId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult meetingresult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return 2;
}
}
@@ -0,0 +1,143 @@
/**
* 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.bulkimport.importhandler.chartofaccounts;
import com.google.gson.GsonBuilder;
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
import org.apache.fineract.accounting.glaccount.domain.GLAccountUsage;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.ChartOfAcountsConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.CodeValueDataIdSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataIdSerializer;
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class ChartOfAccountsImportHandler implements ImportHandler {
private List<GLAccountData> glAccounts;
private Workbook workbook;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public ChartOfAccountsImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.glAccounts=new ArrayList<>();
this.workbook=workbook;
readExcelFile();
return importEntity();
}
public void readExcelFile() {
Sheet chartOfAccountsSheet=workbook.getSheet(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME);
Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(chartOfAccountsSheet,TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){
Row row;
row=chartOfAccountsSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, ChartOfAcountsConstants.STATUS_COL)){
glAccounts.add(readGlAccounts(row));
}
}
}
private GLAccountData readGlAccounts(Row row) {
String accountType=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.ACCOUNT_TYPE_COL,row);
EnumOptionData accountTypeEnum=GLAccountType.fromString(accountType);
String accountName=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.ACCOUNT_NAME_COL,row);
String usage=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.ACCOUNT_USAGE_COL,row);
Long usageId=null;
EnumOptionData usageEnum=null;
if (usage!=null&& usage.equals(GLAccountUsage.DETAIL.toString())){
usageId=1L;
usageEnum=new EnumOptionData(usageId,null,null);
}else if (usage!=null&&usage.equals(GLAccountUsage.HEADER.toString())){
usageId=2L;
usageEnum=new EnumOptionData(usageId,null,null);
}
Boolean manualEntriesAllowed=ImportHandlerUtils.readAsBoolean(ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL,row);
Long parentId=null;
if (ImportHandlerUtils.readAsString(ChartOfAcountsConstants.PARENT_ID_COL,row)!=null) {
parentId = Long.parseLong(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.PARENT_ID_COL,row));
}
String glCode=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.GL_CODE_COL,row);
Long tagId=null;
if(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.TAG_ID_COL,row)!=null)
tagId=Long.parseLong(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.TAG_ID_COL,row));
CodeValueData tagIdCodeValueData=new CodeValueData(tagId);
String description=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.DESCRIPTION_COL,row);
return GLAccountData.importInstance(accountName,parentId,glCode,manualEntriesAllowed,accountTypeEnum,
usageEnum,description,tagIdCodeValueData,row.getRowNum());
}
public Count importEntity() {
Sheet chartOfAccountsSheet=workbook.getSheet(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(EnumOptionData.class, new EnumOptionDataIdSerializer());
gsonBuilder.registerTypeAdapter(CodeValueData.class, new CodeValueDataIdSerializer());
int successCount = 0;
int errorCount = 0;
String errorMessage = "";
for (GLAccountData glAccount: glAccounts) {
try {
String payload=gsonBuilder.create().toJson(glAccount);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createGLAccount() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = chartOfAccountsSheet.getRow(glAccount.getRowIndex()).createCell(ChartOfAcountsConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(chartOfAccountsSheet,glAccount.getRowIndex(),errorMessage,ChartOfAcountsConstants.STATUS_COL);
}
}
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(ChartOfAcountsConstants.STATUS_COL, chartOfAccountsSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.STATUS_COLUMN_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,212 @@
/**
* 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.bulkimport.importhandler.client;
import com.google.gson.GsonBuilder;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.address.data.AddressData;
import org.apache.fineract.portfolio.client.data.ClientData;
import org.apache.fineract.portfolio.client.data.ClientNonPersonData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class ClientEntityImportHandler implements ImportHandler {
private Workbook workbook;
private List<ClientData> clients;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public ClientEntityImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook = workbook;
this.clients=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME);
Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(clientSheet,0);
for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){
Row row;
row=clientSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, ClientEntityConstants.STATUS_COL)){
clients.add(readClient(row,locale,dateFormat));
}
}
}
private ClientData readClient(Row row,final String locale, final String dateFormat) {
Long legalFormId=2L;
String name = ImportHandlerUtils.readAsString(ClientEntityConstants.NAME_COL, row);
String officeName = ImportHandlerUtils.readAsString(ClientEntityConstants.OFFICE_NAME_COL, row);
Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName);
String staffName = ImportHandlerUtils.readAsString(ClientEntityConstants.STAFF_NAME_COL, row);
Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName);
LocalDate incorportionDate=ImportHandlerUtils.readAsDate(ClientEntityConstants.INCOPORATION_DATE_COL,row);
LocalDate incorporationTill=ImportHandlerUtils.readAsDate(ClientEntityConstants.INCOPORATION_VALID_TILL_COL,row);
String mobileNo=null;
if (ImportHandlerUtils.readAsLong(ClientEntityConstants.MOBILE_NO_COL, row)!=null)
mobileNo = ImportHandlerUtils.readAsLong(ClientEntityConstants.MOBILE_NO_COL, row).toString();
String clientType=ImportHandlerUtils.readAsString(ClientEntityConstants.CLIENT_TYPE_COL, row);
Long clientTypeId = null;
if (clientType!=null) {
String clientTypeAr[] =clientType .split("-");
if (clientTypeAr[1] != null) {
clientTypeId = Long.parseLong(clientTypeAr[1]);
}
}
String clientClassification= ImportHandlerUtils.readAsString(ClientEntityConstants.CLIENT_CLASSIFICATION_COL, row);
Long clientClassicationId = null;
if (clientClassification!=null) {
String clientClassificationAr[] =clientClassification.split("-");
if (clientClassificationAr[1] != null)
clientClassicationId = Long.parseLong(clientClassificationAr[1]);
}
String incorporationNo=ImportHandlerUtils.readAsString(ClientEntityConstants.INCOPORATION_NUMBER_COL,row);
String mainBusinessLine=ImportHandlerUtils.readAsString(ClientEntityConstants.MAIN_BUSINESS_LINE,row);
Long mainBusinessId = null;
if (mainBusinessLine!=null) {
String mainBusinessLineAr[] = ImportHandlerUtils.readAsString(ClientEntityConstants.MAIN_BUSINESS_LINE, row).split("-");
if (mainBusinessLineAr[1] != null)
mainBusinessId = Long.parseLong(mainBusinessLineAr[1]);
}
String constitution= ImportHandlerUtils.readAsString(ClientEntityConstants.CONSTITUTION_COL,row);
Long constitutionId = null;
if (constitution!=null) {
String constitutionAr[] = constitution.split("-");
if (constitutionAr[1] != null)
constitutionId = Long.parseLong(constitutionAr[1]);
}
String remarks = ImportHandlerUtils.readAsString(ClientEntityConstants.REMARKS_COL, row);
ClientNonPersonData clientNonPersonData= ClientNonPersonData.importInstance(incorporationNo,incorporationTill,remarks,
mainBusinessId,constitutionId,locale,dateFormat);
String externalId= ImportHandlerUtils.readAsString(ClientEntityConstants.EXTERNAL_ID_COL, row);
Boolean active = ImportHandlerUtils.readAsBoolean(ClientEntityConstants.ACTIVE_COL, row);
LocalDate submittedOn=ImportHandlerUtils.readAsDate(ClientEntityConstants.SUBMITTED_ON_COL,row);
LocalDate activationDate = ImportHandlerUtils.readAsDate(ClientEntityConstants.ACTIVATION_DATE_COL, row);
if (!active){
activationDate=submittedOn;
}
AddressData addressDataObj=null;
if (ImportHandlerUtils.readAsBoolean(ClientEntityConstants.ADDRESS_ENABLED,row)) {
String addressType = ImportHandlerUtils.readAsString(ClientEntityConstants.ADDRESS_TYPE_COL, row);
Long addressTypeId = null;
if (addressType!=null) {
String addressTypeAr[] = addressType.split("-");
if (addressTypeAr[1] != null)
addressTypeId = Long.parseLong(addressTypeAr[1]);
}
String street = ImportHandlerUtils.readAsString(ClientEntityConstants.STREET_COL, row);
String addressLine1 = ImportHandlerUtils.readAsString(ClientEntityConstants.ADDRESS_LINE_1_COL, row);
String addressLine2 = ImportHandlerUtils.readAsString(ClientEntityConstants.ADDRESS_LINE_2_COL, row);
String addressLine3 = ImportHandlerUtils.readAsString(ClientEntityConstants.ADDRESS_LINE_3_COL, row);
String city = ImportHandlerUtils.readAsString(ClientEntityConstants.CITY_COL, row);
String postalCode = ImportHandlerUtils.readAsString(ClientEntityConstants.POSTAL_CODE_COL, row);
Boolean isActiveAddress = ImportHandlerUtils.readAsBoolean(ClientEntityConstants.IS_ACTIVE_ADDRESS_COL, row);
String stateProvince=ImportHandlerUtils.readAsString(ClientEntityConstants.STATE_PROVINCE_COL, row);
Long stateProvinceId = null;
if (stateProvince!=null) {
String stateProvinceAr[] = stateProvince.split("-");
if (stateProvinceAr[1] != null)
stateProvinceId = Long.parseLong(stateProvinceAr[1]);
}
String country= ImportHandlerUtils.readAsString(ClientEntityConstants.COUNTRY_COL, row);
Long countryId = null;
if (country!=null) {
String countryAr[] = country.split("-");
if (countryAr[1] != null)
countryId = Long.parseLong(countryAr[1]);
}
addressDataObj = new AddressData(addressTypeId, street, addressLine1, addressLine2, addressLine3,
city, postalCode, isActiveAddress, stateProvinceId, countryId);
}
return ClientData.importClientEntityInstance(legalFormId,row.getRowNum(),name,officeId,clientTypeId,clientClassicationId,
staffId,active,activationDate,submittedOn, externalId,incorportionDate,mobileNo,clientNonPersonData,addressDataObj,locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME);
int successCount = 0;
int errorCount = 0;
String errorMessage = "";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
for (ClientData client: clients) {
try {
String payload=gsonBuilder.create().toJson(client);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createClient() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = clientSheet.getRow(client.getRowIndex()).createCell(ClientEntityConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(clientSheet,client.getRowIndex(),errorMessage,ClientEntityConstants.STATUS_COL);
}
}
clientSheet.setColumnWidth(ClientEntityConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(ClientEntityConstants.STATUS_COL, clientSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.STATUS_COLUMN_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,197 @@
/**
* 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.bulkimport.importhandler.client;
import com.google.gson.GsonBuilder;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.ClientPersonConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.address.data.AddressData;
import org.apache.fineract.portfolio.client.data.ClientData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class ClientPersonImportHandler implements ImportHandler {
private Workbook workbook;
private List<ClientData> clients;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public ClientPersonImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook = workbook;
this.clients=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME);
Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(clientSheet,0);
for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){
Row row;
row=clientSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, ClientPersonConstants.STATUS_COL)){
clients.add(readClient(row,locale,dateFormat));
}
}
}
private ClientData readClient(Row row,final String locale, final String dateFormat) {
Long legalFormId=1L;
String firstName = ImportHandlerUtils.readAsString(ClientPersonConstants.FIRST_NAME_COL, row);
String lastName = ImportHandlerUtils.readAsString(ClientPersonConstants.LAST_NAME_COL, row);
String middleName = ImportHandlerUtils.readAsString(ClientPersonConstants.MIDDLE_NAME_COL, row);
String officeName = ImportHandlerUtils.readAsString(ClientPersonConstants.OFFICE_NAME_COL, row);
Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName);
String staffName = ImportHandlerUtils.readAsString(ClientPersonConstants.STAFF_NAME_COL, row);
Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName);
String externalId = ImportHandlerUtils.readAsString(ClientPersonConstants.EXTERNAL_ID_COL, row);
LocalDate submittedOn=ImportHandlerUtils.readAsDate(ClientPersonConstants.SUBMITTED_ON_COL,row);
LocalDate activationDate = ImportHandlerUtils.readAsDate(ClientPersonConstants.ACTIVATION_DATE_COL, row);
Boolean active = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.ACTIVE_COL, row);
if (!active){
activationDate=submittedOn;
}
String mobileNo=null;
if (ImportHandlerUtils.readAsLong(ClientPersonConstants.MOBILE_NO_COL, row)!=null)
mobileNo = ImportHandlerUtils.readAsLong(ClientPersonConstants.MOBILE_NO_COL, row).toString();
LocalDate dob = ImportHandlerUtils.readAsDate(ClientPersonConstants.DOB_COL, row);
String clientType=ImportHandlerUtils.readAsString(ClientPersonConstants.CLIENT_TYPE_COL, row);
Long clientTypeId = null;
if (clientType!=null) {
String clientTypeAr[] = clientType.split("-");
if (clientTypeAr[1] != null) {
clientTypeId = Long.parseLong(clientTypeAr[1]);
}
}
String gender=ImportHandlerUtils.readAsString(ClientPersonConstants.GENDER_COL, row);
Long genderId = null;
if (gender!=null) {
String genderAr[] = gender.split("-");
if (genderAr[1] != null)
genderId = Long.parseLong(genderAr[1]);
}
String clientClassification= ImportHandlerUtils.readAsString(ClientPersonConstants.CLIENT_CLASSIFICATION_COL, row);
Long clientClassicationId = null;
if (clientClassification!=null) {
String clientClassificationAr[] = clientClassification.split("-");
if (clientClassificationAr[1] != null)
clientClassicationId = Long.parseLong(clientClassificationAr[1]);
}
Boolean isStaff = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.IS_STAFF_COL, row);
AddressData addressDataObj=null;
if (ImportHandlerUtils.readAsBoolean(ClientPersonConstants.ADDRESS_ENABLED_COL,row)) {
String addressType=ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_TYPE_COL, row);
Long addressTypeId = null;
if (addressType!=null) {
String addressTypeAr[] = addressType.split("-");
if (addressTypeAr[1] != null)
addressTypeId = Long.parseLong(addressTypeAr[1]);
}
String street = ImportHandlerUtils.readAsString(ClientPersonConstants.STREET_COL, row);
String addressLine1 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_1_COL, row);
String addressLine2 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_2_COL, row);
String addressLine3 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_3_COL, row);
String city = ImportHandlerUtils.readAsString(ClientPersonConstants.CITY_COL, row);
String postalCode = ImportHandlerUtils.readAsString(ClientPersonConstants.POSTAL_CODE_COL, row);
Boolean isActiveAddress = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.IS_ACTIVE_ADDRESS_COL, row);
String stateProvince=ImportHandlerUtils.readAsString(ClientPersonConstants.STATE_PROVINCE_COL, row);
Long stateProvinceId = null;
if (stateProvince!=null) {
String stateProvinceAr[] = stateProvince.split("-");
if (stateProvinceAr[1] != null)
stateProvinceId = Long.parseLong(stateProvinceAr[1]);
}
String country=ImportHandlerUtils.readAsString(ClientPersonConstants.COUNTRY_COL, row);
Long countryId=null;
if (country!=null) {
String countryAr[] = country.split("-");
if (countryAr[1] != null)
countryId = Long.parseLong(countryAr[1]);
}
addressDataObj = new AddressData(addressTypeId, street, addressLine1, addressLine2, addressLine3,
city, postalCode, isActiveAddress, stateProvinceId, countryId);
}
return ClientData.importClientPersonInstance(legalFormId,row.getRowNum(),firstName,lastName,middleName,submittedOn,activationDate,active,externalId,
officeId,staffId,mobileNo,dob,clientTypeId,genderId,clientClassicationId,isStaff,addressDataObj,locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
for (ClientData client: clients) {
try {
String payload=gsonBuilder.create().toJson(client);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createClient() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = clientSheet.getRow(client.getRowIndex()).createCell(ClientPersonConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(clientSheet,client.getRowIndex(),errorMessage,ClientPersonConstants.STATUS_COL);
}
}
clientSheet.setColumnWidth(ClientPersonConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(ClientPersonConstants.STATUS_COL, clientSheet.
getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), TemplatePopulateImportConstants.STATUS_COLUMN_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,390 @@
/**
* 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.bulkimport.importhandler.fixeddeposits;
import com.google.gson.*;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.FixedDepositConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataIdSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.savings.data.*;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class FixedDepositImportHandler implements ImportHandler {
private Workbook workbook;
private List<FixedDepositAccountData> savings;
private List<SavingsApproval> approvalDates;
private List<SavingsActivation> activationDates;
private List<ClosingOfSavingsAccounts> closedOnDate;
private List<String> statuses;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public FixedDepositImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook = workbook;
savings=new ArrayList<>();
approvalDates=new ArrayList<>();
activationDates=new ArrayList<>();
closedOnDate=new ArrayList<>();
statuses=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = savingsSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, FixedDepositConstants.STATUS_COL)) {
savings.add(readSavings(row,locale,dateFormat));
approvalDates.add(readSavingsApproval(row,locale,dateFormat));
activationDates.add(readSavingsActivation(row,locale,dateFormat));
closedOnDate.add(readSavingsClosed(row,locale,dateFormat));
}
}
}
private ClosingOfSavingsAccounts readSavingsClosed(Row row,String locale,String dateFormat) {
LocalDate closedOnDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.CLOSED_ON_DATE, row);
Long onAccountClosureId = ImportHandlerUtils.readAsLong(FixedDepositConstants.ON_ACCOUNT_CLOSURE_ID, row);
Long toSavingsAccountId = ImportHandlerUtils.readAsLong(FixedDepositConstants.TO_SAVINGS_ACCOUNT_ID, row);
if (closedOnDate!=null)
return ClosingOfSavingsAccounts.importInstance(null, closedOnDate,onAccountClosureId,toSavingsAccountId, null,
row.getRowNum(),locale,dateFormat);
else
return null;
}
private SavingsActivation readSavingsActivation(Row row,String locale,String dateFormat) {
LocalDate activationDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.ACTIVATION_DATE_COL, row);
if (activationDate!=null)
return SavingsActivation.importInstance(activationDate, row.getRowNum(),locale,dateFormat);
else
return null;
}
private SavingsApproval readSavingsApproval(Row row,String locale,String dateFormat) {
LocalDate approvalDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.APPROVED_DATE_COL, row);
if (approvalDate!=null)
return SavingsApproval.importInstance(approvalDate, row.getRowNum(),locale,dateFormat);
else
return null;
}
private FixedDepositAccountData readSavings(Row row,String locale,String dateFormat) {
String productName = ImportHandlerUtils.readAsString(FixedDepositConstants.PRODUCT_COL, row);
Long productId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName);
String fieldOfficerName = ImportHandlerUtils.readAsString(FixedDepositConstants.FIELD_OFFICER_NAME_COL, row);
Long fieldOfficerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), fieldOfficerName);
LocalDate submittedOnDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.SUBMITTED_ON_DATE_COL, row);
String interestCompoundingPeriodType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, row);
Long interestCompoundingPeriodTypeId = null;
EnumOptionData interestCompoundingPeriodTypeEnum=null;
if (interestCompoundingPeriodType!=null) {
if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_DAILY))
interestCompoundingPeriodTypeId = 1L;
else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_MONTHLY))
interestCompoundingPeriodTypeId = 4L;
else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_QUARTERLY))
interestCompoundingPeriodTypeId = 5L;
else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_SEMI_ANNUALLY))
interestCompoundingPeriodTypeId = 6L;
else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY))
interestCompoundingPeriodTypeId = 7L;
interestCompoundingPeriodTypeEnum = new EnumOptionData(interestCompoundingPeriodTypeId, null, null);
}
String interestPostingPeriodType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_POSTING_PERIOD_COL, row);
Long interestPostingPeriodTypeId = null;
EnumOptionData interestPostingPeriodTypeEnum=null;
if (interestCompoundingPeriodType!=null) {
if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_MONTHLY))
interestPostingPeriodTypeId = 4L;
else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_QUARTERLY))
interestPostingPeriodTypeId = 5L;
else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY))
interestPostingPeriodTypeId = 7L;
else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_BIANUALLY))
interestPostingPeriodTypeId = 6L;
interestPostingPeriodTypeEnum = new EnumOptionData(interestPostingPeriodTypeId, null, null);
}
String interestCalculationType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_CALCULATION_COL, row);
EnumOptionData interestCalculationTypeEnum=null;
if (interestCalculationType!=null) {
Long interestCalculationTypeId = null;
if (interestCalculationType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAILY_BALANCE))
interestCalculationTypeId = 1L;
else if (interestCalculationType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_AVG_BALANCE))
interestCalculationTypeId = 2L;
interestCalculationTypeEnum = new EnumOptionData(interestCalculationTypeId, null, null);
}
String interestCalculationDaysInYearType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row);
Long interestCalculationDaysInYearTypeId = null;
EnumOptionData interestCalculationDaysInYearTypeEnum=null;
if (interestCalculationDaysInYearType!=null) {
if (interestCalculationDaysInYearType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_360))
interestCalculationDaysInYearTypeId = 360L;
else if (interestCalculationDaysInYearType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_365))
interestCalculationDaysInYearTypeId = 365L;
interestCalculationDaysInYearTypeEnum = new EnumOptionData(interestCalculationDaysInYearTypeId, null, null);
}
Integer lockinPeriodFrequency = ImportHandlerUtils.readAsInt(FixedDepositConstants.LOCKIN_PERIOD_COL, row);
String lockinPeriodFrequencyType = ImportHandlerUtils.readAsString(FixedDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, row);
Long lockinPeriodFrequencyTypeId =null;
EnumOptionData lockinPeriodFrequencyTypeEnum=null;
if (lockinPeriodFrequencyType!=null) {
if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_DAYS))
lockinPeriodFrequencyTypeId = 0L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_WEEKS))
lockinPeriodFrequencyTypeId = 1L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_MONTHS))
lockinPeriodFrequencyTypeId = 2L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_YEARS))
lockinPeriodFrequencyTypeId = 3L;
lockinPeriodFrequencyTypeEnum = new EnumOptionData(lockinPeriodFrequencyTypeId, null, null);
}
BigDecimal depositAmount=null;
if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.DEPOSIT_AMOUNT_COL, row)!=null) {
depositAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.DEPOSIT_AMOUNT_COL, row));
}
Integer depositPeriod = ImportHandlerUtils.readAsInt(FixedDepositConstants.DEPOSIT_PERIOD_COL, row);
String depositPeriodFrequency = ImportHandlerUtils.readAsString(FixedDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, row);
Long depositPeriodFrequencyId = null;
if (depositPeriodFrequency!=null) {
if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_DAYS))
depositPeriodFrequencyId = 0L;
else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_WEEKS))
depositPeriodFrequencyId = 1L;
else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_MONTHS))
depositPeriodFrequencyId = 2L;
else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_YEARS))
depositPeriodFrequencyId = 3L;
}
String externalId = ImportHandlerUtils.readAsString(FixedDepositConstants.EXTERNAL_ID_COL, row);
String clientName = ImportHandlerUtils.readAsString(FixedDepositConstants.CLIENT_NAME_COL, row);
List<SavingsAccountChargeData> charges = new ArrayList<SavingsAccountChargeData>();
String charge1 = ImportHandlerUtils.readAsString(FixedDepositConstants.CHARGE_ID_1, row);
String charge2 = ImportHandlerUtils.readAsString(FixedDepositConstants.CHARGE_ID_2, row);
if (charge1!=null) {
if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_1, row)!=null)
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_1, row),
BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_1, row)),
ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_1, row)));
}else {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_1, row),
null,
ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_1, row)));
}
if (charge2!=null) {
if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_2, row)!=null) {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_2, row),
BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_2, row)),
ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_2, row)));
}else {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_2, row),
null,
ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_2, row)));
}
}
String status = ImportHandlerUtils.readAsString(FixedDepositConstants.STATUS_COL, row);
statuses.add(status);
Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName);
return FixedDepositAccountData.importInstance (clientId, productId, fieldOfficerId, submittedOnDate,
interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum,
interestCalculationDaysInYearTypeEnum, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum,
depositAmount, depositPeriod, depositPeriodFrequencyId, externalId, charges,row.getRowNum(),locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
int progressLevel = 0;
Long savingsId=null;
for (int i = 0; i < savings.size(); i++) {
Row row = savingsSheet.getRow(savings.get(i).getRowIndex());
Cell statusCell = row.createCell(FixedDepositConstants.STATUS_COL);
Cell errorReportCell = row.createCell(FixedDepositConstants.FAILURE_REPORT_COL);
try {
String status = statuses.get(i);
progressLevel = getProgressLevel(status);
if (progressLevel == 0) {
CommandProcessingResult result= importSavings(i,dateFormat);
savingsId = result.getSavingsId();
progressLevel = 1;
} else
savingsId = ImportHandlerUtils.readAsLong(FixedDepositConstants.SAVINGS_ID_COL, savingsSheet.getRow(savings.get(i).getRowIndex()));
if (progressLevel <= 1) progressLevel = importSavingsApproval(savingsId, i,dateFormat);
if (progressLevel <= 2) progressLevel = importSavingsActivation(savingsId, i,dateFormat);
if (progressLevel <= 3) progressLevel = importSavingsClosing(savingsId, i,dateFormat);
successCount++;
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
writeFixedDepositErrorMessage(savingsId,errorMessage,progressLevel,statusCell,errorReportCell,row);
}
}
setReportHeaders(savingsSheet);
return Count.instance(successCount,errorCount);
}
private void writeFixedDepositErrorMessage(Long savingsId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){
String status = "";
if (progressLevel == 0)
status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED;
else if (progressLevel == 1)
status = TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED;
else if (progressLevel == 2) status = TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED;
statusCell.setCellValue(status);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED));
if (progressLevel > 0) row.createCell(FixedDepositConstants.SAVINGS_ID_COL).setCellValue(savingsId);
errorReportCell.setCellValue(errorMessage);
}
private int importSavingsClosing(Long savingsId, int i,String dateFormat) {
if(closedOnDate.get(i)!=null) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
String payload = gsonBuilder.create().toJson(closedOnDate.get(i));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.closeFixedDepositAccount(savingsId)//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 4;
}
private CommandProcessingResult importSavings(int i,String dateFormat) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataIdSerializer());
JsonObject savingsJsonob=gsonBuilder.create().toJsonTree(savings.get(i)).getAsJsonObject();
savingsJsonob.remove("withdrawalFeeForTransfers");
JsonArray chargesJsonAr=savingsJsonob.getAsJsonArray("charges");
for (int j=0;j<chargesJsonAr.size();j++){
JsonElement chargesJsonElement=chargesJsonAr.get(j);
JsonObject chargeJsonOb =chargesJsonElement.getAsJsonObject();
chargeJsonOb.remove("penalty");
}
if (chargesJsonAr.get(0).getAsJsonObject().toString().equals("{}"))
savingsJsonob.remove("charges");
String payload=savingsJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createFixedDepositAccount() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return result;
}
private int importSavingsApproval(Long savingsId, int i,String dateFormat) {
if(approvalDates.get(i)!=null) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
String payload = gsonBuilder.create().toJson(approvalDates.get(i));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.approveFixedDepositAccountApplication(savingsId)//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 2;
}
private int importSavingsActivation(Long savingsId, int i, String dateFormat) {
if(activationDates.get(i)!=null) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
String payload = gsonBuilder.create().toJson(activationDates.get(i));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.fixedDepositAccountActivation(savingsId)//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 3;
}
private int getProgressLevel(String status) {
if (status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED))
return 0;
else if (status.equals(TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED))
return 1;
else if (status.equals(TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED)) return 2;
return 0;
}
private void setReportHeaders(Sheet savingsSheet) {
savingsSheet.setColumnWidth(FixedDepositConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
Row rowHeader = savingsSheet.getRow(0);
ImportHandlerUtils.writeString(FixedDepositConstants.STATUS_COL, rowHeader, TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
ImportHandlerUtils.writeString(FixedDepositConstants.SAVINGS_ID_COL, rowHeader, TemplatePopulateImportConstants.SAVINGS_ID_COL_REPORT_HEADER);
ImportHandlerUtils.writeString(FixedDepositConstants.FAILURE_REPORT_COL, rowHeader, TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER);
}
}
@@ -0,0 +1,150 @@
/**
* 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.bulkimport.importhandler.fixeddeposits;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.SavingsAccountTransactionEnumValueSerialiser;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionData;
import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class FixedDepositTransactionImportHandler implements ImportHandler {
private Workbook workbook;
private List<SavingsAccountTransactionData> savingsTransactions;
private String savingsAccountId = "";
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public FixedDepositTransactionImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.savingsTransactions=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_TRANSACTION_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsTransactionSheet, TransactionConstants.AMOUNT_COL);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = savingsTransactionSheet.getRow(rowIndex);
if(ImportHandlerUtils.isNotImported(row, TransactionConstants.STATUS_COL))
savingsTransactions.add(readSavingsTransaction(row,locale,dateFormat));
}
}
private SavingsAccountTransactionData readSavingsTransaction(Row row,String locale,String dateFormat) {
String savingsAccountIdCheck=null;
if (ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row)!=null)
savingsAccountIdCheck = ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row).toString();
if(savingsAccountIdCheck!=null)
savingsAccountId = savingsAccountIdCheck;
String transactionType = ImportHandlerUtils.readAsString(TransactionConstants.TRANSACTION_TYPE_COL, row);
SavingsAccountTransactionEnumData savingsAccountTransactionEnumData=new SavingsAccountTransactionEnumData(null,null,transactionType);
BigDecimal amount=null;
if (ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)!=null)
amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row));
LocalDate transactionDate = ImportHandlerUtils.readAsDate(TransactionConstants.TRANSACTION_DATE_COL, row);
String paymentType = ImportHandlerUtils.readAsString(TransactionConstants.PAYMENT_TYPE_COL, row);
Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), paymentType);
String accountNumber = ImportHandlerUtils.readAsString(TransactionConstants.ACCOUNT_NO_COL, row);
String checkNumber = ImportHandlerUtils.readAsString(TransactionConstants.CHECK_NO_COL, row);
String routingCode = ImportHandlerUtils.readAsString(TransactionConstants.ROUTING_CODE_COL, row);
String receiptNumber = ImportHandlerUtils.readAsString(TransactionConstants.RECEIPT_NO_COL, row);
String bankNumber = ImportHandlerUtils.readAsString(TransactionConstants.BANK_NO_COL, row);
return SavingsAccountTransactionData.importInstance(amount, transactionDate, paymentTypeId, accountNumber,
checkNumber, routingCode, receiptNumber, bankNumber, Long.parseLong(savingsAccountId), savingsAccountTransactionEnumData, row.getRowNum(),locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_TRANSACTION_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(SavingsAccountTransactionEnumData.class
,new SavingsAccountTransactionEnumValueSerialiser());
for (SavingsAccountTransactionData transaction : savingsTransactions) {
try {
JsonObject savingsTransactionJsonob=gsonBuilder.create().toJsonTree(transaction).getAsJsonObject();
savingsTransactionJsonob.remove("transactionType");
savingsTransactionJsonob.remove("reversed");
savingsTransactionJsonob.remove("interestedPostedAsOn");
String payload= savingsTransactionJsonob.toString();
CommandWrapper commandRequest=null;
if (transaction.getTransactionType().getValue().equals("Withdrawal")) {
commandRequest = new CommandWrapperBuilder() //
.fixedDepositAccountWithdrawal(transaction.getSavingsAccountId()) //
.withJson(payload) //
.build(); //
}else if (transaction.getTransactionType().getValue().equals("Deposit")){
commandRequest = new CommandWrapperBuilder() //
.fixedDepositAccountDeposit(transaction.getSavingsAccountId()) //
.withJson(payload) //
.build();
}
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(TransactionConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL);
}
}
savingsTransactionSheet.setColumnWidth(TransactionConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(TransactionConstants.STATUS_COL, savingsTransactionSheet.getRow(TransactionConstants.STATUS_COL), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,257 @@
/**
* 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.bulkimport.importhandler.group;
import com.google.common.reflect.TypeToken;
import com.google.gson.GsonBuilder;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.GroupConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.ClientIdSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataValueSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.calendar.data.CalendarData;
import org.apache.fineract.portfolio.client.data.ClientData;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Service
public class GroupImportHandler implements ImportHandler {
private List<GroupGeneralData> groups;
private List<CalendarData> meetings;
private Workbook workbook;
private List<String>statuses;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public GroupImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
groups=new ArrayList<>();
meetings=new ArrayList<>();
statuses=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(String locale, String dateFormat) {
Sheet groupsSheet = workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(groupsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = groupsSheet.getRow(rowIndex);
if(ImportHandlerUtils.isNotImported(row, GroupConstants.STATUS_COL)) {
groups.add(readGroup(row,locale,dateFormat));
meetings.add(readMeeting(row,locale,dateFormat));
}
}
}
private CalendarData readMeeting(Row row,String locale,String dateFormat) {
LocalDate meetingStartDate = ImportHandlerUtils.readAsDate(GroupConstants.MEETING_START_DATE_COL, row);
Boolean isRepeating = ImportHandlerUtils.readAsBoolean(GroupConstants.IS_REPEATING_COL, row);
String frequency = ImportHandlerUtils.readAsString(GroupConstants.FREQUENCY_COL, row);
EnumOptionData frequencyEnum=new EnumOptionData(null,null,ImportHandlerUtils.getFrequencyId(frequency));
Integer interval = ImportHandlerUtils.readAsInt(GroupConstants.INTERVAL_COL, row);
String repeatsOnDay = ImportHandlerUtils.readAsString(GroupConstants.REPEATS_ON_DAY_COL, row);
EnumOptionData repeatsOnDayEnum=new EnumOptionData(null,null,ImportHandlerUtils.getRepeatsOnDayId(repeatsOnDay));
if(meetingStartDate==null)
return null;
else {
if(repeatsOnDay==null)
return CalendarData.importInstanceNoRepeatsOnDay(meetingStartDate, isRepeating, frequencyEnum, interval, row.getRowNum(),locale,dateFormat);
else
return CalendarData.importInstanceWithRepeatsOnDay(meetingStartDate, isRepeating, frequencyEnum, interval, repeatsOnDayEnum, row.getRowNum(),locale,dateFormat);
}
}
private GroupGeneralData readGroup(Row row,String locale,String dateFormat) {
String status = ImportHandlerUtils.readAsString(GroupConstants.STATUS_COL, row);
String officeName = ImportHandlerUtils.readAsString(GroupConstants.OFFICE_NAME_COL, row);
Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName);
String staffName = ImportHandlerUtils.readAsString(GroupConstants.STAFF_NAME_COL, row);
Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName);
String centerName = ImportHandlerUtils.readAsString(GroupConstants.CENTER_NAME_COL, row);
Long centerId=null;
if(centerName!=null)
centerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME), centerName);
String externalId = ImportHandlerUtils.readAsString(GroupConstants.EXTERNAL_ID_COL, row);
Boolean active = ImportHandlerUtils.readAsBoolean(GroupConstants.ACTIVE_COL, row);
LocalDate submittedOnDate=ImportHandlerUtils.readAsDate(GroupConstants.SUBMITTED_ON_DATE_COL,row);
LocalDate activationDate=null;
if(active) {
activationDate = ImportHandlerUtils.readAsDate(GroupConstants.ACTIVATION_DATE_COL, row);
}else {
activationDate=submittedOnDate;
}
String groupName = ImportHandlerUtils.readAsString(GroupConstants.NAME_COL, row);
if (groupName == null || groupName.equals("")) {
throw new IllegalArgumentException("Name is blank");
}
List<ClientData> clientMembers = new ArrayList<>();
for (int cellNo = GroupConstants.CLIENT_NAMES_STARTING_COL; cellNo <GroupConstants.CLIENT_NAMES_ENDING_COL; cellNo++) {
String clientName = ImportHandlerUtils.readAsString(cellNo, row);
if (clientName==null)
break;
Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName);
ClientData clientData = new ClientData(clientId);
if (!containsClientId(clientMembers,clientId)) {
clientMembers.add(clientData);
}
}
statuses.add(status);
return GroupGeneralData.importInstance(groupName, clientMembers, activationDate, submittedOnDate,active, externalId,
officeId, staffId, centerId, row.getRowNum(),locale,dateFormat);
}
private boolean containsClientId(List<ClientData> clientMembers,Long clientId){
for (ClientData client: clientMembers) {
if (client.getId()==clientId){
return true;
}
}
return false;
}
public Count importEntity(String dateFormat) {
Sheet groupSheet = workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME);
int successCount=0;
int errorCount=0;
int progressLevel = 0;
String groupId = "";
String errorMessage="";
for (int i = 0; i < groups.size(); i++) {
Row row = groupSheet.getRow(groups.get(i).getRowIndex());
Cell errorReportCell = row.createCell(GroupConstants.FAILURE_COL);
Cell statusCell = row.createCell(GroupConstants.STATUS_COL);
CommandProcessingResult result=null;
try {
String status = statuses.get(i);
progressLevel = getProgressLevel(status);
if(progressLevel == 0)
{
result = importGroup(i,dateFormat);
groupId = result.getGroupId().toString();
progressLevel = 1;
} else
groupId = ImportHandlerUtils.readAsInt(GroupConstants.GROUP_ID_COL, groupSheet.getRow(groups.get(i).getRowIndex())).toString();
if(meetings.get(i) != null && groups.get(i).getCenterId() == null)
progressLevel = importGroupMeeting(result, i,dateFormat);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
writeGroupErrorMessage(groupId,errorMessage,progressLevel,statusCell,errorReportCell,row);
}
}
setReportHeaders(groupSheet);
return Count.instance(successCount,errorCount);
}
private void writeGroupErrorMessage(String groupId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){
String status = "";
if(progressLevel == 0)
status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED;
else if(progressLevel == 1)
status =TemplatePopulateImportConstants.STATUS_MEETING_FAILED ;
statusCell.setCellValue(status);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED));
if(progressLevel>0)
row.createCell(GroupConstants.GROUP_ID_COL).setCellValue(Integer.parseInt(groupId));
errorReportCell.setCellValue(errorMessage);
}
private void setReportHeaders(Sheet groupSheet) {
ImportHandlerUtils.writeString(GroupConstants.STATUS_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
ImportHandlerUtils.writeString(GroupConstants.GROUP_ID_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.GROUP_ID_COL_REPORT_HEADER);
ImportHandlerUtils.writeString(GroupConstants.FAILURE_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER);
}
private Integer importGroupMeeting(CommandProcessingResult result, int rowIndex, String dateFormat) {
CalendarData calendarData=meetings.get(rowIndex);
calendarData.setTitle("group_" + result.getGroupId().toString() + "_CollectionMeeting");
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataValueSerializer());
String payload = gsonBuilder.create().toJson(calendarData);
CommandWrapper commandWrapper=new CommandWrapper(result.getOfficeId(),result.getGroupId(),
result.getClientId(),result.getLoanId(),result.getSavingsId(),null,
null,null,null,null,payload,result.getTransactionId(),
result.getProductId(),null,null,null);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createCalendar(commandWrapper,TemplatePopulateImportConstants.CENTER_ENTITY_TYPE,result.getGroupId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult meetingresult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return 2;
}
private CommandProcessingResult importGroup(int rowIndex, String dateFormat) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
Type clientCollectionType = new TypeToken<Collection<ClientData>>() {}.getType();
gsonBuilder.registerTypeAdapter(clientCollectionType,new ClientIdSerializer());
String payload= gsonBuilder.create().toJson(groups.get(rowIndex));;
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createGroup() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return result;
}
private int getProgressLevel(String status) {
if(status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED))
return 0;
else if(status.equals(TemplatePopulateImportConstants.STATUS_MEETING_FAILED))
return 1;
return 0;
}
}
@@ -0,0 +1,151 @@
/**
* 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.bulkimport.importhandler.guarantor;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.GuarantorConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.loanaccount.guarantor.data.GuarantorData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class GuarantorImportHandler implements ImportHandler {
private Workbook workbook;
private List<GuarantorData> guarantors;
private Long loanAccountId ;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public GuarantorImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.guarantors=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
Sheet addGuarantorSheet = workbook.getSheet(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(addGuarantorSheet, GuarantorConstants.LOAN_ACCOUNT_NO_COL);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = addGuarantorSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, GuarantorConstants.STATUS_COL))
guarantors.add(ReadGuarantor(row,locale,dateFormat));
}
}
private GuarantorData ReadGuarantor(Row row,String locale,String dateFormat) {
String loanaccountInfo=ImportHandlerUtils.readAsString(GuarantorConstants.LOAN_ACCOUNT_NO_COL, row);
if (loanaccountInfo!=null){
String loanAccountAr[]=loanaccountInfo.split("-");
loanAccountId=Long.parseLong(loanAccountAr[0]);
}
String guarantorType = ImportHandlerUtils.readAsString(GuarantorConstants.GUARANTO_TYPE_COL, row);
Integer guarantorTypeId = null;
if (guarantorType!=null) {
if (guarantorType.equalsIgnoreCase(TemplatePopulateImportConstants.GUARANTOR_INTERNAL))
guarantorTypeId = 1;
else if (guarantorType.equalsIgnoreCase(TemplatePopulateImportConstants.GUARANTOR_EXTERNAL))
guarantorTypeId = 3;
}
String clientName = ImportHandlerUtils.readAsString(GuarantorConstants.ENTITY_ID_COL, row);
Long entityId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName);
String clientRelationshipTypeInfo=ImportHandlerUtils.readAsString(GuarantorConstants.CLIENT_RELATIONSHIP_TYPE_COL, row);
Integer clientRelationshipTypeId=null;
if (clientRelationshipTypeInfo!=null){
String clientRelationshipTypeAr[]=clientRelationshipTypeInfo.split("-");
clientRelationshipTypeId=Integer.parseInt(clientRelationshipTypeAr[1]);
}
String firstname = ImportHandlerUtils.readAsString(GuarantorConstants.FIRST_NAME_COL, row);
String lastname = ImportHandlerUtils.readAsString(GuarantorConstants.LAST_NAME_COL, row);
String addressLine1 = ImportHandlerUtils.readAsString(GuarantorConstants.ADDRESS_LINE_1_COL, row);
String addressLine2 = ImportHandlerUtils.readAsString(GuarantorConstants.ADDRESS_LINE_2_COL, row);
String city = ImportHandlerUtils.readAsString(GuarantorConstants.CITY_COL, row);
LocalDate dob = ImportHandlerUtils.readAsDate(GuarantorConstants.DOB_COL, row);
String zip = ImportHandlerUtils.readAsString(GuarantorConstants.ZIP_COL, row);
Integer savingsId = ImportHandlerUtils.readAsInt(GuarantorConstants.SAVINGS_ID_COL, row);
BigDecimal amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(GuarantorConstants.AMOUNT, row));
return GuarantorData.importInstance(guarantorTypeId,clientRelationshipTypeId,entityId,firstname,
lastname,addressLine1, addressLine2,city,dob,zip,savingsId,amount, row.getRowNum(), loanAccountId,locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet addGuarantorSheet = workbook.getSheet(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder=new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
for (GuarantorData guarantor : guarantors) {
try {
JsonObject guarantorJsonob=gsonBuilder.create().toJsonTree(guarantor).getAsJsonObject();
guarantorJsonob.remove("status");
String payload = guarantorJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createGuarantor(guarantor.getAccountId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = addGuarantorSheet.getRow(guarantor.getRowIndex()).createCell(GuarantorConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(addGuarantorSheet,guarantor.getRowIndex(),errorMessage,GuarantorConstants.STATUS_COL);
}
}
addGuarantorSheet.setColumnWidth(GuarantorConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(GuarantorConstants.STATUS_COL, addGuarantorSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,38 @@
/**
* 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.bulkimport.importhandler.helper;
import com.google.gson.*;
import org.apache.fineract.portfolio.client.data.ClientData;
import java.lang.reflect.Type;
import java.util.Collection;
public class ClientIdSerializer implements JsonSerializer<Collection<ClientData>> {
@Override
public JsonElement serialize(Collection<ClientData> src, Type typeOfSrc, JsonSerializationContext context) {
JsonArray clientIdJsonArray=new JsonArray();
for (ClientData client:src) {
JsonElement clientIdElment=new JsonPrimitive(client.id().toString());
clientIdJsonArray.add(clientIdElment);
}
return clientIdJsonArray;
}
}
@@ -0,0 +1,34 @@
/**
* 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.bulkimport.importhandler.helper;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import java.lang.reflect.Type;
public class CodeValueDataIdSerializer implements JsonSerializer<CodeValueData> {
@Override
public JsonElement serialize(CodeValueData src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.getId());
}
}
@@ -0,0 +1,34 @@
/**
* 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.bulkimport.importhandler.helper;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import java.lang.reflect.Type;
public class CurrencyDateCodeSerializer implements JsonSerializer<CurrencyData>{
@Override
public JsonElement serialize(CurrencyData src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.code());
}
}
@@ -0,0 +1,41 @@
/**
* 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.bulkimport.importhandler.helper;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.joda.time.LocalDate;
import java.lang.reflect.Type;
public class DateSerializer implements JsonSerializer<LocalDate> {
private final String dateFormat;
public DateSerializer(String dateFormat) {
this.dateFormat = dateFormat;
}
@Override
public JsonElement serialize(LocalDate src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.toString(dateFormat));
}
}
@@ -0,0 +1,34 @@
/**
* 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.bulkimport.importhandler.helper;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import java.lang.reflect.Type;
public class EnumOptionDataIdSerializer implements JsonSerializer<EnumOptionData> {
@Override
public JsonElement serialize(EnumOptionData src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.getId());
}
}
@@ -0,0 +1,34 @@
/**
* 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.bulkimport.importhandler.helper;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import java.lang.reflect.Type;
public class EnumOptionDataValueSerializer implements JsonSerializer<EnumOptionData> {
@Override
public JsonElement serialize(EnumOptionData src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.getValue());
}
}
@@ -0,0 +1,37 @@
/**
* 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.bulkimport.importhandler.helper;
import com.google.gson.*;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import java.lang.reflect.Type;
import java.util.Collection;
public class GroupIdSerializer implements JsonSerializer<Collection<GroupGeneralData>> {
@Override
public JsonElement serialize(Collection<GroupGeneralData> src, Type typeOfSrc, JsonSerializationContext context) {
JsonArray groupIdJsonArray=new JsonArray();
for (GroupGeneralData group:src) {
JsonElement groupIdElement=new JsonPrimitive(group.getId().toString());
groupIdJsonArray.add(groupIdElement);
}
return groupIdJsonArray;
}
}
@@ -0,0 +1,35 @@
/**
* 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.bulkimport.importhandler.helper;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData;
import java.lang.reflect.Type;
public class SavingsAccountTransactionEnumValueSerialiser implements JsonSerializer<SavingsAccountTransactionEnumData> {
@Override
public JsonElement serialize(SavingsAccountTransactionEnumData src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.getValue());
}
}
@@ -0,0 +1,226 @@
/**
* 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.bulkimport.importhandler.journalentry;
import com.google.gson.GsonBuilder;
import org.apache.fineract.accounting.journalentry.data.CreditDebit;
import org.apache.fineract.accounting.journalentry.data.JournalEntryData;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.ChartOfAcountsConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.JournalEntryConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.CurrencyDateCodeSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class JournalEntriesImportHandler implements ImportHandler {
private Workbook workbook;
private List<JournalEntryData> gltransaction;
private LocalDate transactionDate;
List<CreditDebit> credits = new ArrayList<>();
List<CreditDebit> debits = new ArrayList<>();
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public JournalEntriesImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
gltransaction=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
String currentTransactionId = null;
String prevTransactionId = null;
JournalEntryData journalEntry = null;
Sheet addJournalEntriesSheet = workbook.getSheet(TemplatePopulateImportConstants.JOURNAL_ENTRY_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(addJournalEntriesSheet, 4);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = addJournalEntriesSheet.getRow(rowIndex);
currentTransactionId = ImportHandlerUtils.readAsString(JournalEntryConstants.TRANSACTION_ID_COL, row);
if (currentTransactionId.equals(prevTransactionId)) {
if (journalEntry != null) {
String creditGLAcct = ImportHandlerUtils.readAsString(
JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, row);
Long glAccountIdCredit = ImportHandlerUtils.getIdByName(
workbook.getSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME), creditGLAcct);
String debitGLAcct = ImportHandlerUtils.readAsString(
JournalEntryConstants. GL_ACCOUNT_ID_DEBIT_COL, row);
Long glAccountIdDebit = ImportHandlerUtils.getIdByName(
workbook.getSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME), debitGLAcct);
BigDecimal creditAmt=null;
if (ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_CREDIT_COL, row)!=null)
creditAmt = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_CREDIT_COL, row));
BigDecimal debitAmount=null;
if (ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_DEBIT_COL, row)!=null)
debitAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_DEBIT_COL, row));
if (creditGLAcct!=null) {
CreditDebit credit = new CreditDebit(
glAccountIdCredit, creditAmt);
journalEntry.addCredits(credit);
}
if (debitGLAcct!=null) {
CreditDebit debit = new CreditDebit(
glAccountIdDebit, debitAmount);
journalEntry.addDebits(debit);
}
}
} else {
if (journalEntry != null) {
gltransaction.add(journalEntry);
journalEntry = null;
}
journalEntry = readAddJournalEntries(row,locale,dateFormat);
}
prevTransactionId = currentTransactionId;
}
// Adding last JE
gltransaction.add(journalEntry);
}
private JournalEntryData readAddJournalEntries(Row row,String locale,String dateFormat) {
LocalDate transactionDateCheck = ImportHandlerUtils.readAsDate(JournalEntryConstants.TRANSACION_ON_DATE_COL, row);
if (transactionDateCheck!=null)
transactionDate = transactionDateCheck;
String officeName = ImportHandlerUtils.readAsString(JournalEntryConstants.OFFICE_NAME_COL, row);
Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName);
String paymentType = ImportHandlerUtils.readAsString(JournalEntryConstants.PAYMENT_TYPE_ID_COL, row);
Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME),
paymentType);
String currencyName = ImportHandlerUtils.readAsString(JournalEntryConstants.CURRENCY_NAME_COL, row);
String currencyCode = ImportHandlerUtils.getCodeByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME),
currencyName).toString();
String glAccountNameCredit = ImportHandlerUtils.readAsString(JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, row);
Long glAccountIdCredit = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME),
glAccountNameCredit);
String glAccountNameDebit = ImportHandlerUtils.readAsString(JournalEntryConstants.GL_ACCOUNT_ID_DEBIT_COL, row);
Long glAccountIdDebit = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME),
glAccountNameDebit);
credits = new ArrayList<>();
debits = new ArrayList<>();
// String credit = readAsString(JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, row);
// String debit = readAsString(JournalEntryConstants.GL_ACCOUNT_ID_DEBIT_COL, row);
if (glAccountNameCredit!=null) {
if (ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_CREDIT_COL, row) != null){
credits.add(new CreditDebit(glAccountIdCredit, BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(
JournalEntryConstants.AMOUNT_CREDIT_COL, row))));
}else {
credits.add(new CreditDebit(glAccountIdCredit,null));
}
}
if (glAccountNameDebit!=null) {
if (ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_DEBIT_COL, row)!=null) {
debits.add(new CreditDebit(glAccountIdDebit, BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(
JournalEntryConstants.AMOUNT_DEBIT_COL, row))));
}else {
debits.add(new CreditDebit(glAccountIdDebit, null));
}
}
String accountNo=ImportHandlerUtils.readAsString(JournalEntryConstants.ACCOUNT_NO_COL,row);
String chequeNo=ImportHandlerUtils.readAsString(JournalEntryConstants.CHECK_NO_COL,row);
String routingCode=ImportHandlerUtils.readAsString(JournalEntryConstants.ROUTING_CODE_COL,row);
String receiptNo=ImportHandlerUtils.readAsString(JournalEntryConstants.RECEIPT_NO_COL,row);
String bankNo=ImportHandlerUtils.readAsString(JournalEntryConstants.BANK_NO_COL,row);
String comments=ImportHandlerUtils.readAsString(JournalEntryConstants.COMMENTS_COL,row);
return JournalEntryData.importInstance(officeId, transactionDate, currencyCode,
paymentTypeId, row.getRowNum(), credits, debits,accountNo,chequeNo,routingCode,receiptNo,bankNo,comments,locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet addJournalEntriesSheet = workbook.getSheet(TemplatePopulateImportConstants.JOURNAL_ENTRY_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(CurrencyData.class,new CurrencyDateCodeSerializer());
for (JournalEntryData transaction : gltransaction) {
try {
String payload =gsonBuilder.create().toJson(transaction);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createJournalEntry() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = addJournalEntriesSheet.getRow(
transaction.getRowIndex()).createCell(JournalEntryConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook,
IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(addJournalEntriesSheet,transaction.getRowIndex(),errorMessage, JournalEntryConstants.STATUS_COL);
}
}
addJournalEntriesSheet.setColumnWidth(JournalEntryConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(JournalEntryConstants.STATUS_COL, addJournalEntriesSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,464 @@
/**
* 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.bulkimport.importhandler.loan;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataValueSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.loanaccount.data.*;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@Service
public class LoanImportHandler implements ImportHandler {
private Workbook workbook;
private List<LoanAccountData> loans;
private List<LoanApprovalData> approvalDates;
private List<LoanTransactionData> loanRepayments;
private List<DisbursementData> disbursalDates;
private List<String> statuses;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public LoanImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.loans = new ArrayList<>();
this.approvalDates = new ArrayList<>();
this.loanRepayments = new ArrayList<>();
this.disbursalDates = new ArrayList<>();
this.statuses=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(loanSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = loanSheet.getRow(rowIndex);
if ( ImportHandlerUtils.isNotImported(row, LoanConstants.STATUS_COL)) {
loans.add(readLoan(row,locale,dateFormat));
approvalDates.add(readLoanApproval(row,locale,dateFormat));
disbursalDates.add(readDisbursalData(row,locale,dateFormat));
loanRepayments.add(readLoanRepayment(row,locale,dateFormat));
}
}
}
private LoanTransactionData readLoanRepayment(Row row,String locale,String dateFormat) {
BigDecimal repaymentAmount=null;
if (ImportHandlerUtils.readAsDouble(LoanConstants.TOTAL_AMOUNT_REPAID_COL, row)!=null)
repaymentAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.TOTAL_AMOUNT_REPAID_COL, row));
LocalDate lastRepaymentDate = ImportHandlerUtils.readAsDate(LoanConstants.LAST_REPAYMENT_DATE_COL, row);
String repaymentType = ImportHandlerUtils.readAsString(LoanConstants.REPAYMENT_TYPE_COL, row);
Long repaymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), repaymentType);
if (repaymentAmount!=null&&lastRepaymentDate!=null&&repaymentType!=null&&repaymentTypeId!=null)
return LoanTransactionData.importInstance(repaymentAmount, lastRepaymentDate, repaymentTypeId, row.getRowNum(),locale,dateFormat);
else
return null;
}
private DisbursementData readDisbursalData(Row row,String locale,String dateFormat) {
LocalDate disbursedDate = ImportHandlerUtils.readAsDate(LoanConstants.DISBURSED_DATE_COL, row);
String linkAccountId=null;
if ( ImportHandlerUtils.readAsLong(LoanConstants.LINK_ACCOUNT_ID, row)!=null)
linkAccountId = ImportHandlerUtils.readAsLong(LoanConstants.LINK_ACCOUNT_ID, row).toString();
if (disbursedDate!=null) {
return DisbursementData.importInstance(disbursedDate,linkAccountId,row.getRowNum(),locale,dateFormat);
}
return null;
}
private LoanApprovalData readLoanApproval(Row row,String locale,String dateFormat) {
LocalDate approvedDate = ImportHandlerUtils.readAsDate(LoanConstants.APPROVED_DATE_COL, row);
if (approvedDate!=null)
return LoanApprovalData.importInstance(approvedDate, row.getRowNum(),locale,dateFormat);
else
return null;
}
private LoanAccountData readLoan(Row row,String locale,String dateFormat) {
String externalId = ImportHandlerUtils.readAsString(LoanConstants.EXTERNAL_ID_COL, row);
String status = ImportHandlerUtils.readAsString(LoanConstants.STATUS_COL, row);
String productName = ImportHandlerUtils.readAsString(LoanConstants.PRODUCT_COL, row);
Long productId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName);
String loanOfficerName = ImportHandlerUtils.readAsString(LoanConstants.LOAN_OFFICER_NAME_COL, row);
Long loanOfficerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), loanOfficerName);
LocalDate submittedOnDate = ImportHandlerUtils.readAsDate(LoanConstants.SUBMITTED_ON_DATE_COL, row);
String fundName = ImportHandlerUtils.readAsString(LoanConstants.FUND_NAME_COL, row);
Long fundId;
if (fundName == null)
fundId = null;
else
fundId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), fundName);
BigDecimal principal = null;
if ( ImportHandlerUtils.readAsDouble(LoanConstants.PRINCIPAL_COL, row) != null)
principal = BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.PRINCIPAL_COL, row));
Integer numberOfRepayments = ImportHandlerUtils.readAsInt(LoanConstants.NO_OF_REPAYMENTS_COL, row);
Integer repaidEvery = ImportHandlerUtils.readAsInt(LoanConstants.REPAID_EVERY_COL, row);
String repaidEveryFrequency = ImportHandlerUtils.readAsString(LoanConstants.REPAID_EVERY_FREQUENCY_COL, row);
String repaidEveryFrequencyId = "";
EnumOptionData repaidEveryFrequencyEnums = null;
if (repaidEveryFrequency != null) {
if (repaidEveryFrequency.equalsIgnoreCase("Days"))
repaidEveryFrequencyId = "0";
else if (repaidEveryFrequency.equalsIgnoreCase("Weeks"))
repaidEveryFrequencyId = "1";
else if (repaidEveryFrequency.equalsIgnoreCase("Months")) repaidEveryFrequencyId = "2";
repaidEveryFrequencyEnums = new EnumOptionData(null, null, repaidEveryFrequencyId);
}
Integer loanTerm = ImportHandlerUtils.readAsInt(LoanConstants.LOAN_TERM_COL, row);
String loanTermFrequency = ImportHandlerUtils.readAsString(LoanConstants.LOAN_TERM_FREQUENCY_COL, row);
EnumOptionData loanTermFrequencyEnum = null;
if (loanTermFrequency != null) {
String loanTermFrequencyId = "";
if (loanTermFrequency.equalsIgnoreCase("Days"))
loanTermFrequencyId = "0";
else if (loanTermFrequency.equalsIgnoreCase("Weeks"))
loanTermFrequencyId = "1";
else if (loanTermFrequency.equalsIgnoreCase("Months"))
loanTermFrequencyId = "2";
loanTermFrequencyEnum = new EnumOptionData(null, null, loanTermFrequencyId);
}
BigDecimal nominalInterestRate = null;
if ( ImportHandlerUtils.readAsDouble(LoanConstants.NOMINAL_INTEREST_RATE_COL, row) != null)
nominalInterestRate = BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.NOMINAL_INTEREST_RATE_COL, row));
String amortization = ImportHandlerUtils.readAsString(LoanConstants.AMORTIZATION_COL, row);
String amortizationId = "";
EnumOptionData amortizationEnumOption = null;
if (amortization != null) {
if (amortization.equalsIgnoreCase("Equal principal payments"))
amortizationId = "0";
else if (amortization.equalsIgnoreCase("Equal installments")) amortizationId = "1";
amortizationEnumOption = new EnumOptionData(null, null, amortizationId);
}
String interestMethod = ImportHandlerUtils.readAsString(LoanConstants.INTEREST_METHOD_COL, row);
String interestMethodId = "";
EnumOptionData interestMethodEnum = null;
if (interestMethod != null) {
if (interestMethod.equalsIgnoreCase("Flat"))
interestMethodId = "1";
else if (interestMethod.equalsIgnoreCase("Declining Balance")) interestMethodId = "0";
interestMethodEnum = new EnumOptionData(null, null, interestMethodId);
}
String interestCalculationPeriod = ImportHandlerUtils.readAsString(LoanConstants.INTEREST_CALCULATION_PERIOD_COL, row);
String interestCalculationPeriodId = "";
EnumOptionData interestCalculationPeriodEnum = null;
if (interestCalculationPeriod != null) {
if (interestCalculationPeriod.equalsIgnoreCase("Daily"))
interestCalculationPeriodId = "0";
else if (interestCalculationPeriod.equalsIgnoreCase("Same as repayment period"))
interestCalculationPeriodId = "1";
interestCalculationPeriodEnum = new EnumOptionData(null, null, interestCalculationPeriodId);
}
BigDecimal arrearsTolerance = null;
if ( ImportHandlerUtils.readAsDouble(LoanConstants.ARREARS_TOLERANCE_COL, row) != null)
arrearsTolerance = BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.ARREARS_TOLERANCE_COL, row));
String repaymentStrategy = ImportHandlerUtils.readAsString(LoanConstants.REPAYMENT_STRATEGY_COL, row);
Long repaymentStrategyId = null;
if (repaymentStrategy!=null) {
if (repaymentStrategy.equalsIgnoreCase("Penalties, Fees, Interest, Principal order"))
repaymentStrategyId = 1L;
else if (repaymentStrategy.equalsIgnoreCase("HeavensFamily Unique"))
repaymentStrategyId = 2L;
else if (repaymentStrategy.equalsIgnoreCase("Creocore Unique"))
repaymentStrategyId = 3L;
else if (repaymentStrategy.equalsIgnoreCase("Overdue/Due Fee/Int,Principal"))
repaymentStrategyId = 4L;
else if (repaymentStrategy.equalsIgnoreCase("Principal, Interest, Penalties, Fees Order"))
repaymentStrategyId = 5L;
else if (repaymentStrategy.equalsIgnoreCase("Interest, Principal, Penalties, Fees Order"))
repaymentStrategyId = 6L;
else if (repaymentStrategy.equalsIgnoreCase("Early Repayment Strategy"))
repaymentStrategyId = 7L;
}
Integer graceOnPrincipalPayment = ImportHandlerUtils.readAsInt(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL, row);
Integer graceOnInterestPayment = ImportHandlerUtils.readAsInt(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL, row);
Integer graceOnInterestCharged = ImportHandlerUtils.readAsInt(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL, row);
LocalDate interestChargedFromDate = ImportHandlerUtils.readAsDate(LoanConstants.INTEREST_CHARGED_FROM_COL, row);
LocalDate firstRepaymentOnDate = ImportHandlerUtils.readAsDate(LoanConstants.FIRST_REPAYMENT_COL, row);
String loanType=null;
EnumOptionData loanTypeEnumOption=null;
if ( ImportHandlerUtils.readAsString(LoanConstants.LOAN_TYPE_COL, row)!=null) {
loanType = ImportHandlerUtils.readAsString(LoanConstants.LOAN_TYPE_COL, row).toLowerCase(Locale.ENGLISH);
loanTypeEnumOption = new EnumOptionData(null, null, loanType);
}
String clientOrGroupName = ImportHandlerUtils.readAsString(LoanConstants.CLIENT_NAME_COL, row);
List<LoanChargeData> charges = new ArrayList<>();
Long charge1 = ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_1, row);
Long charge2 = ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_2, row);
Long groupId = ImportHandlerUtils.readAsLong(LoanConstants.GROUP_ID, row);
String linkAccountId = ImportHandlerUtils.readAsString(LoanConstants.LINK_ACCOUNT_ID, row);
if (charge1!=null) {
if ( ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_1, row)!=null) {
charges.add(new LoanChargeData( ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_1, row),
ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_1, row),
BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_1, row))));
}else {
charges.add(new LoanChargeData( ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_1, row),
ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_1, row),null));
}
}
if (charge2!=null) {
if ( ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_2, row)!=null){
charges.add(new LoanChargeData( ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_2, row),
ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_2, row),
BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_2, row))));
}else {
charges.add(new LoanChargeData( ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_2, row),
ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_2, row),
null));
}
}
statuses.add(status);
if (loanType!=null) {
if (loanType.equals("individual")) {
Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientOrGroupName);
return LoanAccountData.importInstanceIndividual(loanTypeEnumOption, clientId, productId, loanOfficerId, submittedOnDate, fundId,
principal, numberOfRepayments,
repaidEvery, repaidEveryFrequencyEnums, loanTerm, loanTermFrequencyEnum, nominalInterestRate, submittedOnDate,
amortizationEnumOption, interestMethodEnum, interestCalculationPeriodEnum, arrearsTolerance, repaymentStrategyId,
graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged, interestChargedFromDate, firstRepaymentOnDate,
row.getRowNum(), externalId, null, charges, linkAccountId,locale,dateFormat);
} else if (loanType.equals("jlg")) {
Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientOrGroupName);
return LoanAccountData.importInstanceIndividual(loanTypeEnumOption, clientId, productId, loanOfficerId, submittedOnDate, fundId,
principal, numberOfRepayments,
repaidEvery, repaidEveryFrequencyEnums, loanTerm, loanTermFrequencyEnum, nominalInterestRate, submittedOnDate,
amortizationEnumOption, interestMethodEnum, interestCalculationPeriodEnum, arrearsTolerance, repaymentStrategyId,
graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged, interestChargedFromDate, firstRepaymentOnDate,
row.getRowNum(), externalId, groupId, charges, linkAccountId,locale,dateFormat);
} else {
Long groupIdforGroupLoan = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME), clientOrGroupName);
return LoanAccountData.importInstanceGroup(loanTypeEnumOption, groupIdforGroupLoan, productId, loanOfficerId, submittedOnDate, fundId,
principal, numberOfRepayments,
repaidEvery, repaidEveryFrequencyEnums, loanTerm, loanTermFrequencyEnum, nominalInterestRate,
amortizationEnumOption, interestMethodEnum, interestCalculationPeriodEnum, arrearsTolerance,
repaymentStrategyId, graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged,
interestChargedFromDate, firstRepaymentOnDate, row.getRowNum(), externalId, linkAccountId,locale,dateFormat);
}
}else {
return null;
}
}
public Count importEntity(String dateFormat) {
Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
int successCount=0;
int errorCount=0;
int progressLevel = 0;
String loanId;
String errorMessage="";
for (int i = 0; i < loans.size(); i++) {
Row row = loanSheet.getRow(loans.get(i).getRowIndex());
Cell errorReportCell = row.createCell(LoanConstants.FAILURE_REPORT_COL);
Cell statusCell = row.createCell(LoanConstants.STATUS_COL);
CommandProcessingResult result=null;
loanId="";
try {
String status = statuses.get(i);;
progressLevel = getProgressLevel(status);
if (progressLevel == 0&& loans.get(i)!=null) {
result = importLoan(i,dateFormat);
loanId = result.getLoanId().toString();
progressLevel = 1;
} else
loanId = ImportHandlerUtils.readAsString(LoanConstants.LOAN_ID_COL, loanSheet.getRow(loans.get(i).getRowIndex()));
if (progressLevel <= 1 && approvalDates.get(i)!=null) progressLevel = importLoanApproval(result, i,dateFormat);
if (progressLevel <= 2 && disbursalDates.get(i)!=null) progressLevel = importDisbursalData(result, i,dateFormat);
if (loanRepayments.get(i) != null) progressLevel = importLoanRepayment(result, i,dateFormat);
successCount++;
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
writeLoanErrorMessage(loanId,errorMessage,progressLevel,statusCell,errorReportCell,row);
}
}
setReportHeaders(loanSheet);
return Count.instance(successCount,errorCount);
}
private void writeLoanErrorMessage(String loanId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){
String status = "";
if (progressLevel == 0)
status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED;
else if (progressLevel == 1)
status = TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED;
else if (progressLevel == 2)
status = TemplatePopulateImportConstants.STATUS_DISBURSAL_FAILED;
else if (progressLevel == 3) status = TemplatePopulateImportConstants.STATUS_DISBURSAL_REPAYMENT_FAILED;
statusCell.setCellValue(status);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED));
if (progressLevel > 0) row.createCell(LoanConstants.LOAN_ID_COL).setCellValue(Integer.parseInt(loanId));
errorReportCell.setCellValue(errorMessage);
}
private void setReportHeaders(Sheet sheet) {
sheet.setColumnWidth(LoanConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
Row rowHeader = sheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
ImportHandlerUtils.writeString(LoanConstants.STATUS_COL, rowHeader, "Status");
ImportHandlerUtils.writeString(LoanConstants.LOAN_ID_COL, rowHeader, "Loan ID");
ImportHandlerUtils.writeString(LoanConstants.FAILURE_REPORT_COL, rowHeader, "Report");
}
private Integer importLoanRepayment(CommandProcessingResult result, int rowIndex,String dateFormat) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
JsonObject loanRepaymentJsonob=gsonBuilder.create().toJsonTree(loanRepayments.get(rowIndex)).getAsJsonObject();
loanRepaymentJsonob.remove("manuallyReversed");
String payload=loanRepaymentJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.loanRepaymentTransaction(result.getLoanId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult loanRepaymentResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return 4;
}
private Integer importDisbursalData(CommandProcessingResult result, int rowIndex, String dateFormat) {
if (approvalDates.get(rowIndex) != null && disbursalDates.get(rowIndex) != null) {
DisbursementData disbusalData = disbursalDates.get(rowIndex);
String linkAccountId = disbusalData.getLinkAccountId();
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
if (linkAccountId != null && linkAccountId != "") {
String payload =gsonBuilder.create().toJson(disbusalData);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.disburseLoanToSavingsApplication(result.getLoanId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult loanDisburseToSavingsResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else {
String payload = gsonBuilder.create().toJson(disbusalData);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.disburseLoanApplication(result.getLoanId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult loanDisburseResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
}
return 3;
}
private Integer importLoanApproval(CommandProcessingResult result, int rowIndex,String dateFormat) {
if (approvalDates.get(rowIndex) != null) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
String payload = gsonBuilder.create().toJson(approvalDates.get(rowIndex));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.approveLoanApplication(result.getLoanId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult loanapprovalresult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 2;
}
private CommandProcessingResult importLoan(int rowIndex,String dateFormat) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataValueSerializer());
JsonObject loanJsonOb = gsonBuilder.create().toJsonTree(loans.get(rowIndex)).getAsJsonObject();
loanJsonOb.remove("isLoanProductLinkedToFloatingRate");
loanJsonOb.remove("isInterestRecalculationEnabled");
loanJsonOb.remove("isFloatingInterestRate");
JsonArray chargesJsonAr=loanJsonOb.getAsJsonArray("charges");
if (chargesJsonAr!=null) {
for (int i = 0; i < chargesJsonAr.size(); i++) {
JsonElement chargesJsonElement = chargesJsonAr.get(i);
JsonObject chargeJsonOb = chargesJsonElement.getAsJsonObject();
chargeJsonOb.remove("penalty");
chargeJsonOb.remove("paid");
chargeJsonOb.remove("waived");
chargeJsonOb.remove("chargePayable");
}
}
loanJsonOb.remove("isTopup");
String payload=loanJsonOb.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createLoanApplication() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return result;
}
private int getProgressLevel(String status) {
if (status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED))
return 0;
else if (status.equals(TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED))
return 1;
else if (status.equals(TemplatePopulateImportConstants.STATUS_DISBURSAL_FAILED))
return 2;
else if (status.equals(TemplatePopulateImportConstants.STATUS_DISBURSAL_REPAYMENT_FAILED)) return 3;
return 0;
}
}
@@ -0,0 +1,134 @@
/**
* 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.bulkimport.importhandler.loanrepayment;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.LoanRepaymentConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class LoanRepaymentImportHandler implements ImportHandler {
private Workbook workbook;
private List<LoanTransactionData> loanRepayments;
private Integer loanAccountId;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public LoanRepaymentImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.loanRepayments=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(String locale, String dateFormat) {
Sheet loanRepaymentSheet = workbook.getSheet(TemplatePopulateImportConstants.LOAN_REPAYMENT_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(loanRepaymentSheet, LoanRepaymentConstants.AMOUNT_COL);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = loanRepaymentSheet.getRow(rowIndex);
if(ImportHandlerUtils.isNotImported(row, LoanRepaymentConstants.STATUS_COL))
loanRepayments.add(readLoanRepayment(row,locale,dateFormat));
}
}
private LoanTransactionData readLoanRepayment(Row row,String locale, String dateFormat) {
String loanaccountInfo=ImportHandlerUtils.readAsString(LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL, row);
if (loanaccountInfo!=null){
String loanAccountAr[]=loanaccountInfo.split("-");
loanAccountId=Integer.parseInt(loanAccountAr[0]);
}
BigDecimal repaymentAmount=null;
if (ImportHandlerUtils.readAsDouble(LoanRepaymentConstants.AMOUNT_COL, row)!=null)
repaymentAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanRepaymentConstants.AMOUNT_COL, row));
LocalDate repaymentDate = ImportHandlerUtils.readAsDate(LoanRepaymentConstants.REPAID_ON_DATE_COL, row);
String repaymentType = ImportHandlerUtils.readAsString(LoanRepaymentConstants.REPAYMENT_TYPE_COL, row);
Long repaymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), repaymentType);
String accountNumber = ImportHandlerUtils.readAsString(LoanRepaymentConstants.ACCOUNT_NO_COL, row);
Integer checkNumber = ImportHandlerUtils.readAsInt(LoanRepaymentConstants.CHECK_NO_COL, row);
Integer routingCode = ImportHandlerUtils.readAsInt(LoanRepaymentConstants.ROUTING_CODE_COL, row);
Integer receiptNumber = ImportHandlerUtils.readAsInt(LoanRepaymentConstants.RECEIPT_NO_COL, row);
Integer bankNumber = ImportHandlerUtils.readAsInt(LoanRepaymentConstants.BANK_NO_COL, row);
return LoanTransactionData.importInstance(repaymentAmount, repaymentDate, repaymentTypeId, accountNumber,
checkNumber, routingCode, receiptNumber, bankNumber, loanAccountId, "", row.getRowNum(),locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet loanRepaymentSheet = workbook.getSheet(TemplatePopulateImportConstants.LOAN_REPAYMENT_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
for (LoanTransactionData loanRepayment : loanRepayments) {
try {
JsonObject loanRepaymentJsonob=gsonBuilder.create().toJsonTree(loanRepayment).getAsJsonObject();
loanRepaymentJsonob.remove("manuallyReversed");
String payload=loanRepaymentJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.loanRepaymentTransaction(loanRepayment.getAccountId().longValue()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = loanRepaymentSheet.getRow(loanRepayment.getRowIndex()).createCell(LoanRepaymentConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(loanRepaymentSheet,loanRepayment.getRowIndex(),errorMessage,LoanRepaymentConstants.STATUS_COL);
}
}
loanRepaymentSheet.setColumnWidth(LoanRepaymentConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(LoanRepaymentConstants.STATUS_COL,
loanRepaymentSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,123 @@
/**
* 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.bulkimport.importhandler.office;
import com.google.gson.GsonBuilder;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class OfficeImportHandler implements ImportHandler {
private List<OfficeData> offices;
private Workbook workbook;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public OfficeImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(final Workbook workbook, final String locale, final String dateFormat) {
this.offices=new ArrayList<>();
this.workbook=workbook;
readExcelFile(locale, dateFormat);
return importEntity (dateFormat);
}
public void readExcelFile(final String locale, final String dateFormat) {
Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(officeSheet,0);
for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++) {
Row row;
row=officeSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, OfficeConstants.STATUS_COL)){
offices.add(readOffice(row, locale, dateFormat));
}
}
}
private OfficeData readOffice(Row row, final String locale, final String dateFormat) {
String officeName = ImportHandlerUtils.readAsString(OfficeConstants.OFFICE_NAME_COL,row);
Long parentId= ImportHandlerUtils.readAsLong(OfficeConstants.PARENT_OFFICE_ID_COL,row);
LocalDate openedDate= ImportHandlerUtils.readAsDate(OfficeConstants.OPENED_ON_COL,row);
String externalId= ImportHandlerUtils.readAsString(OfficeConstants.EXTERNAL_ID_COL,row);
OfficeData office = OfficeData.importInstance(officeName,parentId,openedDate,externalId);
office.setImportFields(row.getRowNum(), locale, dateFormat);
return office;
}
public Count importEntity(String dateFormat) {
Sheet officeSheet = workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
int successCount = 0;
int errorCount = 0;
String errorMessage="";
for (OfficeData office: offices) {
try {
String payload = gsonBuilder.create().toJson(office);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createOffice() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount ++;
Cell statusCell = officeSheet.getRow(office.getRowIndex()).createCell(OfficeConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(officeSheet,office.getRowIndex(),errorMessage,OfficeConstants.STATUS_COL);
}
}
officeSheet.setColumnWidth(OfficeConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(OfficeConstants.STATUS_COL, officeSheet.getRow(0), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount, errorCount);
}
public List<OfficeData> getOffices() {
return offices;
}
}
@@ -0,0 +1,372 @@
/**
* 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.bulkimport.importhandler.recurringdeposit;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.RecurringDepositConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataIdSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.savings.data.RecurringDepositAccountData;
import org.apache.fineract.portfolio.savings.data.SavingsAccountChargeData;
import org.apache.fineract.portfolio.savings.data.SavingsActivation;
import org.apache.fineract.portfolio.savings.data.SavingsApproval;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class RecurringDepositImportHandler implements ImportHandler {
private Workbook workbook;
private List<RecurringDepositAccountData> savings;
private List<SavingsApproval> approvalDates;
private List<SavingsActivation> activationDates;
private List<String> statuses;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public RecurringDepositImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
savings=new ArrayList<>();
approvalDates=new ArrayList<>();
activationDates=new ArrayList<>();
statuses=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(String locale, String dateFormat) {
Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.RECURRING_DEPOSIT_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsSheet, TemplatePopulateImportConstants.ROWHEADER_INDEX);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = savingsSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, RecurringDepositConstants.STATUS_COL)) {
savings.add(readSavings(row,locale,dateFormat));
approvalDates.add(readSavingsApproval(row,locale,dateFormat));
activationDates.add(readSavingsActivation(row,locale,dateFormat));
}
}
}
private SavingsActivation readSavingsActivation(Row row,String locale, String dateFormat) {
LocalDate activationDate = ImportHandlerUtils.readAsDate(RecurringDepositConstants.ACTIVATION_DATE_COL, row);
if (activationDate!=null)
return SavingsActivation.importInstance(activationDate, row.getRowNum(),locale,dateFormat);
else
return null;
}
private SavingsApproval readSavingsApproval(Row row,String locale, String dateFormat) {
LocalDate approvalDate = ImportHandlerUtils.readAsDate(RecurringDepositConstants.APPROVED_DATE_COL, row);
if (approvalDate!=null)
return SavingsApproval.importInstance(approvalDate, row.getRowNum(),locale,dateFormat);
else
return null;
}
private RecurringDepositAccountData readSavings(Row row,String locale, String dateFormat) {
String productName = ImportHandlerUtils.readAsString(RecurringDepositConstants.PRODUCT_COL, row);
Long productId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName);
String fieldOfficerName = ImportHandlerUtils.readAsString(RecurringDepositConstants.FIELD_OFFICER_NAME_COL, row);
Long fieldOfficerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), fieldOfficerName);
LocalDate submittedOnDate = ImportHandlerUtils.readAsDate(RecurringDepositConstants.SUBMITTED_ON_DATE_COL, row);
String interestCompoundingPeriodType = ImportHandlerUtils.readAsString(RecurringDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, row);
Long interestCompoundingPeriodTypeId = null;
EnumOptionData interestCompoundingPeriodTypeEnum=null;
if (interestCompoundingPeriodType!=null) {
if (interestCompoundingPeriodType.equalsIgnoreCase("Daily"))
interestCompoundingPeriodTypeId = 1L;
else if (interestCompoundingPeriodType.equalsIgnoreCase("Monthly"))
interestCompoundingPeriodTypeId = 4L;
else if (interestCompoundingPeriodType.equalsIgnoreCase("Quarterly"))
interestCompoundingPeriodTypeId = 5L;
else if (interestCompoundingPeriodType.equalsIgnoreCase("Semi-Annual"))
interestCompoundingPeriodTypeId = 6L;
else if (interestCompoundingPeriodType.equalsIgnoreCase("Annually"))
interestCompoundingPeriodTypeId = 7L;
interestCompoundingPeriodTypeEnum = new EnumOptionData(interestCompoundingPeriodTypeId, null, null);
}
String interestPostingPeriodType = ImportHandlerUtils.readAsString(RecurringDepositConstants.INTEREST_POSTING_PERIOD_COL, row);
Long interestPostingPeriodTypeId = null;
EnumOptionData interestPostingPeriodTypeEnum=null;
if (interestPostingPeriodType!=null) {
if (interestPostingPeriodType.equalsIgnoreCase("Monthly"))
interestPostingPeriodTypeId = 4L;
else if (interestPostingPeriodType.equalsIgnoreCase("Quarterly"))
interestPostingPeriodTypeId = 5L;
else if (interestPostingPeriodType.equalsIgnoreCase("Annually"))
interestPostingPeriodTypeId = 7L;
else if (interestPostingPeriodType.equalsIgnoreCase("BiAnnual"))
interestPostingPeriodTypeId = 6L;
interestPostingPeriodTypeEnum = new EnumOptionData(interestPostingPeriodTypeId, null, null);
}
String interestCalculationType = ImportHandlerUtils.readAsString(RecurringDepositConstants.INTEREST_CALCULATION_COL, row);
Long interestCalculationTypeId = null;
EnumOptionData interestCalculationTypeEnum=null;
if (interestCalculationType!=null) {
if (interestCalculationType.equalsIgnoreCase("Daily Balance"))
interestCalculationTypeId = 1L;
else if (interestCalculationType.equalsIgnoreCase("Average Daily Balance"))
interestCalculationTypeId = 2L;
interestCalculationTypeEnum = new EnumOptionData(interestCalculationTypeId, null, null);
}
String interestCalculationDaysInYearType = ImportHandlerUtils.readAsString(RecurringDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row);
EnumOptionData interestCalculationDaysInYearTypeEnum=null;
Long interestCalculationDaysInYearTypeId = null;
if (interestCalculationDaysInYearType!=null) {
if (interestCalculationDaysInYearType.equalsIgnoreCase("360 Days"))
interestCalculationDaysInYearTypeId = 360L;
else if (interestCalculationDaysInYearType.equalsIgnoreCase("365 Days"))
interestCalculationDaysInYearTypeId = 365L;
interestCalculationDaysInYearTypeEnum = new EnumOptionData(interestCalculationDaysInYearTypeId, null, null);
}
Integer lockinPeriodFrequency = ImportHandlerUtils.readAsInt(RecurringDepositConstants.LOCKIN_PERIOD_COL, row);
String lockinPeriodFrequencyType = ImportHandlerUtils.readAsString(RecurringDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, row);
Long lockinPeriodFrequencyTypeId = null;
EnumOptionData lockinPeriodFrequencyTypeEnum=null;
if (lockinPeriodFrequencyType!=null) {
if (lockinPeriodFrequencyType.equalsIgnoreCase("Days"))
lockinPeriodFrequencyTypeId = 0L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase("Weeks"))
lockinPeriodFrequencyTypeId = 1L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase("Months"))
lockinPeriodFrequencyTypeId = 2L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase("Years"))
lockinPeriodFrequencyTypeId = 3L;
lockinPeriodFrequencyTypeEnum = new EnumOptionData(lockinPeriodFrequencyTypeId, null, null);
}
BigDecimal depositAmount=null;
if (ImportHandlerUtils.readAsDouble(RecurringDepositConstants.RECURRING_DEPOSIT_AMOUNT_COL, row)!=null)
depositAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(RecurringDepositConstants.RECURRING_DEPOSIT_AMOUNT_COL, row));
Integer depositPeriod = ImportHandlerUtils.readAsInt(RecurringDepositConstants.DEPOSIT_PERIOD_COL, row);
String depositPeriodFrequency = ImportHandlerUtils.readAsString(RecurringDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, row);
Long depositPeriodFrequencyId = null;
if (depositPeriodFrequency!=null) {
if (depositPeriodFrequency.equalsIgnoreCase("Days"))
depositPeriodFrequencyId = 0L;
else if (depositPeriodFrequency.equalsIgnoreCase("Weeks"))
depositPeriodFrequencyId = 1L;
else if (depositPeriodFrequency.equalsIgnoreCase("Months"))
depositPeriodFrequencyId = 2L;
else if (depositPeriodFrequency.equalsIgnoreCase("Years"))
depositPeriodFrequencyId = 3L;
}
Integer recurringFrequency = ImportHandlerUtils.readAsInt(RecurringDepositConstants.DEPOSIT_FREQUENCY_COL, row);
String recurringFrequencyType = ImportHandlerUtils.readAsString(RecurringDepositConstants.DEPOSIT_FREQUENCY_TYPE_COL, row);
Long recurringFrequencyTypeId = null;
EnumOptionData recurringFrequencyTypeEnum=null;
if (recurringFrequencyType!=null) {
if (recurringFrequencyType.equalsIgnoreCase("Days"))
recurringFrequencyTypeId = 0L;
else if (recurringFrequencyType.equalsIgnoreCase("Weeks"))
recurringFrequencyTypeId = 1L;
else if (recurringFrequencyType.equalsIgnoreCase("Months"))
recurringFrequencyTypeId = 2L;
else if (recurringFrequencyType.equalsIgnoreCase("Years"))
recurringFrequencyTypeId = 3L;
recurringFrequencyTypeEnum = new EnumOptionData(recurringFrequencyTypeId, null, null);
}
LocalDate depositStartDate = ImportHandlerUtils.readAsDate(RecurringDepositConstants.DEPOSIT_START_DATE_COL, row);
Boolean allowWithdrawal = ImportHandlerUtils.readAsBoolean(RecurringDepositConstants.ALLOW_WITHDRAWAL_COL, row);
Boolean isMandatoryDeposit = ImportHandlerUtils.readAsBoolean(RecurringDepositConstants.IS_MANDATORY_DEPOSIT_COL, row);
Boolean inheritCalendar = ImportHandlerUtils.readAsBoolean(RecurringDepositConstants.FREQ_SAME_AS_GROUP_CENTER_COL, row);
Boolean adjustAdvancePayments = ImportHandlerUtils.readAsBoolean(RecurringDepositConstants.ADJUST_ADVANCE_PAYMENTS_COL, row);
String clientName = ImportHandlerUtils.readAsString(RecurringDepositConstants.CLIENT_NAME_COL, row);
String externalId = ImportHandlerUtils.readAsString(RecurringDepositConstants.EXTERNAL_ID_COL, row);
List<SavingsAccountChargeData> charges = new ArrayList<>();
String charge1 = ImportHandlerUtils.readAsString(RecurringDepositConstants.CHARGE_ID_1, row);
String charge2 = ImportHandlerUtils.readAsString(RecurringDepositConstants.CHARGE_ID_2, row);
if (charge1!=null) {
if (ImportHandlerUtils.readAsDouble(RecurringDepositConstants.CHARGE_AMOUNT_1, row)!=null) {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(RecurringDepositConstants.CHARGE_ID_1, row),
BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(RecurringDepositConstants.CHARGE_AMOUNT_1, row)),
ImportHandlerUtils.readAsDate(RecurringDepositConstants.CHARGE_DUE_DATE_1, row)));
}else {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(RecurringDepositConstants.CHARGE_ID_1, row),
null,
ImportHandlerUtils.readAsDate(RecurringDepositConstants.CHARGE_DUE_DATE_1, row)));
}
}
if (charge2!=null) {
if (ImportHandlerUtils.readAsDouble(RecurringDepositConstants.CHARGE_AMOUNT_2, row)!=null) {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(RecurringDepositConstants.CHARGE_ID_2, row),
BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(RecurringDepositConstants.CHARGE_AMOUNT_2, row)),
ImportHandlerUtils.readAsDate(RecurringDepositConstants.CHARGE_DUE_DATE_2, row)));
}else {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(RecurringDepositConstants.CHARGE_ID_2, row),
null,
ImportHandlerUtils.readAsDate(RecurringDepositConstants.CHARGE_DUE_DATE_2, row)));
}
}
String status = ImportHandlerUtils.readAsString(RecurringDepositConstants.STATUS_COL, row);
statuses.add(status);
Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName);
return RecurringDepositAccountData.importInstance(clientId, productId, fieldOfficerId, submittedOnDate,
interestCompoundingPeriodTypeEnum,interestPostingPeriodTypeEnum,interestCalculationTypeEnum,
interestCalculationDaysInYearTypeEnum, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum,
depositAmount, depositPeriod, depositPeriodFrequencyId, depositStartDate,
recurringFrequency, recurringFrequencyTypeEnum, inheritCalendar, isMandatoryDeposit,
allowWithdrawal, adjustAdvancePayments, externalId,charges, row.getRowNum(),locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.RECURRING_DEPOSIT_SHEET_NAME);
int successCount=0;
int errorCount=0;
int progressLevel = 0;
Long savingsId=null;
String errorMessage="";
for (int i = 0; i < savings.size(); i++) {
Row row = savingsSheet.getRow(savings.get(i).getRowIndex());
Cell statusCell = row.createCell(RecurringDepositConstants.STATUS_COL);
Cell errorReportCell = row.createCell(RecurringDepositConstants.FAILURE_REPORT_COL);
try {
String status = statuses.get(i);
progressLevel = getProgressLevel(status);
if (progressLevel == 0) {
CommandProcessingResult result= importSavings(i,dateFormat);
savingsId = result.getSavingsId();
progressLevel = 1;
} else
savingsId = ImportHandlerUtils.readAsLong(RecurringDepositConstants.SAVINGS_ID_COL, savingsSheet.getRow(savings.get(i).getRowIndex()));
if (progressLevel <= 1) progressLevel = importSavingsApproval(savingsId, i,dateFormat);
if (progressLevel <= 2) progressLevel = importSavingsActivation(savingsId, i,dateFormat);
successCount++;
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
writeRecurringDepositErrorMessage(savingsId,errorMessage,progressLevel,statusCell,errorReportCell,row);
}
}
setReportHeaders(savingsSheet);
return Count.instance(successCount,errorCount);
}
private void writeRecurringDepositErrorMessage(Long savingsId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){
String status = "";
if (progressLevel == 0)
status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED;
else if (progressLevel == 1)
status = TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED;
else if (progressLevel == 2) status = TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED;
statusCell.setCellValue(status);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED));
if (progressLevel > 0) row.createCell(RecurringDepositConstants.SAVINGS_ID_COL).setCellValue(savingsId);
errorReportCell.setCellValue(errorMessage);
}
private void setReportHeaders(Sheet savingsSheet) {
savingsSheet.setColumnWidth(RecurringDepositConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
Row rowHeader = savingsSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
ImportHandlerUtils.writeString(RecurringDepositConstants.STATUS_COL, rowHeader, "Status");
ImportHandlerUtils.writeString(RecurringDepositConstants.SAVINGS_ID_COL, rowHeader, "Savings ID");
ImportHandlerUtils.writeString(RecurringDepositConstants.FAILURE_REPORT_COL, rowHeader, "Report");
}
private int importSavingsActivation(Long savingsId, int i,String dateFormat) {
if(activationDates.get(i)!=null) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
String payload = gsonBuilder.create().toJson(activationDates.get(i));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.recurringDepositAccountActivation(savingsId)//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 3;
}
private int importSavingsApproval(Long savingsId, int i, String dateFormat) {
if(approvalDates.get(i)!=null) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
String payload = gsonBuilder.create().toJson(approvalDates.get(i));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.approveRecurringDepositAccountApplication(savingsId)//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 2;
}
private CommandProcessingResult importSavings(int i, String dateFormat) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataIdSerializer());
JsonObject savingsJsonob=gsonBuilder.create().toJsonTree(savings.get(i)).getAsJsonObject();
savingsJsonob.remove("withdrawalFeeForTransfers");
String payload=savingsJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createRecurringDepositAccount() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return result;
}
private int getProgressLevel(String status) {
if (status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED))
return 0;
else if (status.equals(TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED))
return 1;
else if (status.equals(TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED)) return 2;
return 0;
}
}
@@ -0,0 +1,157 @@
/**
* 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.bulkimport.importhandler.recurringdeposit;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.SavingsAccountTransactionEnumValueSerialiser;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionData;
import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class RecurringDepositTransactionImportHandler implements ImportHandler {
private Workbook workbook;
private List<SavingsAccountTransactionData> savingsTransactions;
private String savingsAccountId = "";
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public RecurringDepositTransactionImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.savingsTransactions=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(String locale, String dateFormat) {
Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsTransactionSheet, TransactionConstants.AMOUNT_COL);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = savingsTransactionSheet.getRow(rowIndex);
if(ImportHandlerUtils.isNotImported(row, TransactionConstants.STATUS_COL))
savingsTransactions.add(readSavingsTransaction(row,locale,dateFormat));
}
}
private SavingsAccountTransactionData readSavingsTransaction(Row row,String locale, String dateFormat) {
String savingsAccountIdCheck=null;
if (ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row)!=null)
savingsAccountIdCheck = ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row).toString();
if(savingsAccountIdCheck!=null)
savingsAccountId = savingsAccountIdCheck;
String transactionType = ImportHandlerUtils.readAsString(TransactionConstants.TRANSACTION_TYPE_COL, row);
SavingsAccountTransactionEnumData savingsAccountTransactionEnumData=new SavingsAccountTransactionEnumData(null,null,transactionType);
BigDecimal amount=null;
if (ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)!=null)
amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row));
LocalDate transactionDate = ImportHandlerUtils.readAsDate(TransactionConstants.TRANSACTION_DATE_COL, row);
String paymentType = ImportHandlerUtils.readAsString(TransactionConstants.PAYMENT_TYPE_COL, row);
Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), paymentType);
String accountNumber = ImportHandlerUtils.readAsString(TransactionConstants.ACCOUNT_NO_COL, row);
String checkNumber = ImportHandlerUtils.readAsString(TransactionConstants.CHECK_NO_COL, row);
String routingCode = ImportHandlerUtils.readAsString(TransactionConstants.ROUTING_CODE_COL, row);
String receiptNumber = ImportHandlerUtils.readAsString(TransactionConstants.RECEIPT_NO_COL, row);
String bankNumber = ImportHandlerUtils.readAsString(TransactionConstants.BANK_NO_COL, row);
return SavingsAccountTransactionData.importInstance(amount, transactionDate, paymentTypeId, accountNumber,
checkNumber, routingCode, receiptNumber, bankNumber, Long.parseLong(savingsAccountId), savingsAccountTransactionEnumData, row.getRowNum(),locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(SavingsAccountTransactionEnumData.class
,new SavingsAccountTransactionEnumValueSerialiser());
for (SavingsAccountTransactionData transaction : savingsTransactions) {
try {
JsonObject savingsTransactionJsonob=gsonBuilder.create().toJsonTree(transaction).getAsJsonObject();
savingsTransactionJsonob.remove("transactionType");
savingsTransactionJsonob.remove("reversed");
savingsTransactionJsonob.remove("interestedPostedAsOn");
String payload= savingsTransactionJsonob.toString();
CommandWrapper commandRequest=null;
if (transaction.getTransactionType().getValue().equals("Withdrawal")) {
commandRequest = new CommandWrapperBuilder() //
.recurringAccountWithdrawal(transaction.getSavingsAccountId()) //
.withJson(payload) //
.build(); //
}else if (transaction.getTransactionType().getValue().equals("Deposit")){
commandRequest = new CommandWrapperBuilder() //
.recurringAccountDeposit(transaction.getSavingsAccountId()) //
.withJson(payload) //
.build();
}
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(TransactionConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
} catch (AbstractPlatformDomainRuleException e) {
errorCount++;
e.printStackTrace();
errorMessage = e.getDefaultUserMessage();
ImportHandlerUtils.writeErrorMessage(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL);
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL);
}
}
savingsTransactionSheet.setColumnWidth(TransactionConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(TransactionConstants.STATUS_COL, savingsTransactionSheet.getRow(TransactionConstants.STATUS_COL), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,364 @@
/**
* 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.bulkimport.importhandler.savings;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.SavingsConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataIdSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.savings.data.SavingsAccountChargeData;
import org.apache.fineract.portfolio.savings.data.SavingsAccountData;
import org.apache.fineract.portfolio.savings.data.SavingsActivation;
import org.apache.fineract.portfolio.savings.data.SavingsApproval;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@Service
public class SavingsImportHandler implements ImportHandler {
private Workbook workbook;
private List<SavingsAccountData> savings;
private List<SavingsApproval> approvalDates;
private List<SavingsActivation> activationDates;
private List<String>statuses;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public SavingsImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.savings=new ArrayList<>();
this.approvalDates=new ArrayList<>();
this.activationDates=new ArrayList<>();
this.statuses=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(String locale, String dateFormat) {
Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = savingsSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, SavingsConstants.STATUS_COL)) {
savings.add(readSavings(row,locale,dateFormat));
approvalDates.add(readSavingsApproval(row,locale,dateFormat));
activationDates.add(readSavingsActivation(row,locale,dateFormat));
}
}
}
private SavingsActivation readSavingsActivation(Row row,String locale, String dateFormat) {
LocalDate activationDate = ImportHandlerUtils.readAsDate( SavingsConstants.ACTIVATION_DATE_COL, row);
if (activationDate!=null)
return SavingsActivation.importInstance(activationDate, row.getRowNum(),locale,dateFormat);
else
return null;
}
private SavingsApproval readSavingsApproval(Row row,String locale, String dateFormat) {
LocalDate approvalDate = ImportHandlerUtils.readAsDate( SavingsConstants.APPROVED_DATE_COL, row);
if (approvalDate!=null)
return SavingsApproval.importInstance(approvalDate, row.getRowNum(),locale,dateFormat);
else
return null;
}
private SavingsAccountData readSavings(Row row,String locale, String dateFormat) {
String productName = ImportHandlerUtils.readAsString( SavingsConstants.PRODUCT_COL, row);
Long productId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName);
String fieldOfficerName = ImportHandlerUtils.readAsString(SavingsConstants.FIELD_OFFICER_NAME_COL, row);
Long fieldOfficerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), fieldOfficerName);
LocalDate submittedOnDate = ImportHandlerUtils.readAsDate(SavingsConstants.SUBMITTED_ON_DATE_COL, row);
BigDecimal nominalAnnualInterestRate=null;
if (ImportHandlerUtils.readAsDouble(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL, row)!=null) {
nominalAnnualInterestRate = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL, row));
}
String interestCompoundingPeriodType = ImportHandlerUtils.readAsString(SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL, row);
Long interestCompoundingPeriodTypeId = null;
EnumOptionData interestCompoundingPeriodTypeEnum=null;
if (interestCompoundingPeriodType!=null) {
if (interestCompoundingPeriodType.equalsIgnoreCase("Daily"))
interestCompoundingPeriodTypeId = 1L;
else if (interestCompoundingPeriodType.equalsIgnoreCase("Monthly"))
interestCompoundingPeriodTypeId = 4L;
else if (interestCompoundingPeriodType.equalsIgnoreCase("Quarterly"))
interestCompoundingPeriodTypeId = 5L;
else if (interestCompoundingPeriodType.equalsIgnoreCase("Semi-Annual"))
interestCompoundingPeriodTypeId = 6L;
else if (interestCompoundingPeriodType.equalsIgnoreCase("Annually"))
interestCompoundingPeriodTypeId = 7L;
interestCompoundingPeriodTypeEnum = new EnumOptionData(interestCompoundingPeriodTypeId, null, null);
}
String interestPostingPeriodType = ImportHandlerUtils.readAsString(SavingsConstants.INTEREST_POSTING_PERIOD_COL, row);
Long interestPostingPeriodTypeId = null;
EnumOptionData interestPostingPeriodTypeEnum=null;
if (interestPostingPeriodType!=null) {
if (interestPostingPeriodType.equalsIgnoreCase("Monthly"))
interestPostingPeriodTypeId = 4L;
else if (interestPostingPeriodType.equalsIgnoreCase("Quarterly"))
interestPostingPeriodTypeId = 5L;
else if (interestPostingPeriodType.equalsIgnoreCase("Annually"))
interestPostingPeriodTypeId = 7L;
else if (interestPostingPeriodType.equalsIgnoreCase("BiAnnual"))
interestPostingPeriodTypeId = 6L;
interestPostingPeriodTypeEnum = new EnumOptionData(interestPostingPeriodTypeId, null, null);
}
String interestCalculationType = ImportHandlerUtils.readAsString(SavingsConstants.INTEREST_CALCULATION_COL, row);
Long interestCalculationTypeId = null;
EnumOptionData interestCalculationTypeEnum=null;
if (interestCalculationType!=null) {
if (interestCalculationType.equalsIgnoreCase("Daily Balance"))
interestCalculationTypeId = 1L;
else if (interestCalculationType.equalsIgnoreCase("Average Daily Balance"))
interestCalculationTypeId = 2L;
interestCalculationTypeEnum = new EnumOptionData(interestCalculationTypeId, null, null);
}
String interestCalculationDaysInYearType = ImportHandlerUtils.readAsString(SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row);
EnumOptionData interestCalculationDaysInYearTypeEnum=null;
Long interestCalculationDaysInYearTypeId = null;
if (interestCalculationDaysInYearType!=null) {
if (interestCalculationDaysInYearType.equalsIgnoreCase("360 Days"))
interestCalculationDaysInYearTypeId = 360L;
else if (interestCalculationDaysInYearType.equalsIgnoreCase("365 Days"))
interestCalculationDaysInYearTypeId = 365L;
interestCalculationDaysInYearTypeEnum = new EnumOptionData(interestCalculationDaysInYearTypeId, null, null);
}
BigDecimal minRequiredOpeningBalance=null;
if (ImportHandlerUtils.readAsDouble(SavingsConstants.MIN_OPENING_BALANCE_COL, row)!=null) {
minRequiredOpeningBalance = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.MIN_OPENING_BALANCE_COL, row));
}
Integer lockinPeriodFrequency = ImportHandlerUtils.readAsInt(SavingsConstants.LOCKIN_PERIOD_COL, row);
String lockinPeriodFrequencyType = ImportHandlerUtils.readAsString(SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL, row);
Long lockinPeriodFrequencyTypeId = null;
EnumOptionData lockinPeriodFrequencyTypeEnum=null;
if (lockinPeriodFrequencyType!=null) {
if (lockinPeriodFrequencyType.equalsIgnoreCase("Days"))
lockinPeriodFrequencyTypeId = 0L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase("Weeks"))
lockinPeriodFrequencyTypeId = 1L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase("Months"))
lockinPeriodFrequencyTypeId = 2L;
else if (lockinPeriodFrequencyType.equalsIgnoreCase("Years"))
lockinPeriodFrequencyTypeId = 3L;
lockinPeriodFrequencyTypeEnum = new EnumOptionData(lockinPeriodFrequencyTypeId, null, null);
}
Boolean applyWithdrawalFeeForTransfers = ImportHandlerUtils.readAsBoolean(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS, row);
String savingsType=null;
if (ImportHandlerUtils.readAsString(SavingsConstants.SAVINGS_TYPE_COL, row)!=null)
savingsType = ImportHandlerUtils.readAsString(SavingsConstants.SAVINGS_TYPE_COL, row).toLowerCase(Locale.ENGLISH);
String clientOrGroupName = ImportHandlerUtils.readAsString(SavingsConstants.CLIENT_NAME_COL, row);
String externalId = ImportHandlerUtils.readAsString(SavingsConstants.EXTERNAL_ID_COL, row);
List<SavingsAccountChargeData> charges = new ArrayList<>();
Boolean allowOverdraft = ImportHandlerUtils.readAsBoolean(SavingsConstants.ALLOW_OVER_DRAFT_COL, row);
BigDecimal overdraftLimit = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.OVER_DRAFT_LIMIT_COL, row));
String charge1 = ImportHandlerUtils.readAsString(SavingsConstants.CHARGE_ID_1, row);
String charge2 = ImportHandlerUtils.readAsString(SavingsConstants.CHARGE_ID_2, row);
if (charge1!=null) {
if (ImportHandlerUtils.readAsDouble(SavingsConstants.CHARGE_AMOUNT_1, row)!=null) {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(SavingsConstants.CHARGE_ID_1, row),
BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.CHARGE_AMOUNT_1, row)),
ImportHandlerUtils.readAsDate(SavingsConstants.CHARGE_DUE_DATE_1, row)));
}else {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(SavingsConstants.CHARGE_ID_1, row),
null,
ImportHandlerUtils.readAsDate(SavingsConstants.CHARGE_DUE_DATE_1, row)));
}
}
if (charge2!=null) {
if (ImportHandlerUtils.readAsDouble(SavingsConstants.CHARGE_AMOUNT_2, row)!=null) {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(SavingsConstants.CHARGE_ID_2, row),
BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.CHARGE_AMOUNT_2, row)),
ImportHandlerUtils.readAsDate(SavingsConstants.CHARGE_DUE_DATE_2, row)));
}else {
charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(SavingsConstants.CHARGE_ID_2, row),
null,
ImportHandlerUtils.readAsDate(SavingsConstants.CHARGE_DUE_DATE_2, row)));
}
}
String status = ImportHandlerUtils.readAsString(SavingsConstants.STATUS_COL, row);
statuses.add(status);
if (savingsType!=null) {
if (savingsType.equals("individual")) {
Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientOrGroupName);
return SavingsAccountData.importInstanceIndividual(clientId, productId, fieldOfficerId, submittedOnDate, nominalAnnualInterestRate,
interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum,
interestCalculationDaysInYearTypeEnum, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum,
applyWithdrawalFeeForTransfers, row.getRowNum(), externalId, charges, allowOverdraft, overdraftLimit,locale,dateFormat);
}
Long groupId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME), clientOrGroupName);
return SavingsAccountData.importInstanceGroup(groupId, productId, fieldOfficerId, submittedOnDate, nominalAnnualInterestRate,
interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum,
interestCalculationDaysInYearTypeEnum, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum,
applyWithdrawalFeeForTransfers, row.getRowNum(), externalId, charges, allowOverdraft, overdraftLimit,locale,dateFormat);
}else {
return null;
}
}
public Count importEntity(String dateFormat) {
Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME);
int successCount=0;
int errorCount=0;
int progressLevel = 0;
String errorMessage="";
Long savingsId=null;
for (int i = 0; i < savings.size(); i++) {
Row row = savingsSheet.getRow(savings.get(i).getRowIndex());
Cell statusCell = row.createCell(SavingsConstants.STATUS_COL);
Cell errorReportCell = row.createCell(SavingsConstants.FAILURE_REPORT_COL);
try {
String status = statuses.get(i);
progressLevel = getProgressLevel(status);
if (progressLevel == 0) {
CommandProcessingResult result = importSavings(i,dateFormat);
savingsId = result.getSavingsId();;
progressLevel = 1;
} else
savingsId = ImportHandlerUtils.readAsLong(SavingsConstants.SAVINGS_ID_COL, savingsSheet.getRow(savings.get(i).getRowIndex()));
if (progressLevel <= 1) progressLevel = importSavingsApproval(savingsId, i,dateFormat);
if (progressLevel <= 2) progressLevel = importSavingsActivation(savingsId, i,dateFormat);
successCount++;
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
writeSavingsErrorMessage(savingsId,errorMessage,progressLevel,statusCell,errorReportCell,row);
}
}
setReportHeaders(savingsSheet);
return Count.instance(successCount,errorCount);
}
private void writeSavingsErrorMessage(Long savingsId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){
String status = "";
if (progressLevel == 0)
status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED;
else if (progressLevel == 1)
status = TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED;
else if (progressLevel == 2) status = TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED;
statusCell.setCellValue(status);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED));
if (progressLevel > 0) row.createCell(SavingsConstants.SAVINGS_ID_COL).setCellValue(savingsId);
errorReportCell.setCellValue(errorMessage);
}
private void setReportHeaders(Sheet savingsSheet) {
savingsSheet.setColumnWidth(SavingsConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
Row rowHeader = savingsSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
ImportHandlerUtils.writeString(SavingsConstants.STATUS_COL, rowHeader, TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
ImportHandlerUtils.writeString(SavingsConstants.SAVINGS_ID_COL, rowHeader, TemplatePopulateImportConstants.SAVINGS_ID_COL_REPORT_HEADER);
ImportHandlerUtils.writeString(SavingsConstants.FAILURE_REPORT_COL, rowHeader, TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER);
}
private int importSavingsActivation(Long savingsId, int i, String dateFormat) {
if(activationDates.get(i)!=null) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
String payload = gsonBuilder.create().toJson(activationDates.get(i));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.savingsAccountActivation(savingsId)//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 3;
}
private int importSavingsApproval(Long savingsId, int i,
String dateFormat) {
if(approvalDates.get(i)!=null) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
String payload = gsonBuilder.create().toJson(approvalDates.get(i));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.approveSavingsAccountApplication(savingsId)//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 2;
}
private CommandProcessingResult importSavings(int i,String dateFormat) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataIdSerializer());
JsonObject savingsJsonob=gsonBuilder.create().toJsonTree(savings.get(i)).getAsJsonObject();
savingsJsonob.remove("isDormancyTrackingActive");
String payload= savingsJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createSavingsAccount() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return result;
}
private int getProgressLevel(String status) {
if (status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED))
return 0;
else if (status.equals(TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED))
return 1;
else if (status.equals(TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED)) return 2;
return 0;
}
}
@@ -0,0 +1,152 @@
/**
* 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.bulkimport.importhandler.savings;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.SavingsAccountTransactionEnumValueSerialiser;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionData;
import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class SavingsTransactionImportHandler implements ImportHandler {
private Workbook workbook;
private List<SavingsAccountTransactionData> savingsTransactions;
private String savingsAccountId = "";
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public SavingsTransactionImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.savingsTransactions=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(String locale, String dateFormat) {
Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsTransactionSheet, TransactionConstants.AMOUNT_COL);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = savingsTransactionSheet.getRow(rowIndex);
if(ImportHandlerUtils.isNotImported(row, TransactionConstants.STATUS_COL))
savingsTransactions.add(readSavingsTransaction(row,locale,dateFormat));
}
}
private SavingsAccountTransactionData readSavingsTransaction(Row row,String locale, String dateFormat) {
String savingsAccountIdCheck=null;
if (ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row)!=null)
savingsAccountIdCheck = ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row).toString();
if(savingsAccountIdCheck!=null)
savingsAccountId = savingsAccountIdCheck;
String transactionType = ImportHandlerUtils.readAsString(TransactionConstants.TRANSACTION_TYPE_COL, row);
SavingsAccountTransactionEnumData savingsAccountTransactionEnumData=new SavingsAccountTransactionEnumData(null,null,transactionType);
BigDecimal amount=null;
if (ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)!=null)
amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row));
LocalDate transactionDate = ImportHandlerUtils.readAsDate(TransactionConstants.TRANSACTION_DATE_COL, row);
String paymentType = ImportHandlerUtils.readAsString(TransactionConstants.PAYMENT_TYPE_COL, row);
Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), paymentType);
String accountNumber = ImportHandlerUtils.readAsString(TransactionConstants.ACCOUNT_NO_COL, row);
String checkNumber = ImportHandlerUtils.readAsString(TransactionConstants.CHECK_NO_COL, row);
String routingCode = ImportHandlerUtils.readAsString(TransactionConstants.ROUTING_CODE_COL, row);
String receiptNumber = ImportHandlerUtils.readAsString(TransactionConstants.RECEIPT_NO_COL, row);
String bankNumber = ImportHandlerUtils.readAsString(TransactionConstants.BANK_NO_COL, row);
return SavingsAccountTransactionData.importInstance(amount, transactionDate, paymentTypeId, accountNumber,
checkNumber, routingCode, receiptNumber, bankNumber, Long.parseLong(savingsAccountId), savingsAccountTransactionEnumData, row.getRowNum(),locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(SavingsAccountTransactionEnumData.class
,new SavingsAccountTransactionEnumValueSerialiser());
for (SavingsAccountTransactionData transaction : savingsTransactions) {
try {
JsonObject savingsTransactionJsonob=gsonBuilder.create().toJsonTree(transaction).getAsJsonObject();
savingsTransactionJsonob.remove("transactionType");
savingsTransactionJsonob.remove("reversed");
savingsTransactionJsonob.remove("interestedPostedAsOn");
String payload= savingsTransactionJsonob.toString();
CommandWrapper commandRequest=null;
if (transaction.getTransactionType().getValue().equals("Withdrawal")) {
commandRequest = new CommandWrapperBuilder() //
.savingsAccountWithdrawal(transaction.getSavingsAccountId()) //
.withJson(payload) //
.build(); //
}else if (transaction.getTransactionType().getValue().equals("Deposit")){
commandRequest = new CommandWrapperBuilder() //
.savingsAccountDeposit(transaction.getSavingsAccountId()) //
.withJson(payload) //
.build();
}
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(TransactionConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL);
}
}
savingsTransactionSheet.setColumnWidth(TransactionConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(TransactionConstants.STATUS_COL, savingsTransactionSheet.getRow(TransactionConstants.STATUS_COL), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,174 @@
/**
* 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.bulkimport.importhandler.sharedaccount;
import com.google.gson.GsonBuilder;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.SharedAccountsConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountChargeData;
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
public class SharedAccountImportHandler implements ImportHandler {
private Workbook workbook;
private List<ShareAccountData> shareAccountDataList;
private List<String>statuses;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public SharedAccountImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.shareAccountDataList=new ArrayList<>();
statuses=new ArrayList<String>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(String locale, String dateFormat) {
Sheet sharedAccountsSheet=workbook.getSheet(TemplatePopulateImportConstants.SHARED_ACCOUNTS_SHEET_NAME);
Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(sharedAccountsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){
Row row;
row=sharedAccountsSheet.getRow(rowIndex);
if (ImportHandlerUtils.isNotImported(row, SharedAccountsConstants.STATUS_COL)){
shareAccountDataList.add(readSharedAccount(row,locale,dateFormat));
}
}
}
private ShareAccountData readSharedAccount(Row row,String locale, String dateFormat) {
String clientName = ImportHandlerUtils.readAsString(SharedAccountsConstants.CLIENT_NAME_COL, row);
Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName);
String productName = ImportHandlerUtils.readAsString(SharedAccountsConstants.PRODUCT_COL, row);
Long productId=ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.SHARED_PRODUCTS_SHEET_NAME),productName);
LocalDate submittedOnDate=ImportHandlerUtils.readAsDate(SharedAccountsConstants.SUBMITTED_ON_COL,row);
String externalId = ImportHandlerUtils.readAsString(SharedAccountsConstants.EXTERNAL_ID_COL, row);
Integer totNoOfShares=ImportHandlerUtils.readAsInt(SharedAccountsConstants.TOTAL_NO_SHARES_COL,row);
Long defaultSavingsAccountId=ImportHandlerUtils.readAsLong(SharedAccountsConstants.DEFAULT_SAVINGS_AC_COL,row);
Integer minimumActivePeriodDays=ImportHandlerUtils.readAsInt(SharedAccountsConstants.MINIMUM_ACTIVE_PERIOD_IN_DAYS_COL,row);
Integer minimumActivePeriodFrequencyType=0;
Integer lockInPeriod=ImportHandlerUtils.readAsInt(SharedAccountsConstants.LOCK_IN_PERIOD_COL,row);
Integer lockPeriodFrequencyType=null;
if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE,row)!=null) {
if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE, row)
.equals(TemplatePopulateImportConstants.FREQUENCY_DAYS)) {
lockPeriodFrequencyType = 0;
} else if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE, row)
.equals(TemplatePopulateImportConstants.FREQUENCY_WEEKS)) {
lockPeriodFrequencyType = 1;
} else if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE, row)
.equals(TemplatePopulateImportConstants.FREQUENCY_MONTHS)) {
lockPeriodFrequencyType = 2;
} else if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE, row)
.equals(TemplatePopulateImportConstants.FREQUENCY_YEARS)) {
lockPeriodFrequencyType = 3;
}
}
LocalDate applicationDate=ImportHandlerUtils.readAsDate(SharedAccountsConstants.APPLICATION_DATE_COL,row);
Boolean allowDividendCalc=ImportHandlerUtils.readAsBoolean(SharedAccountsConstants.ALLOW_DIVIDEND_CALCULATION_FOR_INACTIVE_CLIENTS_COL,row);
List<ShareAccountChargeData> charges=new ArrayList<>();
for (int cellNo=SharedAccountsConstants.CHARGES_NAME_1_COL;cellNo<SharedAccountsConstants.CHARGES_NAME_3_COL;cellNo+=2){
String chargeName=ImportHandlerUtils.readAsString(cellNo,row);
if (chargeName==null||chargeName.equals("0")){
break;
}
Long chargeId=ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.SHARED_PRODUCTS_SHEET_NAME),chargeName);
BigDecimal amount=null;
if(ImportHandlerUtils.readAsDouble(cellNo+1,row)!=null)
amount=BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(cellNo+1,row));
ShareAccountChargeData shareAccountChargeData=new ShareAccountChargeData(chargeId,amount);
charges.add(shareAccountChargeData);
}
String status=ImportHandlerUtils.readAsString(SharedAccountsConstants.STATUS_COL,row);
statuses.add(status);
return ShareAccountData.importInstance(clientId,productId,totNoOfShares,externalId,submittedOnDate,minimumActivePeriodDays,
minimumActivePeriodFrequencyType,lockInPeriod,lockPeriodFrequencyType,applicationDate,allowDividendCalc,charges,
defaultSavingsAccountId,row.getRowNum(),locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet sharedAccountsSheet=workbook.getSheet(TemplatePopulateImportConstants.SHARED_ACCOUNTS_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
for (ShareAccountData shareAccountData: shareAccountDataList) {
try {
String payload=gsonBuilder.create().toJson(shareAccountData);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createAccount("share")//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = sharedAccountsSheet.getRow(shareAccountData.getRowIndex())
.createCell(SharedAccountsConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(sharedAccountsSheet,shareAccountData.getRowIndex(),errorMessage,SharedAccountsConstants.STATUS_COL);
}
}
sharedAccountsSheet.setColumnWidth(SharedAccountsConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(SharedAccountsConstants.STATUS_COL, sharedAccountsSheet.getRow(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT),
TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,124 @@
/**
* 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.bulkimport.importhandler.staff;
import com.google.gson.GsonBuilder;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.StaffConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.organisation.staff.data.StaffData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class StaffImportHandler implements ImportHandler {
private List<StaffData> staffList;
private Workbook workbook;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public StaffImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
this.staffList=new ArrayList<>();
readExcelFile(locale,dateFormat);
return importEntity(dateFormat);
}
public void readExcelFile(String locale, String dateFormat) {
Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.EMPLOYEE_SHEET_NAME);
Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(staffSheet,TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){
Row row;
row=staffSheet.getRow(rowIndex);
if ( ImportHandlerUtils.isNotImported(row, StaffConstants.STATUS_COL)){
staffList.add(readStaff(row,locale,dateFormat));
}
}
}
private StaffData readStaff(Row row,String locale, String dateFormat) {
String officeName = ImportHandlerUtils.readAsString( StaffConstants.OFFICE_NAME_COL, row);
Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName);
String firstName = ImportHandlerUtils.readAsString(StaffConstants.FIRST_NAME_COL, row);
String lastName = ImportHandlerUtils.readAsString(StaffConstants.LAST_NAME_COL, row);
Boolean isLoanOfficer=ImportHandlerUtils.readAsBoolean(StaffConstants.IS_LOAN_OFFICER,row);
String mobileNo=null;
if (ImportHandlerUtils.readAsLong(StaffConstants.MOBILE_NO_COL,row)!=null)
mobileNo=ImportHandlerUtils.readAsLong(StaffConstants.MOBILE_NO_COL,row).toString();
LocalDate joinedOnDate=ImportHandlerUtils.readAsDate(StaffConstants.JOINED_ON_COL,row);
String externalId=ImportHandlerUtils.readAsString(StaffConstants.EXTERNAL_ID_COL,row);
Boolean isActive=ImportHandlerUtils.readAsBoolean(StaffConstants.IS_ACTIVE_COL,row);
return StaffData.importInstance(externalId,firstName,lastName,mobileNo,officeId,isLoanOfficer,isActive,
joinedOnDate,row.getRowNum(),locale,dateFormat);
}
public Count importEntity(String dateFormat) {
Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.EMPLOYEE_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
for (StaffData staff: staffList) {
try {
String payload=gsonBuilder.create().toJson(staff);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createStaff()//
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = staffSheet.getRow(staff.getRowIndex()).createCell(StaffConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(staffSheet,staff.getRowIndex(),errorMessage,StaffConstants.STATUS_COL);
}
}
staffSheet.setColumnWidth(StaffConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(StaffConstants.STATUS_COL, staffSheet.getRow(0), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,137 @@
/**
* 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.bulkimport.importhandler.users;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.UserConstants;
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.useradministration.data.AppUserData;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class UserImportHandler implements ImportHandler{
private Workbook workbook;
private List<AppUserData> users;
private List<String> statuses;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public UserImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
this.workbook=workbook;
users=new ArrayList<>();
statuses=new ArrayList<>();
readExcelFile();
return importEntity(dateFormat);
}
public void readExcelFile() {
Sheet usersSheet = workbook.getSheet(TemplatePopulateImportConstants.USER_SHEET_NAME);
Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(usersSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
Row row;
row = usersSheet.getRow(rowIndex);
if(ImportHandlerUtils.isNotImported(row, UserConstants.STATUS_COL)) {
users.add(readUsers(row));
}
}
}
private AppUserData readUsers(Row row) {
String officeName = ImportHandlerUtils.readAsString(UserConstants.OFFICE_NAME_COL, row);
Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName);
String staffName = ImportHandlerUtils.readAsString(UserConstants.STAFF_NAME_COL, row);
Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName);
String userName=ImportHandlerUtils.readAsString(UserConstants.USER_NAME_COL,row);
String firstName=ImportHandlerUtils.readAsString(UserConstants.FIRST_NAME_COL,row);
String lastName=ImportHandlerUtils.readAsString(UserConstants.LAST_NAME_COL,row);
String email=ImportHandlerUtils.readAsString(UserConstants.EMAIL_COL,row);
Boolean autoGenPw=ImportHandlerUtils.readAsBoolean(UserConstants.AUTO_GEN_PW_COL,row);
Boolean overridepw=ImportHandlerUtils.readAsBoolean(UserConstants.OVERRIDE_PW_EXPIRY_POLICY_COL,row);
String status=ImportHandlerUtils.readAsString(UserConstants.STATUS_COL,row);
statuses.add(status);
List<Long> rolesIds=new ArrayList<>();
for (int cellNo=UserConstants.ROLE_NAME_START_COL;cellNo<UserConstants.ROLE_NAME_END_COL;cellNo++){
String roleName=ImportHandlerUtils.readAsString(cellNo,row);
if (roleName==null)
break;
Long roleId=ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.ROLES_SHEET_NAME),roleName);
if (!rolesIds.contains(roleId))
rolesIds.add(roleId);
}
return AppUserData.importInstance(officeId,staffId,userName,firstName,lastName,email,
autoGenPw,overridepw,rolesIds,row.getRowNum());
}
public Count importEntity(String dateFormat) {
Sheet userSheet=workbook.getSheet(TemplatePopulateImportConstants.USER_SHEET_NAME);
int successCount=0;
int errorCount=0;
String errorMessage="";
GsonBuilder gsonBuilder=new GsonBuilder();
for (AppUserData user:users){
try {
JsonObject userJsonob=gsonBuilder.create().toJsonTree(user).getAsJsonObject();
String payload=userJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createUser() //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = userSheet.getRow(user.getRowIndex()).createCell(UserConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
}catch (RuntimeException ex){
errorCount++;
ex.printStackTrace();
errorMessage=ImportHandlerUtils.getErrorMessage(ex);
ImportHandlerUtils.writeErrorMessage(userSheet,user.getRowIndex(),errorMessage,UserConstants.STATUS_COL);
}
}
userSheet.setColumnWidth(UserConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(UserConstants.STATUS_COL, userSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
return Count.instance(successCount,errorCount);
}
}
@@ -0,0 +1,161 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.portfolio.client.data.ClientData;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
public abstract class AbstractWorkbookPopulator implements WorkbookPopulator {
protected void writeInt(int colIndex, Row row, int value) {
row.createCell(colIndex).setCellValue(value);
}
protected void writeLong(int colIndex, Row row, long value) {
row.createCell(colIndex).setCellValue(value);
}
protected void writeString(int colIndex, Row row, String value) {
row.createCell(colIndex).setCellValue(value);
}
protected void writeBoolean(int colIndex,Row row,Boolean value){
row.createCell(colIndex).setCellValue(value);
}
protected void writeDouble(int colIndex, Row row, double value) {
row.createCell(colIndex).setCellValue(value);
}
protected void writeFormula(int colIndex, Row row, String formula) {
row.createCell(colIndex).setCellType(Cell.CELL_TYPE_FORMULA);
row.createCell(colIndex).setCellFormula(formula);
}
protected void writeDate(int colIndex, Row row, String value, CellStyle dateCellStyle,String dateFormat) {
try {
SimpleDateFormat formatinDB=null;
if (value.matches("\\d{4}-\\d{1,2}-\\d{1,2}")){
formatinDB=new SimpleDateFormat("yyyy-mm-dd");
}else if (value.matches("\\d{1,2}/\\d{1,2}/\\d{4}")){
formatinDB=new SimpleDateFormat("dd/mm/yyyy");
}else if(value.matches("\\d{1,2} \\w{3,12} \\d{4}")){
formatinDB=new SimpleDateFormat("dd MMMM yyyy");
}
Date date1=formatinDB.parse(value);
SimpleDateFormat expectedFormat=new SimpleDateFormat(dateFormat);
Date date2=expectedFormat.parse(expectedFormat.format(date1));
Calendar cal = Calendar.getInstance();
cal.setTime(date2);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date dateWithoutTime = cal.getTime();
row.createCell(colIndex).setCellValue(dateWithoutTime);
row.getCell(colIndex).setCellStyle(dateCellStyle);
} catch (ParseException pe) {
throw new IllegalArgumentException("ParseException");
}
}
protected void writeBigDecimal(int colIndex, Row row, BigDecimal value) {
row.createCell(colIndex).setCellValue(value.doubleValue());
}
protected void setOfficeDateLookupTable(Sheet sheet, List<OfficeData> offices, int officeNameCol,
int activationDateCol,String dateFormat) {
if(offices!=null){
Workbook workbook = sheet.getWorkbook();
CellStyle dateCellStyle = workbook.createCellStyle();
short df = workbook.createDataFormat().getFormat(dateFormat);
dateCellStyle.setDataFormat(df);
int rowIndex = 0;
for (OfficeData office : offices) {
Row row = sheet.createRow(++rowIndex);
writeString(officeNameCol, row, office.name().trim().replaceAll("[ )(]", "_"));
writeDate(activationDateCol, row,
"" + office.getOpeningDate().getDayOfMonth() + "/"
+ office.getOpeningDate().getMonthOfYear() + "/" + office.getOpeningDate().getYear(),
dateCellStyle,dateFormat);
}
}
}
protected void setClientAndGroupDateLookupTable(Sheet sheet, List<ClientData> clients,
List<GroupGeneralData> groups, int nameCol, int activationDateCol,boolean containsClientExtId,
String dateFormat) {
Workbook workbook = sheet.getWorkbook();
CellStyle dateCellStyle = workbook.createCellStyle();
short df = workbook.createDataFormat().getFormat(dateFormat);
dateCellStyle.setDataFormat(df);
int rowIndex = 0;
SimpleDateFormat outputFormat = new SimpleDateFormat(dateFormat);
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
if (clients != null){
for (ClientData client : clients) {
Row row = sheet.getRow(++rowIndex);
if (row == null)
row = sheet.createRow(rowIndex);
writeString(nameCol, row, client.displayName().replaceAll("[ )(] ", "_") + "(" + client.id() + ")");
if (client.getActivationDate() != null) {
date = inputFormat.parse(client.getActivationDate().toString());
writeDate(activationDateCol, row, outputFormat.format(date), dateCellStyle,dateFormat);
}
if (containsClientExtId){
if (client.getExternalId()!=null){
writeString(nameCol+1,row,client.getExternalId());
}
}
}
}
if (groups!=null){
for (GroupGeneralData group : groups) {
Row row = sheet.getRow(++rowIndex);
if (row == null)
row = sheet.createRow(rowIndex);
writeString(nameCol, row, group.getName().replaceAll("[ )(] ", "_"));
date = inputFormat.parse(group.getActivationDate().toString());
writeDate(activationDateCol, row, outputFormat.format(date), dateCellStyle,dateFormat);
}
}
} catch (ParseException e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,123 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.portfolio.group.data.CenterData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CenterSheetPopulator extends AbstractWorkbookPopulator {
private List<CenterData> allCenters;
private List<OfficeData> offices;
private Map<String, ArrayList<String>> officeToCenters;
private Map<Integer, Integer[]> officeNameToBeginEndIndexesOfCenters;
private Map<String, Long> centerNameToCenterId;
private static final int OFFICE_NAME_COL = 0;
private static final int CENTER_NAME_COL = 1;
private static final int CENTER_ID_COL = 2;
public CenterSheetPopulator(List<CenterData> centers, List<OfficeData> offices) {
this.allCenters = centers;
this.offices = offices;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet centerSheet = workbook.createSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME);
setLayout(centerSheet);
setOfficeToCentersMap();
centerNameToCenterIdMap();
populateCentersByOfficeName(centerSheet);
centerSheet.protectSheet("");
}
private void centerNameToCenterIdMap() {
centerNameToCenterId = new HashMap<String, Long>();
for (CenterData centerData : allCenters) {
centerNameToCenterId.put(centerData.getName(), centerData.getId());
}
}
private void populateCentersByOfficeName(Sheet centerSheet) {
int rowIndex = 1, officeIndex = 0, startIndex = 1;
officeNameToBeginEndIndexesOfCenters = new HashMap<Integer, Integer[]>();
Row row = centerSheet.createRow(rowIndex);
for (OfficeData office : offices) {
startIndex = rowIndex + 1;
writeString(OFFICE_NAME_COL, row, office.name());
ArrayList<String> centersList = new ArrayList<String>();
if (officeToCenters.containsKey(office.name().trim().replaceAll("[ )(]", "_"))){
centersList = officeToCenters.get(office.name().trim().replaceAll("[ )(]", "_"));
if (!centersList.isEmpty()) {
for (String centerName : centersList) {
writeString(CENTER_NAME_COL, row, centerName);
writeLong(CENTER_ID_COL, row, centerNameToCenterId.get(centerName));
row = centerSheet.createRow(++rowIndex);
}
officeNameToBeginEndIndexesOfCenters.put(officeIndex++, new Integer[] { startIndex, rowIndex });
} else {
officeNameToBeginEndIndexesOfCenters.put(officeIndex++, new Integer[] { startIndex, rowIndex + 1 });
}
}
}
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
for (int colIndex = 0; colIndex <= 10; colIndex++)
worksheet.setColumnWidth(colIndex, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(OFFICE_NAME_COL, rowHeader, "Office Names");
writeString(CENTER_NAME_COL, rowHeader, "Center Names");
writeString(CENTER_ID_COL, rowHeader, "Center ID");
}
private void setOfficeToCentersMap() {
officeToCenters = new HashMap<>();
for (CenterData center : allCenters) {
add(center.getOfficeName().trim().replaceAll("[ )(]", "_"), center.getName().trim());
}
}
// Guava Multi-map can reduce this.
private void add(String key, String value) {
ArrayList<String> values = officeToCenters.get(key);
if (values == null) {
values = new ArrayList<>();
}
values.add(value);
officeToCenters.put(key, values);
}
public Map<Integer, Integer[]> getOfficeNameToBeginEndIndexesOfCenters() {
return officeNameToBeginEndIndexesOfCenters;
}
}
@@ -0,0 +1,144 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.portfolio.client.data.ClientData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ClientSheetPopulator extends AbstractWorkbookPopulator {
private List<ClientData> allClients;
private List<OfficeData> officesDataList;
private Map<String, ArrayList<String>> officeToClients;
private Map<Integer, Integer[]> officeNameToBeginEndIndexesOfClients;
private Map<String, Long> clientNameToClientId;
private Map<String, Long> clientNameToSavingsAccountIds;
private static final int OFFICE_NAME_COL = 0;
private static final int CLIENT_NAME_COL = 1;
private static final int CLIENT_ID_COL = 2;
public ClientSheetPopulator(final List<ClientData> clients, final List<OfficeData> Offices) {
this.allClients = clients;
this.officesDataList = Offices;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet clientSheet = workbook.createSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME);
setLayout(clientSheet);
setOfficeToClientsMap();
setClientNameToClientIdMap();
populateClientsByOfficeName(clientSheet);
clientSheet.protectSheet("");
setClientNameToSavingsAccountsIdsMap();
}
private void setClientNameToClientIdMap() {
clientNameToClientId = new HashMap<>();
for (ClientData clientData : allClients) {
clientNameToClientId.put(clientData.displayName().trim() + "(" + clientData.id() + ")",
clientData.id());
}
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
worksheet.setColumnWidth(OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
for (int colIndex = 1; colIndex <= 10; colIndex++)
worksheet.setColumnWidth(colIndex, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(OFFICE_NAME_COL, rowHeader, "Office Names");
writeString(CLIENT_NAME_COL, rowHeader, "Client Names");
writeString(CLIENT_ID_COL, rowHeader, "Client ID");
}
private void setOfficeToClientsMap() {
officeToClients = new HashMap<>();
for (ClientData person : allClients) {
addToOfficeClientMap(person.getOfficeName().trim().replaceAll("[ )(]", "_"),
person.displayName().trim() + "(" + person.id() + ")");
}
}
private void setClientNameToSavingsAccountsIdsMap(){
clientNameToSavingsAccountIds=new HashMap<>();
for (ClientData client: allClients) {
clientNameToSavingsAccountIds.put(client.displayName().trim() + "(" + client.id() + ")",client.getSavingsAccountId());
}
}
// Guava Multi-map can reduce this.
private void addToOfficeClientMap(String key, String value) {
ArrayList<String> values = officeToClients.get(key);
if (values == null) {
values = new ArrayList<String>();
}
values.add(value);
officeToClients.put(key, values);
}
private void populateClientsByOfficeName(Sheet clientSheet) {
int rowIndex = 1, startIndex = 1, officeIndex = 0;
officeNameToBeginEndIndexesOfClients = new HashMap<>();
Row row = clientSheet.createRow(rowIndex);
for (OfficeData office : officesDataList) {
startIndex = rowIndex + 1;
writeString(OFFICE_NAME_COL, row, office.name());
ArrayList<String> clientList = new ArrayList<String>();
if (officeToClients.containsKey(office.name().trim().replaceAll("[ )(]", "_")))
clientList = officeToClients.get(office.name().trim().replaceAll("[ )(]", "_"));
if (!clientList.isEmpty()) {
for (String clientName : clientList) {
writeString(CLIENT_NAME_COL, row, clientName);
writeLong(CLIENT_ID_COL, row, clientNameToClientId.get(clientName));
row = clientSheet.createRow(++rowIndex);
}
officeNameToBeginEndIndexesOfClients.put(officeIndex++, new Integer[] { startIndex, rowIndex });
} else
officeIndex++;
}
}
public List<ClientData> getClients() {
return allClients;
}
public Integer getClientsSize() {
return allClients.size();
}
public Map<Integer, Integer[]> getOfficeNameToBeginEndIndexesOfClients() {
return officeNameToBeginEndIndexesOfClients;
}
public Map<String, Long> getClientNameToSavingsAccountIds() {
return clientNameToSavingsAccountIds;
}
}
@@ -0,0 +1,116 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.fund.data.FundData;
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.List;
public class ExtrasSheetPopulator extends AbstractWorkbookPopulator {
private List<FundData> funds;
private List<PaymentTypeData> paymentTypes;
private List<CurrencyData> currencies;
private static final int FUND_ID_COL = 0;
private static final int FUND_NAME_COL = 1;
private static final int PAYMENT_TYPE_ID_COL = 2;
private static final int PAYMENT_TYPE_NAME_COL = 3;
private static final int CURRENCY_CODE_COL = 4;
private static final int CURRENCY_NAME_COL = 5;
public ExtrasSheetPopulator(List<FundData> funds, List<PaymentTypeData> paymentTypes,
List<CurrencyData> currencies) {
this.funds = funds;
this.paymentTypes = paymentTypes;
this.currencies = currencies;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
int fundRowIndex = 1;
Sheet extrasSheet = workbook.createSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME);
setLayout(extrasSheet);
for (FundData fund : funds) {
Row row = extrasSheet.createRow(fundRowIndex++);
writeLong(FUND_ID_COL, row, fund.getId());
writeString(FUND_NAME_COL, row, fund.getName());
}
int paymentTypeRowIndex = 1;
for (PaymentTypeData paymentType : paymentTypes) {
Row row;
if (paymentTypeRowIndex < fundRowIndex)
row = extrasSheet.getRow(paymentTypeRowIndex++);
else
row = extrasSheet.createRow(paymentTypeRowIndex++);
writeLong(PAYMENT_TYPE_ID_COL, row, paymentType.getId());
writeString(PAYMENT_TYPE_NAME_COL, row, paymentType.getName().trim().replaceAll("[ )(]", "_"));
}
int currencyCodeRowIndex = 1;
for (CurrencyData currencies : currencies) {
Row row;
if (currencyCodeRowIndex < paymentTypeRowIndex)
row = extrasSheet.getRow(currencyCodeRowIndex++);
else
row = extrasSheet.createRow(currencyCodeRowIndex++);
writeString(CURRENCY_NAME_COL, row, currencies.getName().trim().replaceAll("[ )(]", "_"));
writeString(CURRENCY_CODE_COL, row, currencies.code());
}
extrasSheet.protectSheet("");
}
private void setLayout(Sheet worksheet) {
worksheet.setColumnWidth(FUND_ID_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(FUND_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(PAYMENT_TYPE_ID_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(PAYMENT_TYPE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(CURRENCY_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(CURRENCY_CODE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
writeString(FUND_ID_COL, rowHeader, "Fund ID");
writeString(FUND_NAME_COL, rowHeader, "Name");
writeString(PAYMENT_TYPE_ID_COL, rowHeader, "Payment Type ID");
writeString(PAYMENT_TYPE_NAME_COL, rowHeader, "Payment Type Name");
writeString(CURRENCY_NAME_COL, rowHeader, "Currency Type ");
writeString(CURRENCY_CODE_COL, rowHeader, "Currency Code ");
}
public Integer getFundsSize() {
return funds.size();
}
public Integer getPaymentTypesSize() {
return paymentTypes.size();
}
public Integer getCurrenciesSize() {
return currencies.size();
}
}
@@ -0,0 +1,173 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.savings.data.FixedDepositProductData;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.List;
public class FixedDepositProductSheetPopulator extends AbstractWorkbookPopulator {
List<FixedDepositProductData> products;
private static final int ID_COL = 0;
private static final int NAME_COL = 1;
private static final int SHORT_NAME_COL = 2;
private static final int NOMINAL_ANNUAL_INTEREST_RATE_COL = 3;
private static final int INTEREST_COMPOUNDING_PERIOD_COL = 4;
private static final int INTEREST_POSTING_PERIOD_COL = 5;
private static final int INTEREST_CALCULATION_COL = 6;
private static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 7;
private static final int LOCKIN_PERIOD_COL = 8;
private static final int LOCKIN_PERIOD_FREQUENCY_COL = 9;
private static final int CURRENCY_COL = 10;
private static final int MIN_DEPOSIT_COL = 11;
private static final int MAX_DEPOSIT_COL = 12;
private static final int DEPOSIT_COL = 13;
private static final int MIN_DEPOSIT_TERM_COL = 14;
private static final int MIN_DEPOSIT_TERM_TYPE_COL = 15;
private static final int MAX_DEPOSIT_TERM_COL = 16;
private static final int MAX_DEPOSIT_TERM_TYPE_COL = 17;
private static final int PRECLOSURE_PENAL_APPLICABLE_COL = 18;
private static final int PRECLOSURE_PENAL_INTEREST_COL = 19;
private static final int PRECLOSURE_INTEREST_TYPE_COL = 20;
private static final int IN_MULTIPLES_OF_DEPOSIT_TERM_COL = 21;
private static final int IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL = 22;
public FixedDepositProductSheetPopulator(List<FixedDepositProductData> fixedDepositProducts) {
this.products =fixedDepositProducts;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
int rowIndex = 1;
Sheet productSheet = workbook.createSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
setLayout(productSheet);
CellStyle dateCellStyle = workbook.createCellStyle();
short df = workbook.createDataFormat().getFormat(dateFormat);
dateCellStyle.setDataFormat(df);
for(FixedDepositProductData product : products) {
Row row = productSheet.createRow(rowIndex++);
writeLong(ID_COL, row, product.getId());
writeString(NAME_COL, row, product.getName().trim().replaceAll("[ )(]", "_"));
writeString(SHORT_NAME_COL, row, product.getShortName().trim().replaceAll("[ )(]", "_"));
writeBigDecimal(NOMINAL_ANNUAL_INTEREST_RATE_COL, row, product.getNominalAnnualInterestRate());
writeString(INTEREST_COMPOUNDING_PERIOD_COL, row, product.getInterestCompoundingPeriodType().getValue());
writeString(INTEREST_POSTING_PERIOD_COL, row, product.getInterestPostingPeriodType().getValue());
writeString(INTEREST_CALCULATION_COL, row, product.getInterestCalculationType().getValue());
writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, product.getInterestCalculationDaysInYearType().getValue());
writeBoolean(PRECLOSURE_PENAL_APPLICABLE_COL, row, product.isPreClosurePenalApplicable());
writeInt(MIN_DEPOSIT_TERM_COL, row, product.getMinDepositTerm());
writeString(MIN_DEPOSIT_TERM_TYPE_COL, row, product.getMinDepositTermType().getValue());
if(product.getMinDepositAmount() != null)
writeBigDecimal(MIN_DEPOSIT_COL, row, product.getMinDepositAmount());
if(product.getMaxDepositAmount() != null)
writeBigDecimal(MAX_DEPOSIT_COL, row, product.getMaxDepositAmount());
if(product.getDepositAmount() != null)
writeBigDecimal(DEPOSIT_COL, row, product.getDepositAmount());
if(product.getMaxDepositTerm() != null)
writeInt(MAX_DEPOSIT_TERM_COL, row, product.getMaxDepositTerm());
if(product.getInMultiplesOfDepositTerm() != null)
writeInt(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, row, product.getInMultiplesOfDepositTerm());
if(product.getPreClosurePenalInterest() != null)
writeBigDecimal(PRECLOSURE_PENAL_INTEREST_COL, row, product.getPreClosurePenalInterest());
if(product.getMaxDepositTermType() != null)
writeString(MAX_DEPOSIT_TERM_TYPE_COL, row, product.getMaxDepositTermType().getValue());
if(product.getPreClosurePenalInterestOnType() != null)
writeString(PRECLOSURE_INTEREST_TYPE_COL, row, product.getPreClosurePenalInterestOnType().getValue());
if(product.getInMultiplesOfDepositTermType() != null)
writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, row, product.getInMultiplesOfDepositTermType().getValue());
if(product.getLockinPeriodFrequency() != null)
writeInt(LOCKIN_PERIOD_COL, row, product.getLockinPeriodFrequency());
if(product.getLockinPeriodFrequencyType() != null)
writeString(LOCKIN_PERIOD_FREQUENCY_COL, row, product.getLockinPeriodFrequencyType().getValue());
CurrencyData currency = product.getCurrency();
writeString(CURRENCY_COL, row, currency.code());
}
productSheet.protectSheet("");
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(SHORT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(NOMINAL_ANNUAL_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CURRENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(PRECLOSURE_PENAL_APPLICABLE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(PRECLOSURE_PENAL_INTEREST_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(PRECLOSURE_INTEREST_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(ID_COL, rowHeader, "ID");
writeString(NAME_COL, rowHeader, "Name");
writeString(SHORT_NAME_COL, rowHeader, "Short Name");
writeString(NOMINAL_ANNUAL_INTEREST_RATE_COL, rowHeader, "Interest");
writeString(INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period");
writeString(INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period");
writeString(INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated Using");
writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days In Year");
writeString(LOCKIN_PERIOD_COL, rowHeader, "Locked In For");
writeString(LOCKIN_PERIOD_FREQUENCY_COL, rowHeader, "Frequency");
writeString(CURRENCY_COL, rowHeader, "Currency");
writeString(MIN_DEPOSIT_COL, rowHeader, "Min Deposit");
writeString(MAX_DEPOSIT_COL, rowHeader, "Max Deposit");
writeString(DEPOSIT_COL, rowHeader, "Deposit");
writeString(MIN_DEPOSIT_TERM_COL, rowHeader, "Min Deposit Term");
writeString(MAX_DEPOSIT_TERM_COL, rowHeader, "Max Deposit Term");
writeString(MIN_DEPOSIT_TERM_TYPE_COL, rowHeader, "Min Deposit Term Type");
writeString(MAX_DEPOSIT_TERM_TYPE_COL, rowHeader, "Max Deposit Term Type");
writeString(PRECLOSURE_PENAL_APPLICABLE_COL, rowHeader, "Preclosure Penal Applicable");
writeString(PRECLOSURE_PENAL_INTEREST_COL, rowHeader, "Penal Interest");
writeString(PRECLOSURE_INTEREST_TYPE_COL, rowHeader, "Penal Interest Type");
writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, rowHeader, "Multiples of Deposit Term");
writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, rowHeader, "Multiples of Deposit Term Type");
}
public List<FixedDepositProductData> getProducts() {
return products;
}
public Integer getProductsSize() {
return products.size();
}
}
@@ -0,0 +1,71 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.List;
public class GlAccountSheetPopulator extends AbstractWorkbookPopulator {
private List<GLAccountData> allGlAccounts;
private static final int ID_COL = 0;
private static final int ACCOUNT_NAME_COL = 1;
public GlAccountSheetPopulator(List<GLAccountData> glAccounts) {
this.allGlAccounts = glAccounts;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
int rowIndex = 1;
Sheet glAccountSheet = workbook.createSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME);
setLayout(glAccountSheet);
populateglAccounts(glAccountSheet, rowIndex);
glAccountSheet.protectSheet("");
}
private void setLayout(Sheet worksheet) {
worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ACCOUNT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
writeString(ID_COL, rowHeader, "Gl Account ID");
writeString(ACCOUNT_NAME_COL, rowHeader, "Gl Account Name");
}
private void populateglAccounts(Sheet GlAccountSheet, int rowIndex) {
for (GLAccountData glAccount : allGlAccounts) {
Row row = GlAccountSheet.createRow(rowIndex);
writeLong(ID_COL, row, glAccount.getId());
writeString(ACCOUNT_NAME_COL, row, glAccount.getName().trim().replaceAll("[ )(]", "_"));
rowIndex++;
}
}
public Integer getGlAccountNamesSize() {
return allGlAccounts.size();
}
}
@@ -0,0 +1,126 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GroupSheetPopulator extends AbstractWorkbookPopulator {
private List<GroupGeneralData> groups;
private List<OfficeData> offices;
private Map<String, ArrayList<String>> officeToGroups;
private Map<Integer, Integer[]> officeNameToBeginEndIndexesOfGroups;
private Map<String,Long> groupNameToGroupId;
private static final int OFFICE_NAME_COL = 0;
private static final int GROUP_NAME_COL = 1;
private static final int GROUP_ID_COL = 2;
public GroupSheetPopulator(final List<GroupGeneralData> groups, final List<OfficeData> offices) {
this.groups = groups;
this.offices = offices;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet groupSheet = workbook.createSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME);
setLayout(groupSheet);
setGroupNameToGroupIdMap();
setOfficeToGroupsMap();
populateGroupsByOfficeName(groupSheet);
groupSheet.protectSheet("");
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
for (int colIndex = 0; colIndex <= 10; colIndex++)
worksheet.setColumnWidth(colIndex, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(OFFICE_NAME_COL, rowHeader, "Office Names");
writeString(GROUP_NAME_COL, rowHeader, "Group Names");
writeString(GROUP_ID_COL, rowHeader, "Group ID");
}
private void setOfficeToGroupsMap() {
officeToGroups = new HashMap<>();
for (GroupGeneralData group : groups) {
add(group.getOfficeName().trim().replaceAll("[ )(]", "_"), group.getName().trim());
}
}
//Guava Multi-map can reduce this.
private void add(String key, String value) {
ArrayList<String> values = officeToGroups.get(key);
if (values == null) {
values = new ArrayList<>();
}
values.add(value);
officeToGroups.put(key, values);
}
private void populateGroupsByOfficeName(Sheet groupSheet) {
int rowIndex = 1, officeIndex = 0, startIndex = 1;
officeNameToBeginEndIndexesOfGroups = new HashMap<>();
Row row = groupSheet.createRow(rowIndex);
for(OfficeData office : offices) {
startIndex = rowIndex+1;
writeString(OFFICE_NAME_COL, row, office.name());
ArrayList<String> groupsList = new ArrayList<>();
if(officeToGroups.containsKey(office.name().trim().replaceAll("[ )(]", "_")))
groupsList = officeToGroups.get(office.name().trim().replaceAll("[ )(]", "_"));
if(!groupsList.isEmpty()) {
for(String groupName : groupsList) {
writeString(GROUP_NAME_COL, row, groupName);
writeLong(GROUP_ID_COL, row, groupNameToGroupId.get(groupName));
row = groupSheet.createRow(++rowIndex);
}
officeNameToBeginEndIndexesOfGroups.put(officeIndex++, new Integer[]{startIndex, rowIndex});
}
else {
officeNameToBeginEndIndexesOfGroups.put(officeIndex++, new Integer[]{startIndex, rowIndex+1});
}
}
}
public List<GroupGeneralData> getGroups() {
return groups;
}
public Integer getGroupsSize() {
return groups.size();
}
public Map<Integer, Integer[]> getOfficeNameToBeginEndIndexesOfGroups() {
return officeNameToBeginEndIndexesOfGroups;
}
private void setGroupNameToGroupIdMap(){
groupNameToGroupId=new HashMap<String,Long>();
for (GroupGeneralData group : groups) {
groupNameToGroupId.put(group.getName().trim(), group.getId());
}
}
}
@@ -0,0 +1,199 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.List;
public class LoanProductSheetPopulator extends AbstractWorkbookPopulator {
private List<LoanProductData> products;
private static final int ID_COL = 0;
private static final int NAME_COL = 1;
private static final int FUND_NAME_COL = 2;
private static final int PRINCIPAL_COL = 3;
private static final int MIN_PRINCIPAL_COL = 4;
private static final int MAX_PRINCIPAL_COL = 5;
private static final int NO_OF_REPAYMENTS_COL = 6;
private static final int MIN_REPAYMENTS_COL = 7;
private static final int MAX_REPAYMENTS_COL = 8;
private static final int REPAYMENT_EVERY_COL = 9;
private static final int REPAYMENT_FREQUENCY_COL = 10;
private static final int INTEREST_RATE_COL = 11;
private static final int MIN_INTEREST_RATE_COL = 12;
private static final int MAX_INTEREST_RATE_COL = 13;
private static final int INTEREST_RATE_FREQUENCY_COL = 14;
private static final int AMORTIZATION_TYPE_COL = 15;
private static final int INTEREST_TYPE_COL = 16;
private static final int INTEREST_CALCULATION_PERIOD_TYPE_COL = 17;
private static final int IN_ARREARS_TOLERANCE_COL = 18;
private static final int TRANSACTION_PROCESSING_STRATEGY_NAME_COL = 19;
private static final int GRACE_ON_PRINCIPAL_PAYMENT_COL = 20;
private static final int GRACE_ON_INTEREST_PAYMENT_COL = 21;
private static final int GRACE_ON_INTEREST_CHARGED_COL = 22;
private static final int START_DATE_COL = 23;
private static final int CLOSE_DATE_COL = 24;
public LoanProductSheetPopulator(List<LoanProductData> products) {
this.products = products;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
int rowIndex = 1;
Sheet productSheet = workbook.createSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
setLayout(productSheet);
CellStyle dateCellStyle = workbook.createCellStyle();
short df = workbook.createDataFormat().getFormat(dateFormat);
dateCellStyle.setDataFormat(df);
for (LoanProductData product : products) {
Row row = productSheet.createRow(rowIndex++);
writeLong(ID_COL, row, product.getId());
writeString(NAME_COL, row, product.getName().trim().replaceAll("[ )(]", "_"));
if (product.getFundName() != null)
writeString(FUND_NAME_COL, row, product.getFundName());
writeBigDecimal(PRINCIPAL_COL, row, product.getPrincipal());
if (product.getMinPrincipal() != null)
writeBigDecimal(MIN_PRINCIPAL_COL, row, product.getMinPrincipal());
else
writeInt(MIN_PRINCIPAL_COL, row, 1);
if (product.getMaxPrincipal() != null)
writeBigDecimal(MAX_PRINCIPAL_COL, row, product.getMaxPrincipal());
else
writeInt(MAX_PRINCIPAL_COL, row, 999999999);
writeInt(NO_OF_REPAYMENTS_COL, row, product.getNumberOfRepayments());
if (product.getMinNumberOfRepayments() != null)
writeInt(MIN_REPAYMENTS_COL, row, product.getMinNumberOfRepayments());
else
writeInt(MIN_REPAYMENTS_COL, row, 1);
if (product.getMaxNumberOfRepayments() != null)
writeInt(MAX_REPAYMENTS_COL, row, product.getMaxNumberOfRepayments());
else
writeInt(MAX_REPAYMENTS_COL, row, 999999999);
writeInt(REPAYMENT_EVERY_COL, row, product.getRepaymentEvery());
writeString(REPAYMENT_FREQUENCY_COL, row, product.getRepaymentFrequencyType().getValue());
writeBigDecimal(INTEREST_RATE_COL, row, product.getInterestRatePerPeriod());
if (product.getMinInterestRatePerPeriod() != null)
writeBigDecimal(MIN_INTEREST_RATE_COL, row, product.getMinInterestRatePerPeriod());
else
writeInt(MIN_INTEREST_RATE_COL, row, 1);
if (product.getMaxInterestRatePerPeriod() != null)
writeBigDecimal(MAX_INTEREST_RATE_COL, row, product.getMaxInterestRatePerPeriod());
else
writeInt(MAX_INTEREST_RATE_COL, row, 999999999);
writeString(INTEREST_RATE_FREQUENCY_COL, row, product.getInterestRateFrequencyType().getValue());
writeString(AMORTIZATION_TYPE_COL, row, product.getAmortizationType().getValue());
writeString(INTEREST_TYPE_COL, row, product.getInterestType().getValue());
writeString(INTEREST_CALCULATION_PERIOD_TYPE_COL, row,
product.getInterestCalculationPeriodType().getValue());
if (product.getInArrearsTolerance() != null)
writeBigDecimal(IN_ARREARS_TOLERANCE_COL, row, product.getInArrearsTolerance());
writeString(TRANSACTION_PROCESSING_STRATEGY_NAME_COL, row, product.getTransactionProcessingStrategyName());
if (product.getGraceOnPrincipalPayment() != null)
writeInt(GRACE_ON_PRINCIPAL_PAYMENT_COL, row, product.getGraceOnPrincipalPayment());
if (product.getGraceOnInterestPayment() != null)
writeInt(GRACE_ON_INTEREST_PAYMENT_COL, row, product.getGraceOnInterestPayment());
if (product.getGraceOnInterestCharged() != null)
writeInt(GRACE_ON_INTEREST_CHARGED_COL, row, product.getGraceOnInterestCharged());
if (product.getStartDate() != null)
writeDate(START_DATE_COL, row, product.getStartDate().toString(), dateCellStyle,dateFormat);
else
writeDate(START_DATE_COL, row, "1/1/1970", dateCellStyle,dateFormat);
if (product.getCloseDate() != null)
writeDate(CLOSE_DATE_COL, row, product.getCloseDate().toString(), dateCellStyle,dateFormat);
else
writeDate(CLOSE_DATE_COL, row, "1/1/2040", dateCellStyle,dateFormat);
productSheet.protectSheet("");
}
}
private void setLayout(Sheet worksheet) {
worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(FUND_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(NO_OF_REPAYMENTS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_REPAYMENTS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_REPAYMENTS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(REPAYMENT_EVERY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(REPAYMENT_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_RATE_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(AMORTIZATION_TYPE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(INTEREST_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_CALCULATION_PERIOD_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(IN_ARREARS_TOLERANCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(TRANSACTION_PROCESSING_STRATEGY_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(GRACE_ON_PRINCIPAL_PAYMENT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(GRACE_ON_INTEREST_PAYMENT_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(GRACE_ON_INTEREST_CHARGED_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(START_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CLOSE_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
writeString(ID_COL, rowHeader, "ID");
writeString(NAME_COL, rowHeader, "Name");
writeString(FUND_NAME_COL, rowHeader, "Fund");
writeString(PRINCIPAL_COL, rowHeader, "Principal");
writeString(MIN_PRINCIPAL_COL, rowHeader, "Min Principal");
writeString(MAX_PRINCIPAL_COL, rowHeader, "Max Principal");
writeString(NO_OF_REPAYMENTS_COL, rowHeader, "# of Repayments");
writeString(MIN_REPAYMENTS_COL, rowHeader, "Min Repayments");
writeString(MAX_REPAYMENTS_COL, rowHeader, "Max Repayments");
writeString(REPAYMENT_EVERY_COL, rowHeader, "Repayment Every");
writeString(REPAYMENT_FREQUENCY_COL, rowHeader, "Frequency");
writeString(INTEREST_RATE_COL, rowHeader, "Interest");
writeString(MIN_INTEREST_RATE_COL, rowHeader, "Min Interest");
writeString(MAX_INTEREST_RATE_COL, rowHeader, "Max Interest");
writeString(INTEREST_RATE_FREQUENCY_COL, rowHeader, "Frequency");
writeString(AMORTIZATION_TYPE_COL, rowHeader, "Amortization Type");
writeString(INTEREST_TYPE_COL, rowHeader, "Interest Type");
writeString(INTEREST_CALCULATION_PERIOD_TYPE_COL, rowHeader, "Interest Calculation Period");
writeString(IN_ARREARS_TOLERANCE_COL, rowHeader, "In Arrears Tolerance");
writeString(TRANSACTION_PROCESSING_STRATEGY_NAME_COL, rowHeader, "Transaction Processing Strategy");
writeString(GRACE_ON_PRINCIPAL_PAYMENT_COL, rowHeader, "Grace On Principal Payment");
writeString(GRACE_ON_INTEREST_PAYMENT_COL, rowHeader, "Grace on Interest Payment");
writeString(GRACE_ON_INTEREST_CHARGED_COL, rowHeader, "Grace on Interest Charged");
writeString(START_DATE_COL, rowHeader, "Start Date");
writeString(CLOSE_DATE_COL, rowHeader, "End Date");
}
public List<LoanProductData> getProducts(){
return products;
}
public Integer getProductsSize() {
return products.size();
}
}
@@ -0,0 +1,82 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.ArrayList;
import java.util.List;
public class OfficeSheetPopulator extends AbstractWorkbookPopulator {
private List<OfficeData> offices;
private static final int ID_COL = 0;
private static final int OFFICE_NAME_COL = 1;
public OfficeSheetPopulator(final List<OfficeData> offices) {
this.offices = offices;
}
@Override
public void populate(final Workbook workbook,String dateFormat) {
int rowIndex = 1;
Sheet officeSheet = workbook.createSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
setLayout(officeSheet);
populateOffices(officeSheet, rowIndex);
officeSheet.protectSheet("");
}
private void populateOffices(Sheet officeSheet, int rowIndex) {
for (OfficeData office : offices) {
Row row = officeSheet.createRow(rowIndex);
writeLong(ID_COL, row, office.getId());
writeString(OFFICE_NAME_COL, row, office.name().trim().replaceAll("[ )(]", "_"));
rowIndex++;
}
}
private void setLayout(Sheet worksheet) {
worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
writeString(ID_COL, rowHeader, "ID");
writeString(OFFICE_NAME_COL, rowHeader, "Name");
}
public List<OfficeData> getOffices() {
return offices;
}
public List<String> getOfficeNames() {
List<String> officeNames=new ArrayList<>();
for (OfficeData office : offices) {
officeNames.add(office.name());
}
return officeNames;
}
}
@@ -0,0 +1,131 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.organisation.staff.data.StaffData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//import org.apache.commons.collections.CollectionUtils;
public class PersonnelSheetPopulator extends AbstractWorkbookPopulator {
private List<StaffData> personnel;
private List<OfficeData> offices;
// Maintaining the one to many relationship
private Map<String, List<StaffData>> officeToPersonnel;
/*
* Guava Multimap would make this more readable. The value Integer[] contains the beginIndex and
* endIndex for the staff list of each office. Required for applying names in excel.
*/
private Map<Integer, Integer[]> officeNameToBeginEndIndexesOfStaff;
private static final int OFFICE_NAME_COL = 0;
private static final int STAFF_NAME_COL = 1;
private static final int STAFF_ID_COL = 2;
public PersonnelSheetPopulator(List<StaffData> personnel, List<OfficeData> offices) {
this.personnel = personnel;
this.offices = offices;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet staffSheet = workbook.createSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
setLayout(staffSheet);
/*
* This piece of code could have been avoided by making multiple trips to the database for the
* staff of each office but this is more performance efficient
*/
setOfficeToPersonnelMap();
populateStaffByOfficeName(staffSheet);
staffSheet.protectSheet("");
}
private void populateStaffByOfficeName(Sheet staffSheet) {
int rowIndex = 1, startIndex = 1, officeIndex = 0;
officeNameToBeginEndIndexesOfStaff = new HashMap<>();
Row row = staffSheet.createRow(rowIndex);
for (OfficeData office : offices) {
startIndex = rowIndex + 1;
writeString(OFFICE_NAME_COL, row, office.name().trim().replaceAll("[ )(]", "_"));
List<StaffData> staffList =
officeToPersonnel.get(office.name().trim().replaceAll("[ )(]", "_"));
if (staffList!=null){
if (!staffList.isEmpty()) {
for (StaffData staff : staffList) {
writeString(STAFF_NAME_COL, row, staff.getDisplayName());
writeLong(STAFF_ID_COL, row, staff.getId());
row = staffSheet.createRow(++rowIndex);
}
officeNameToBeginEndIndexesOfStaff.put(officeIndex++, new Integer[]{startIndex, rowIndex});
}
}else
officeIndex++;
}
}
private void setOfficeToPersonnelMap() {
officeToPersonnel = new HashMap<>();
for (StaffData person : personnel) {
add(person.getOfficeName().trim().replaceAll("[ )(]", "_"), person);
}
}
// Guava Multi-map can reduce this.
private void add(String key, StaffData value) {
List<StaffData> values = officeToPersonnel.get(key);
if (values == null) {
values = new ArrayList<>();
}
values.add(value);
officeToPersonnel.put(key, values);
}
private void setLayout(Sheet worksheet) {
for (Integer i = 0; i < 3; i++)
worksheet.setColumnWidth(i, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
writeString(OFFICE_NAME_COL, rowHeader, "Office Name");
writeString(STAFF_NAME_COL, rowHeader, "Staff List");
writeString(STAFF_ID_COL, rowHeader, "Staff ID");
}
public Map<Integer, Integer[]> getOfficeNameToBeginEndIndexesOfStaff() {
return officeNameToBeginEndIndexesOfStaff;
}
}
@@ -0,0 +1,190 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.savings.data.RecurringDepositProductData;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.List;
public class RecurringDepositProductSheetPopulator extends AbstractWorkbookPopulator {
private List<RecurringDepositProductData> products;
private static final int ID_COL = 0;
private static final int NAME_COL = 1;
private static final int SHORT_NAME_COL = 2;
private static final int NOMINAL_ANNUAL_INTEREST_RATE_COL = 3;
private static final int INTEREST_COMPOUNDING_PERIOD_COL = 4;
private static final int INTEREST_POSTING_PERIOD_COL = 5;
private static final int INTEREST_CALCULATION_COL = 6;
private static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 7;
private static final int LOCKIN_PERIOD_COL = 8;
private static final int LOCKIN_PERIOD_FREQUENCY_COL = 9;
private static final int CURRENCY_COL = 10;
private static final int MIN_DEPOSIT_COL = 11;
private static final int MAX_DEPOSIT_COL = 12;
private static final int DEPOSIT_COL = 13;
private static final int MIN_DEPOSIT_TERM_COL = 14;
private static final int MIN_DEPOSIT_TERM_TYPE_COL = 15;
private static final int MAX_DEPOSIT_TERM_COL = 16;
private static final int MAX_DEPOSIT_TERM_TYPE_COL = 17;
private static final int PRECLOSURE_PENAL_APPLICABLE_COL = 18;
private static final int PRECLOSURE_PENAL_INTEREST_COL = 19;
private static final int PRECLOSURE_INTEREST_TYPE_COL = 20;
private static final int IN_MULTIPLES_OF_DEPOSIT_TERM_COL = 21;
private static final int IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL = 22;
private static final int IS_MANDATORY_DEPOSIT_COL = 23;
private static final int ALLOW_WITHDRAWAL_COL = 24;
private static final int ADJUST_ADVANCE_COL = 25;
public RecurringDepositProductSheetPopulator(List<RecurringDepositProductData> recurringDepositProducts) {
this.products=recurringDepositProducts;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
int rowIndex = 1;
Sheet productSheet = workbook.createSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
setLayout(productSheet);
CellStyle dateCellStyle = workbook.createCellStyle();
short df = workbook.createDataFormat().getFormat(dateFormat);
dateCellStyle.setDataFormat(df);
for(RecurringDepositProductData product : products) {
Row row = productSheet.createRow(rowIndex++);
writeLong(ID_COL, row, product.getId());
writeString(NAME_COL, row, product.getName().trim().replaceAll("[ )(]", "_"));
writeString(SHORT_NAME_COL, row, product.getShortName().trim().replaceAll("[ )(]", "_"));
writeBigDecimal(NOMINAL_ANNUAL_INTEREST_RATE_COL, row, product.getNominalAnnualInterestRate());
writeString(INTEREST_COMPOUNDING_PERIOD_COL, row, product.getInterestCompoundingPeriodType().getValue());
writeString(INTEREST_POSTING_PERIOD_COL, row, product.getInterestPostingPeriodType().getValue());
writeString(INTEREST_CALCULATION_COL, row, product.getInterestCalculationType().getValue());
writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, product.getInterestCalculationDaysInYearType().getValue());
writeBoolean(PRECLOSURE_PENAL_APPLICABLE_COL, row, product.isPreClosurePenalApplicable());
writeString(MIN_DEPOSIT_TERM_TYPE_COL, row, product.getMinDepositTermType().getValue());
if(product.getMinDepositAmount() != null)
writeBigDecimal(MIN_DEPOSIT_COL, row, product.getMinDepositAmount());
if(product.getMaxDepositAmount() != null)
writeBigDecimal(MAX_DEPOSIT_COL, row, product.getMaxDepositAmount());
if(product.getDepositAmount() != null)
writeBigDecimal(DEPOSIT_COL, row, product.getDepositAmount());
if(product.getMaxDepositTerm() != null)
writeInt(MAX_DEPOSIT_TERM_COL, row, product.getMaxDepositTerm());
if(product.getMinDepositTerm() != null)
writeInt(MIN_DEPOSIT_TERM_COL, row, product.getMinDepositTerm());
if(product.getInMultiplesOfDepositTerm() != null)
writeInt(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, row, product.getInMultiplesOfDepositTerm());
if(product.getPreClosurePenalInterest() != null)
writeBigDecimal(PRECLOSURE_PENAL_INTEREST_COL, row, product.getPreClosurePenalInterest());
if(product.getMaxDepositTermType() != null)
writeString(MAX_DEPOSIT_TERM_TYPE_COL, row, product.getMaxDepositTermType().getValue());
if(product.getPreClosurePenalInterestOnType() != null)
writeString(PRECLOSURE_INTEREST_TYPE_COL, row, product.getPreClosurePenalInterestOnType().getValue());
if(product.getInMultiplesOfDepositTermType() != null)
writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, row, product.getInMultiplesOfDepositTermType().getValue());
writeBoolean(ALLOW_WITHDRAWAL_COL, row, product.isAllowWithdrawal());
writeBoolean(ADJUST_ADVANCE_COL, row, product.isAdjustAdvanceTowardsFuturePayments());
writeBoolean(IS_MANDATORY_DEPOSIT_COL, row, product.isMandatoryDeposit());
if(product.getLockinPeriodFrequency() != null)
writeInt(LOCKIN_PERIOD_COL, row, product.getLockinPeriodFrequency());
if(product.getLockinPeriodFrequencyType() != null)
writeString(LOCKIN_PERIOD_FREQUENCY_COL, row, product.getLockinPeriodFrequencyType().getValue());
CurrencyData currency = product.getCurrency();
writeString(CURRENCY_COL, row, currency.code());
}
productSheet.protectSheet("");
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(SHORT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(NOMINAL_ANNUAL_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CURRENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MAX_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(PRECLOSURE_PENAL_APPLICABLE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(PRECLOSURE_PENAL_INTEREST_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(PRECLOSURE_INTEREST_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(IS_MANDATORY_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ALLOW_WITHDRAWAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ADJUST_ADVANCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(ID_COL, rowHeader, "ID");
writeString(NAME_COL, rowHeader, "Name");
writeString(SHORT_NAME_COL, rowHeader, "Short Name");
writeString(NOMINAL_ANNUAL_INTEREST_RATE_COL, rowHeader, "Interest");
writeString(INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period");
writeString(INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period");
writeString(INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated Using");
writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days In Year");
writeString(LOCKIN_PERIOD_COL, rowHeader, "Locked In For");
writeString(LOCKIN_PERIOD_FREQUENCY_COL, rowHeader, "Frequency");
writeString(CURRENCY_COL, rowHeader, "Currency");
writeString(MIN_DEPOSIT_COL, rowHeader, "Min Deposit");
writeString(MAX_DEPOSIT_COL, rowHeader, "Max Deposit");
writeString(DEPOSIT_COL, rowHeader, "Deposit");
writeString(MIN_DEPOSIT_TERM_COL, rowHeader, "Min Deposit Term");
writeString(MAX_DEPOSIT_TERM_COL, rowHeader, "Max Deposit Term");
writeString(MIN_DEPOSIT_TERM_TYPE_COL, rowHeader, "Min Deposit Term Type");
writeString(MAX_DEPOSIT_TERM_TYPE_COL, rowHeader, "Max Deposit Term Type");
writeString(PRECLOSURE_PENAL_APPLICABLE_COL, rowHeader, "Preclosure Penal Applicable");
writeString(PRECLOSURE_PENAL_INTEREST_COL, rowHeader, "Penal Interest");
writeString(PRECLOSURE_INTEREST_TYPE_COL, rowHeader, "Penal Interest Type");
writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, rowHeader, "Multiples of Deposit Term");
writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, rowHeader, "Multiples of Deposit Term Type");
writeString(IS_MANDATORY_DEPOSIT_COL, rowHeader, "Is Mandatory Deposit?");
writeString(ALLOW_WITHDRAWAL_COL, rowHeader, "Allow Withdrawal?");
writeString(ADJUST_ADVANCE_COL, rowHeader, "Adjust Advance Towards Future Payments?");
}
public List<RecurringDepositProductData> getProducts() {
return products;
}
public Integer getProductsSize() {
return products.size();
}
}
@@ -0,0 +1,67 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.useradministration.data.RoleData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.List;
public class RoleSheetPopulator extends AbstractWorkbookPopulator {
private List<RoleData>rolesList;
private static final int ID_COL=0;
private static final int ROLE_NAME=1;
public RoleSheetPopulator(List<RoleData> roles) {
this.rolesList=roles;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
int rowIndex = 1;
Sheet rolesSheet = workbook.createSheet(TemplatePopulateImportConstants.ROLES_SHEET_NAME);
setLayout(rolesSheet);
populateRoles(rolesSheet, rowIndex);
rolesSheet.protectSheet("");
}
private void populateRoles(Sheet rolesSheet, int rowIndex) {
for (RoleData role : rolesList) {
Row row = rolesSheet.createRow(rowIndex);
writeLong(ID_COL, row, role.getId());
writeString(ROLE_NAME, row, role.getName().trim().replaceAll("[ )(]", "_"));
rowIndex++;
}
}
private void setLayout(Sheet rolesSheet) {
rolesSheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
rolesSheet.setColumnWidth(ROLE_NAME, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
Row rowHeader = rolesSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
writeString(ID_COL, rowHeader, "ID");
writeString(ROLE_NAME, rowHeader, "Role Name");
}
}
@@ -0,0 +1,84 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.portfolio.client.data.ClientData;
import org.apache.fineract.portfolio.savings.data.SavingsAccountData;
import org.apache.fineract.template.domain.Template;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.List;
import java.util.Map;
public class SavingsAccountSheetPopulator extends AbstractWorkbookPopulator {
private List<SavingsAccountData> savingsAccountDataList;
private Map<ClientData,List<SavingsAccountData>> clientToSavingsMap;
private static final int SAVINGS_ACCOUNT_ID_COL=0;
private static final int SAVING_ACCOUNT_NO=1;
private static final int CURRENCY_COL=2;
private static final int CLIENT_NAME=3;
public SavingsAccountSheetPopulator(List<SavingsAccountData> savingsAccountDataList) {
this.savingsAccountDataList=savingsAccountDataList;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet savingsSheet=workbook.createSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME);
setLayout(savingsSheet);
populateSavingsSheet(savingsSheet);
savingsSheet.protectSheet("");
}
private void populateSavingsSheet(Sheet savingsSheet) {
int rowIndex=1;
for (SavingsAccountData savings: savingsAccountDataList) {
Row row=savingsSheet.createRow(rowIndex++);
writeLong(SAVINGS_ACCOUNT_ID_COL,row,savings.id());
writeString(SAVING_ACCOUNT_NO,row,savings.getAccountNo());
writeString(CURRENCY_COL,row,savings.currency().code());
writeString(CLIENT_NAME,row,savings.getClientName());
}
}
private void setLayout(Sheet savingsSheet) {
Row rowHeader = savingsSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
savingsSheet.setColumnWidth(SAVINGS_ACCOUNT_ID_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(SAVINGS_ACCOUNT_ID_COL,rowHeader,"Savings Account Id");
savingsSheet.setColumnWidth(SAVING_ACCOUNT_NO,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(SAVING_ACCOUNT_NO,rowHeader,"Savings Account No");
savingsSheet.setColumnWidth(CURRENCY_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CURRENCY_COL,rowHeader,"Currency Code");
savingsSheet.setColumnWidth(CLIENT_NAME,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CLIENT_NAME,rowHeader,"Client Name");
}
}
@@ -0,0 +1,136 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.savings.data.SavingsProductData;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.List;
public class SavingsProductSheetPopulator extends AbstractWorkbookPopulator {
private List<SavingsProductData> savingsProducts;
private static final int ID_COL = 0;
private static final int NAME_COL = 1;
private static final int NOMINAL_ANNUAL_INTEREST_RATE_COL = 2;
private static final int INTEREST_COMPOUNDING_PERIOD_COL = 3;
private static final int INTEREST_POSTING_PERIOD_COL = 4;
private static final int INTEREST_CALCULATION_COL = 5;
private static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 6;
private static final int MIN_OPENING_BALANCE_COL = 7;
private static final int LOCKIN_PERIOD_COL = 8;
private static final int LOCKIN_PERIOD_FREQUENCY_COL = 9;
private static final int CURRENCY_COL = 10;
private static final int DECIMAL_PLACES_COL = 11;
private static final int IN_MULTIPLES_OF_COL = 12;
private static final int WITHDRAWAL_FEE_COL = 13;
private static final int ALLOW_OVERDRAFT_COL = 14;
private static final int OVERDRAFT_LIMIT_COL = 15;
public SavingsProductSheetPopulator(List<SavingsProductData> savingsProducts) {
this.savingsProducts=savingsProducts;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
int rowIndex = 1;
Sheet productSheet = workbook.createSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
setLayout(productSheet);
CellStyle dateCellStyle = workbook.createCellStyle();
short df = workbook.createDataFormat().getFormat(dateFormat);
dateCellStyle.setDataFormat(df);
for(SavingsProductData product : savingsProducts) {
Row row = productSheet.createRow(rowIndex++);
writeLong(ID_COL, row, product.getId());
writeString(NAME_COL, row, product.getName().trim().replaceAll("[ )(]", "_"));
writeBigDecimal(NOMINAL_ANNUAL_INTEREST_RATE_COL, row, product.getNominalAnnualInterestRate());
writeString(INTEREST_COMPOUNDING_PERIOD_COL, row, product.getInterestCompoundingPeriodType().getValue());
writeString(INTEREST_POSTING_PERIOD_COL, row, product.getInterestPostingPeriodType().getValue());
writeString(INTEREST_CALCULATION_COL, row, product.getInterestCalculationType().getValue());
writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, product.getInterestCalculationDaysInYearType().getValue());
if(product.getMinRequiredOpeningBalance() != null)
writeBigDecimal(MIN_OPENING_BALANCE_COL, row, product.getMinRequiredOpeningBalance());
if(product.getLockinPeriodFrequency() != null)
writeInt(LOCKIN_PERIOD_COL, row, product.getLockinPeriodFrequency());
if(product.getLockinPeriodFrequencyType() != null)
writeString(LOCKIN_PERIOD_FREQUENCY_COL, row, product.getLockinPeriodFrequencyType().getValue());
CurrencyData currency = product.getCurrency();
writeString(CURRENCY_COL, row, currency.code());
writeInt(DECIMAL_PLACES_COL, row, currency.decimalPlaces());
if(currency.currencyInMultiplesOf() != null)
writeInt(IN_MULTIPLES_OF_COL, row, currency.currencyInMultiplesOf());
writeBoolean(WITHDRAWAL_FEE_COL, row, product.isWithdrawalFeeForTransfers());
writeBoolean(ALLOW_OVERDRAFT_COL, row,product.isAllowOverdraft());
if(product.getOverdraftLimit() != null)
writeBigDecimal(OVERDRAFT_LIMIT_COL, row, product.getOverdraftLimit());
}
productSheet.protectSheet("");
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(NOMINAL_ANNUAL_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(MIN_OPENING_BALANCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CURRENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(DECIMAL_PLACES_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(IN_MULTIPLES_OF_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(WITHDRAWAL_FEE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ALLOW_OVERDRAFT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(OVERDRAFT_LIMIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(ID_COL, rowHeader, "ID");
writeString(NAME_COL, rowHeader, "Name");
writeString(NOMINAL_ANNUAL_INTEREST_RATE_COL, rowHeader, "Interest");
writeString(INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period");
writeString(INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period");
writeString(INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated Using");
writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days In Year");
writeString(MIN_OPENING_BALANCE_COL, rowHeader, "Min Opening Balance");
writeString(LOCKIN_PERIOD_COL, rowHeader, "Locked In For");
writeString(LOCKIN_PERIOD_FREQUENCY_COL, rowHeader, "Frequency");
writeString(CURRENCY_COL, rowHeader, "Currency");
writeString(DECIMAL_PLACES_COL, rowHeader, "Decimal Places");
writeString(IN_MULTIPLES_OF_COL, rowHeader, "In Multiples Of");
writeString(WITHDRAWAL_FEE_COL, rowHeader, "Withdrawal Fee for Transfers?");
writeString(ALLOW_OVERDRAFT_COL, rowHeader, "Apply Overdraft");
writeString(OVERDRAFT_LIMIT_COL, rowHeader, "Overdraft Limit");
}
public List<SavingsProductData> getProducts() {
return savingsProducts;
}
public Integer getProductsSize() {
return savingsProducts.size();
}
}
@@ -0,0 +1,159 @@
/**
* 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.bulkimport.populator;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.charge.data.ChargeData;
import org.apache.fineract.portfolio.shareproducts.data.ShareProductData;
import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.math.BigDecimal;
import java.util.*;
public class SharedProductsSheetPopulator extends AbstractWorkbookPopulator {
private List<ShareProductData> sharedProductDataList;
private List<ChargeData> chargesForSharedProducts;
private Map<Long,Integer[]>productToBeginEndIndexesofCharges;
private static final int PRODUCT_ID=0;
private static final int PRODUCT_NAME_COL = 1;
private static final int CURRENCY_COL = 2;
private static final int DECIMAL_PLACES_COL = 3;
private static final int TODAYS_PRICE_COL = 4;
private static final int CURRENCY_IN_MULTIPLES_COL = 5;
private static final int CHARGES_ID_1_COL = 7;
private static final int CHARGES_NAME_1_COL = 8;
private static final int CHARGES_ID_2_COL = 9;
private static final int CHARGES_NAME_2_COL = 10;
private static final int CHARGES_ID_3_COL = 11;
private static final int CHARGES_NAME_3_COL = 12;
public SharedProductsSheetPopulator(List<ShareProductData> shareProductDataList,List<ChargeData> chargesForShares) {
this.sharedProductDataList=shareProductDataList;
this.chargesForSharedProducts=chargesForShares;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet sharedProductsSheet=workbook.createSheet(TemplatePopulateImportConstants.SHARED_PRODUCTS_SHEET_NAME);
setLayout(sharedProductsSheet);
populateSheet(sharedProductsSheet);
sharedProductsSheet.protectSheet("");
}
private void populateSheet(Sheet sharedProductsSheet) {
int index = 0;
int startIndexCharges = 1;
int endIndexCharges = 0;
productToBeginEndIndexesofCharges = new HashMap<>();
for (ShareProductData productData : sharedProductDataList) {
Row row = sharedProductsSheet.createRow(++index);
writeLong(PRODUCT_ID, row, productData.getId());
writeString(PRODUCT_NAME_COL, row, productData.getName().replaceAll("[ ]", "_"));
writeString(CURRENCY_COL, row, productData.getCurrency().getName().replaceAll("[ ]", "_"));
writeInt(DECIMAL_PLACES_COL, row, productData.getCurrency().decimalPlaces());
writeBigDecimal(TODAYS_PRICE_COL, row, deriveMarketPrice(productData));
writeInt(CURRENCY_IN_MULTIPLES_COL,row,productData.getCurrency().currencyInMultiplesOf());
if (chargesForSharedProducts != null) {
int chargeRowIndex=0;
for (ChargeData chargeData:chargesForSharedProducts) {
if (chargeData.getCurrency().getName().equals(productData.getCurrency().getName())) {
writeString(CHARGES_NAME_1_COL+chargeRowIndex, row, chargeData.getName());
writeLong(CHARGES_ID_1_COL+chargeRowIndex, row, chargeData.getId());
chargeRowIndex+=2;
endIndexCharges++;
}
}
productToBeginEndIndexesofCharges.put(productData.getId(), new Integer[]{startIndexCharges, endIndexCharges});
startIndexCharges = endIndexCharges + 1;
}
}
}
private BigDecimal deriveMarketPrice(final ShareProductData shareProductData) {
BigDecimal marketValue = shareProductData.getUnitPrice();
Collection<ShareProductMarketPriceData> marketDataSet = shareProductData.getMarketPrice();
if (marketDataSet != null && !marketDataSet.isEmpty()) {
Date currentDate = DateUtils.getDateOfTenant();
for (ShareProductMarketPriceData data : marketDataSet) {
Date futureDate = data.getStartDate();
if (currentDate.after(futureDate)) {
marketValue = data.getShareValue();
}
}
}
return marketValue;
}
private void setLayout(Sheet workSheet) {
Row rowHeader=workSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
workSheet.setColumnWidth(PRODUCT_ID,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(PRODUCT_ID,rowHeader,"Product Id");
workSheet.setColumnWidth(PRODUCT_NAME_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(PRODUCT_NAME_COL,rowHeader,"Product Name");
workSheet.setColumnWidth(CURRENCY_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(CURRENCY_COL,rowHeader,"Currency");
workSheet.setColumnWidth(DECIMAL_PLACES_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(DECIMAL_PLACES_COL,rowHeader,"Decimal Places");
workSheet.setColumnWidth(TODAYS_PRICE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(TODAYS_PRICE_COL,rowHeader,"Today's Price");
workSheet.setColumnWidth(CURRENCY_IN_MULTIPLES_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CURRENCY_IN_MULTIPLES_COL,rowHeader,"Currency in multiples of");
workSheet.setColumnWidth(CHARGES_NAME_1_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CHARGES_NAME_1_COL,rowHeader,"Charges Name 1");
workSheet.setColumnWidth(CHARGES_ID_1_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CHARGES_ID_1_COL,rowHeader,"Charges Id 1");
workSheet.setColumnWidth(CHARGES_NAME_2_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CHARGES_NAME_2_COL,rowHeader,"Charges Name 2");
workSheet.setColumnWidth(CHARGES_ID_2_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CHARGES_ID_2_COL,rowHeader,"Charges Id 2");
workSheet.setColumnWidth(CHARGES_NAME_3_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CHARGES_NAME_3_COL,rowHeader,"Charges Name 3");
workSheet.setColumnWidth(CHARGES_ID_3_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CHARGES_ID_3_COL,rowHeader,"Charges Id 3");
}
public List<ShareProductData> getSharedProductDataList() {
return sharedProductDataList;
}
public Map<Long, Integer[]> getProductToBeginEndIndexesofCharges() {
return productToBeginEndIndexesofCharges;
}
}
@@ -0,0 +1,27 @@
/**
* 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.bulkimport.populator;
import org.apache.poi.ss.usermodel.Workbook;
public interface WorkbookPopulator {
void populate(Workbook workbook,String dateFormat);
}
@@ -0,0 +1,235 @@
/**
* 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.bulkimport.populator.centers;
import org.apache.fineract.infrastructure.bulkimport.constants.CenterConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator;
import org.apache.fineract.infrastructure.bulkimport.populator.GroupSheetPopulator;
import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator;
import org.apache.fineract.infrastructure.bulkimport.populator.PersonnelSheetPopulator;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import java.util.List;
public class CentersWorkbookPopulator extends AbstractWorkbookPopulator {
private OfficeSheetPopulator officeSheetPopulator;
private PersonnelSheetPopulator personnelSheetPopulator;
private GroupSheetPopulator groupSheetPopulator;
public CentersWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator,
PersonnelSheetPopulator personnelSheetPopulator,GroupSheetPopulator groupSheetPopulator) {
this.officeSheetPopulator = officeSheetPopulator;
this.personnelSheetPopulator = personnelSheetPopulator;
this.groupSheetPopulator=groupSheetPopulator;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet centerSheet = workbook.createSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME);
personnelSheetPopulator.populate(workbook,dateFormat);
officeSheetPopulator.populate(workbook,dateFormat);
groupSheetPopulator.populate(workbook,dateFormat);
setLayout(centerSheet);
setLookupTable(centerSheet,dateFormat);
setRules(centerSheet,dateFormat);
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(0);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
worksheet.setColumnWidth(CenterConstants.CENTER_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.STAFF_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.ACTIVE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.SUBMITTED_ON_DATE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.MEETING_START_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.IS_REPEATING_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.INTERVAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.REPEATS_ON_DAY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.CENTER_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.FAILURE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.GROUP_NAMES_STARTING_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.LOOKUP_OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.LOOKUP_OFFICE_OPENING_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.LOOKUP_REPEAT_NORMAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.LOOKUP_REPEAT_MONTHLY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(CenterConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(CenterConstants.CENTER_NAME_COL, rowHeader, "Center Name*");
writeString(CenterConstants.OFFICE_NAME_COL, rowHeader, "Office Name*");
writeString(CenterConstants.STAFF_NAME_COL, rowHeader, "Staff Name*");
writeString(CenterConstants.EXTERNAL_ID_COL, rowHeader, "External ID");
writeString(CenterConstants.ACTIVE_COL, rowHeader, "Active*");
writeString(CenterConstants.ACTIVATION_DATE_COL, rowHeader, "Activation Date*");
writeString(CenterConstants.SUBMITTED_ON_DATE_COL,rowHeader,"Submitted On Date");
writeString(CenterConstants.MEETING_START_DATE_COL, rowHeader, "Meeting Start Date* (On or After)");
writeString(CenterConstants.IS_REPEATING_COL, rowHeader, "Repeat*");
writeString(CenterConstants.FREQUENCY_COL, rowHeader, "Frequency*");
writeString(CenterConstants.INTERVAL_COL, rowHeader, "Interval*");
writeString(CenterConstants.REPEATS_ON_DAY_COL, rowHeader, "Repeats On*");
writeString(CenterConstants.GROUP_NAMES_STARTING_COL,rowHeader,"Group Names* (Enter in consecutive cells horizontally)");
writeString(CenterConstants.LOOKUP_OFFICE_NAME_COL, rowHeader, "Office Name");
writeString(CenterConstants.LOOKUP_OFFICE_OPENING_DATE_COL, rowHeader, "Opening Date");
writeString(CenterConstants.LOOKUP_REPEAT_NORMAL_COL, rowHeader, "Repeat Normal Range");
writeString(CenterConstants.LOOKUP_REPEAT_MONTHLY_COL, rowHeader, "Repeat Monthly Range");
writeString(CenterConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, rowHeader, "If Repeat Weekly Range");
}
private void setLookupTable(Sheet centerSheet,String dateFormat) {
setOfficeDateLookupTable(centerSheet, officeSheetPopulator.getOffices(), CenterConstants.LOOKUP_OFFICE_NAME_COL,CenterConstants.LOOKUP_OFFICE_OPENING_DATE_COL,dateFormat);
int rowIndex;
for(rowIndex = 1; rowIndex <= 11; rowIndex++) {
Row row = centerSheet.getRow(rowIndex);
if(row == null)
row = centerSheet.createRow(rowIndex);
writeInt(CenterConstants.LOOKUP_REPEAT_MONTHLY_COL, row, rowIndex);
}
for(rowIndex = 1; rowIndex <= 3; rowIndex++)
writeInt(CenterConstants.LOOKUP_REPEAT_NORMAL_COL, centerSheet.getRow(rowIndex), rowIndex);
String[] days = new String[]{
TemplatePopulateImportConstants.MONDAY,
TemplatePopulateImportConstants.TUESDAY,
TemplatePopulateImportConstants.WEDNESDAY,
TemplatePopulateImportConstants.THURSDAY,
TemplatePopulateImportConstants.FRIDAY,
TemplatePopulateImportConstants.SATURDAY,
TemplatePopulateImportConstants.SUNDAY};
for(rowIndex = 1; rowIndex <= 7; rowIndex++)
writeString(CenterConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, centerSheet.getRow(rowIndex), days[rowIndex-1]);
}
private void setRules(Sheet worksheet,String dateFormat) {
CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.OFFICE_NAME_COL,CenterConstants. OFFICE_NAME_COL);
CellRangeAddressList staffNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.STAFF_NAME_COL,CenterConstants. STAFF_NAME_COL);
CellRangeAddressList activationDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),CenterConstants. ACTIVATION_DATE_COL,CenterConstants. ACTIVATION_DATE_COL);
CellRangeAddressList activeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.ACTIVE_COL, CenterConstants.ACTIVE_COL);
CellRangeAddressList submittedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),CenterConstants. SUBMITTED_ON_DATE_COL,CenterConstants.SUBMITTED_ON_DATE_COL);
CellRangeAddressList meetingStartDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.MEETING_START_DATE_COL,CenterConstants. MEETING_START_DATE_COL);
CellRangeAddressList isRepeatRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),CenterConstants. IS_REPEATING_COL,CenterConstants. IS_REPEATING_COL);
CellRangeAddressList repeatsRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.FREQUENCY_COL, CenterConstants.FREQUENCY_COL);
CellRangeAddressList repeatsEveryRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.INTERVAL_COL,CenterConstants. INTERVAL_COL);
CellRangeAddressList repeatsOnRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.REPEATS_ON_DAY_COL,CenterConstants. REPEATS_ON_DAY_COL);
DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet)worksheet);
List<OfficeData> offices = officeSheetPopulator.getOffices();
setNames(worksheet, offices);
DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office");
DataValidationConstraint staffNameConstraint = validationHelper.
createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$B1))");
DataValidationConstraint activationDateConstraint = validationHelper.createDateConstraint
(DataValidationConstraint.OperatorType.BETWEEN, "=VLOOKUP($B1,$IR$2:$IS" + (offices.size() + 1)+",2,FALSE)",
"=TODAY()", dateFormat);
DataValidationConstraint booleanConstraint = validationHelper.createExplicitListConstraint(new String[]{"True", "False"});
DataValidationConstraint submittedOnDateConstraint =
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL,
"=$F1", null,dateFormat);
DataValidationConstraint meetingStartDateConstraint =
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN,
"=$F1", "=TODAY()", dateFormat);
DataValidationConstraint repeatsConstraint =
validationHelper.createExplicitListConstraint(new String[]{
TemplatePopulateImportConstants.FREQUENCY_DAILY,
TemplatePopulateImportConstants.FREQUENCY_WEEKLY,
TemplatePopulateImportConstants.FREQUENCY_MONTHLY,
TemplatePopulateImportConstants.FREQUENCY_YEARLY});
DataValidationConstraint repeatsEveryConstraint = validationHelper.createFormulaListConstraint("INDIRECT($J1)");
DataValidationConstraint repeatsOnConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE($J1,\"_DAYS\"))");
DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange);
DataValidation staffValidation = validationHelper.createValidation(staffNameConstraint, staffNameRange);
DataValidation activationDateValidation = validationHelper.createValidation(activationDateConstraint, activationDateRange);
DataValidation activeValidation = validationHelper.createValidation(booleanConstraint, activeRange);
DataValidation submittedOnValidation=validationHelper.createValidation(submittedOnDateConstraint,submittedDateRange);
DataValidation meetingStartDateValidation = validationHelper.createValidation(meetingStartDateConstraint, meetingStartDateRange);
DataValidation isRepeatValidation = validationHelper.createValidation(booleanConstraint, isRepeatRange);
DataValidation repeatsValidation = validationHelper.createValidation(repeatsConstraint, repeatsRange);
DataValidation repeatsEveryValidation = validationHelper.createValidation(repeatsEveryConstraint, repeatsEveryRange);
DataValidation repeatsOnValidation = validationHelper.createValidation(repeatsOnConstraint, repeatsOnRange);
worksheet.addValidationData(activeValidation);
worksheet.addValidationData(officeValidation);
worksheet.addValidationData(staffValidation);
worksheet.addValidationData(activationDateValidation);
worksheet.addValidationData(submittedOnValidation);
worksheet.addValidationData(meetingStartDateValidation);
worksheet.addValidationData(isRepeatValidation);
worksheet.addValidationData(repeatsValidation);
worksheet.addValidationData(repeatsEveryValidation);
worksheet.addValidationData(repeatsOnValidation);
}
private void setNames(Sheet worksheet, List<OfficeData> offices) {
Workbook centerWorkbook = worksheet.getWorkbook();
Name officeCenter = centerWorkbook.createName();
officeCenter.setNameName("Office");
officeCenter.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME +"!$B$2:$B$" + (offices.size() + 1));
//Repeat constraint names
Name repeatsDaily = centerWorkbook.createName();
repeatsDaily.setNameName("Daily");
repeatsDaily.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IT$2:$IT$4");
Name repeatsWeekly = centerWorkbook.createName();
repeatsWeekly.setNameName("Weekly");
repeatsWeekly.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IT$2:$IT$4");
Name repeatYearly = centerWorkbook.createName();
repeatYearly.setNameName("Yearly");
repeatYearly.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IT$2:$IT$4");
Name repeatsMonthly = centerWorkbook.createName();
repeatsMonthly.setNameName("Monthly");
repeatsMonthly.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IU$2:$IU$12");
Name repeatsOnWeekly = centerWorkbook.createName();
repeatsOnWeekly.setNameName("Weekly_Days");
repeatsOnWeekly.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IV$2:$IV$8");
//Staff Names for each office
for(Integer i = 0; i < offices.size(); i++) {
Integer[] officeNameToBeginEndIndexesOfStaff = personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i);
Name loanOfficerName = centerWorkbook.createName();
if(officeNameToBeginEndIndexesOfStaff != null) {
loanOfficerName.setNameName("Staff_" + offices.get(i).name().trim().replaceAll("[ )(]", "_"));
loanOfficerName.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + officeNameToBeginEndIndexesOfStaff[1]);
}
}
}
}
@@ -0,0 +1,236 @@
/**
* 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.bulkimport.populator.chartofaccounts;
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
import org.apache.fineract.accounting.glaccount.domain.GLAccountUsage;
import org.apache.fineract.infrastructure.bulkimport.constants.ChartOfAcountsConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator;
import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ChartOfAccountsWorkbook extends AbstractWorkbookPopulator {
private List<GLAccountData> glAccounts;
private Map<String,List<String>> accountTypeToAccountNameAndTag;
private Map<Integer,Integer[]>accountTypeToBeginEndIndexesofAccountNames;
private List<String> accountTypesNoDuplicatesList;
public ChartOfAccountsWorkbook(List<GLAccountData> glAccounts) {
this.glAccounts = glAccounts;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet chartOfAccountsSheet=workbook.createSheet(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME);
setLayout(chartOfAccountsSheet);
setAccountTypeToAccountNameAndTag();
setLookupTable(chartOfAccountsSheet);
setRules(chartOfAccountsSheet);
setDefaults(chartOfAccountsSheet);
}
private void setAccountTypeToAccountNameAndTag() {
accountTypeToAccountNameAndTag=new HashMap<>();
for (GLAccountData glAccount: glAccounts) {
addToaccountTypeToAccountNameMap(glAccount.getType().getValue(),glAccount.getName()+
"-"+glAccount.getId()+"-"+glAccount.getTagId().getName()+"-"+glAccount.getTagId().getId());
}
}
private void addToaccountTypeToAccountNameMap(String key, String value) {
List<String> values=accountTypeToAccountNameAndTag.get(key);
if (values==null){
values=new ArrayList<String>();
}
if (!values.contains(value)){
values.add(value);
accountTypeToAccountNameAndTag.put(key,values);
}
}
private void setRules(Sheet chartOfAccountsSheet) {
CellRangeAddressList accountTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),
ChartOfAcountsConstants. ACCOUNT_TYPE_COL,ChartOfAcountsConstants.ACCOUNT_TYPE_COL);
CellRangeAddressList accountUsageRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),
ChartOfAcountsConstants.ACCOUNT_USAGE_COL,ChartOfAcountsConstants.ACCOUNT_USAGE_COL);
CellRangeAddressList manualEntriesAllowedRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),
ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL,ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL);
CellRangeAddressList parentRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),
ChartOfAcountsConstants.PARENT_COL,ChartOfAcountsConstants.PARENT_COL);
CellRangeAddressList tagRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),
ChartOfAcountsConstants.TAG_COL,ChartOfAcountsConstants.TAG_COL);
DataValidationHelper validationHelper=new HSSFDataValidationHelper((HSSFSheet) chartOfAccountsSheet);
setNames(chartOfAccountsSheet, accountTypesNoDuplicatesList);
DataValidationConstraint accountTypeConstraint=validationHelper.
createExplicitListConstraint(new String[]{
GLAccountType.ASSET.toString(),
GLAccountType.LIABILITY.toString(),
GLAccountType.EQUITY.toString(),
GLAccountType.INCOME.toString(),
GLAccountType.EXPENSE.toString()});
DataValidationConstraint accountUsageConstraint=validationHelper.
createExplicitListConstraint(new String[]{
GLAccountUsage.DETAIL.toString(),
GLAccountUsage.HEADER.toString()});
DataValidationConstraint booleanConstraint=validationHelper.
createExplicitListConstraint(new String[]{"True","False"});
DataValidationConstraint parentConstraint=validationHelper.
createFormulaListConstraint("INDIRECT(CONCATENATE(\"AccountName_\",$A1))");
DataValidationConstraint tagConstraint=validationHelper.
createFormulaListConstraint("INDIRECT(CONCATENATE(\"Tags_\",$A1))");
DataValidation accountTypeValidation=validationHelper.createValidation(accountTypeConstraint,accountTypeRange);
DataValidation accountUsageValidation=validationHelper.createValidation(accountUsageConstraint,accountUsageRange);
DataValidation manualEntriesValidation=validationHelper.createValidation(booleanConstraint,manualEntriesAllowedRange);
DataValidation parentValidation=validationHelper.createValidation(parentConstraint,parentRange);
DataValidation tagValidation=validationHelper.createValidation(tagConstraint,tagRange);
chartOfAccountsSheet.addValidationData(accountTypeValidation);
chartOfAccountsSheet.addValidationData(accountUsageValidation);
chartOfAccountsSheet.addValidationData(manualEntriesValidation);
chartOfAccountsSheet.addValidationData(parentValidation);
chartOfAccountsSheet.addValidationData(tagValidation);
}
private void setNames(Sheet chartOfAccountsSheet,List<String> accountTypesNoDuplicatesList) {
Workbook chartOfAccountsWorkbook=chartOfAccountsSheet.getWorkbook();
for (Integer i=0;i<accountTypesNoDuplicatesList.size();i++){
Name tags=chartOfAccountsWorkbook.createName();
Integer [] tagValueBeginEndIndexes=accountTypeToBeginEndIndexesofAccountNames.get(i);
if(accountTypeToBeginEndIndexesofAccountNames!=null){
tags.setNameName("Tags_"+accountTypesNoDuplicatesList.get(i));
tags.setRefersToFormula(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME+
"!$S$"+tagValueBeginEndIndexes[0]+":$S$"+tagValueBeginEndIndexes[1]);
}
Name accountNames=chartOfAccountsWorkbook.createName();
Integer [] accountNamesBeginEndIndexes=accountTypeToBeginEndIndexesofAccountNames.get(i);
if (accountNamesBeginEndIndexes!=null){
accountNames.setNameName("AccountName_"+accountTypesNoDuplicatesList.get(i));
accountNames.setRefersToFormula(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME+
"!$Q$"+accountNamesBeginEndIndexes[0]+":$Q$"+accountNamesBeginEndIndexes[1]);
}
}
}
private void setDefaults(Sheet worksheet){
try {
for (Integer rowNo = 1; rowNo < 3000; rowNo++) {
Row row = worksheet.getRow(rowNo);
if (row == null)
row = worksheet.createRow(rowNo);
writeFormula(ChartOfAcountsConstants.PARENT_ID_COL, row,
"IF(ISERROR(VLOOKUP($E"+(rowNo+1)+",$Q$2:$R$"+(glAccounts.size()+1)+",2,FALSE))," +
"\"\",(VLOOKUP($E"+(rowNo+1)+",$Q$2:$R$"+(glAccounts.size()+1)+",2,FALSE)))");
writeFormula(ChartOfAcountsConstants.TAG_ID_COL,row,
"IF(ISERROR(VLOOKUP($H"+(rowNo+1)+",$S$2:$T$"+(glAccounts.size()+1)+",2,FALSE))," +
"\"\",(VLOOKUP($H"+(rowNo+1)+",$S$2:$T$"+(glAccounts.size()+1)+",2,FALSE)))");
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void setLookupTable(Sheet chartOfAccountsSheet) {
accountTypesNoDuplicatesList =new ArrayList<>();
for (int i = 0; i <glAccounts.size() ; i++) {
if (!accountTypesNoDuplicatesList.contains(glAccounts.get(i).getType().getValue())) {
accountTypesNoDuplicatesList.add(glAccounts.get(i).getType().getValue());
}
}
int rowIndex=1,startIndex=1,accountTypeIndex=0;
accountTypeToBeginEndIndexesofAccountNames= new HashMap<Integer,Integer[]>();
for (String accountType: accountTypesNoDuplicatesList) {
startIndex=rowIndex+1;
Row row =chartOfAccountsSheet.createRow(rowIndex);
writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_TYPE_COL,row,accountType);
List<String> accountNamesandTags =accountTypeToAccountNameAndTag.get(accountType);
if (!accountNamesandTags.isEmpty()){
for (String accountNameandTag:accountNamesandTags) {
if (chartOfAccountsSheet.getRow(rowIndex)!=null){
String accountNameAndTagAr[]=accountNameandTag.split("-");
writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_NAME_COL,row,accountNameAndTagAr[0]);
writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_ID_COL,row,accountNameAndTagAr[1]);
writeString(ChartOfAcountsConstants.LOOKUP_TAG_COL,row,accountNameAndTagAr[2]);
writeString(ChartOfAcountsConstants.LOOKUP_TAG_ID_COL,row,accountNameAndTagAr[3]);
rowIndex++;
}else{
row =chartOfAccountsSheet.createRow(rowIndex);
String accountNameAndTagAr[]=accountNameandTag.split("-");
writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_NAME_COL,row,accountNameAndTagAr[0]);
writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_ID_COL,row,accountNameAndTagAr[1]);
writeString(ChartOfAcountsConstants.LOOKUP_TAG_COL,row,accountNameAndTagAr[2]);
writeString(ChartOfAcountsConstants.LOOKUP_TAG_ID_COL,row,accountNameAndTagAr[3]);
rowIndex++;
}
}
accountTypeToBeginEndIndexesofAccountNames.put(accountTypeIndex++,new Integer[]{startIndex,rowIndex});
}else {
accountTypeIndex++;
}
}
}
private void setLayout(Sheet chartOfAccountsSheet) {
Row rowHeader=chartOfAccountsSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.ACCOUNT_TYPE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.ACCOUNT_NAME_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.ACCOUNT_USAGE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.PARENT_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.PARENT_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.GL_CODE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.TAG_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.TAG_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.DESCRIPTION_COL,TemplatePopulateImportConstants.EXTRALARGE_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_ACCOUNT_TYPE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_ACCOUNT_NAME_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_ACCOUNT_ID_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_TAG_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_TAG_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(ChartOfAcountsConstants.ACCOUNT_TYPE_COL,rowHeader,"Account Type*");
writeString(ChartOfAcountsConstants.GL_CODE_COL,rowHeader,"GL Code *");
writeString(ChartOfAcountsConstants.ACCOUNT_USAGE_COL,rowHeader,"Account Usage *");
writeString(ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL,rowHeader,"Manual entries allowed *");
writeString(ChartOfAcountsConstants.PARENT_COL,rowHeader,"Parent");
writeString(ChartOfAcountsConstants.PARENT_ID_COL,rowHeader,"Parent Id");
writeString(ChartOfAcountsConstants.ACCOUNT_NAME_COL,rowHeader,"Account Name");
writeString(ChartOfAcountsConstants.TAG_COL,rowHeader,"Tag *");
writeString(ChartOfAcountsConstants.TAG_ID_COL,rowHeader,"Tag Id");
writeString(ChartOfAcountsConstants.DESCRIPTION_COL,rowHeader,"Description *");
writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_TYPE_COL,rowHeader,"Lookup Account type");
writeString(ChartOfAcountsConstants.LOOKUP_TAG_COL,rowHeader,"Lookup Tag");
writeString(ChartOfAcountsConstants.LOOKUP_TAG_ID_COL,rowHeader,"Lookup Tag Id");
writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_NAME_COL,rowHeader,"Lookup Account name *");
writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_ID_COL,rowHeader,"Lookup Account Id");
}
}
@@ -0,0 +1,405 @@
/**
* 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.bulkimport.populator.client;
import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator;
import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator;
import org.apache.fineract.infrastructure.bulkimport.populator.PersonnelSheetPopulator;
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import java.util.List;
public class ClientEntityWorkbookPopulator extends AbstractWorkbookPopulator {
private OfficeSheetPopulator officeSheetPopulator;
private PersonnelSheetPopulator personnelSheetPopulator;
private List<CodeValueData> clientTypeCodeValues;
private List<CodeValueData> constitutionCodeValues;
private List<CodeValueData> clientClassificationCodeValues;
private List<CodeValueData> addressTypesCodeValues;
private List<CodeValueData> stateProvinceCodeValues;
private List<CodeValueData> countryCodeValues;
private List<CodeValueData> mainBusinesslineCodeValues;
public ClientEntityWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator,
PersonnelSheetPopulator personnelSheetPopulator,List<CodeValueData>clientTypeCodeValues,
List<CodeValueData>constitutionCodeValues,List<CodeValueData>mainBusinessline ,
List<CodeValueData>clientClassification,List<CodeValueData>addressTypesCodeValues,
List<CodeValueData>stateProvinceCodeValues,List<CodeValueData>countryCodeValues ) {
this.officeSheetPopulator = officeSheetPopulator;
this.personnelSheetPopulator = personnelSheetPopulator;
this.clientTypeCodeValues=clientTypeCodeValues;
this.constitutionCodeValues=constitutionCodeValues;
this.clientClassificationCodeValues=clientClassification;
this.addressTypesCodeValues=addressTypesCodeValues;
this.stateProvinceCodeValues=stateProvinceCodeValues;
this.countryCodeValues=countryCodeValues;
this.mainBusinesslineCodeValues=mainBusinessline;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet clientSheet = workbook.createSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME);
personnelSheetPopulator.populate(workbook,dateFormat);
officeSheetPopulator.populate(workbook,dateFormat);
setLayout(clientSheet);
setOfficeDateLookupTable(clientSheet, officeSheetPopulator.getOffices(),
ClientEntityConstants.RELATIONAL_OFFICE_NAME_COL, ClientEntityConstants.RELATIONAL_OFFICE_OPENING_DATE_COL,dateFormat);
setClientDataLookupTable(clientSheet);
setRules(clientSheet,dateFormat);
}
private void setClientDataLookupTable(Sheet clientSheet) {
int rowIndex=0;
for (CodeValueData clientTypeCodeValue:clientTypeCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientEntityConstants.LOOKUP_CLIENT_TYPES,row,clientTypeCodeValue.getName()+"-"+clientTypeCodeValue.getId());
}
rowIndex=0;
for (CodeValueData clientClassificationCodeValue:clientClassificationCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION,row,
clientClassificationCodeValue.getName()+"-"+clientClassificationCodeValue.getId());
}
rowIndex=0;
for (CodeValueData constitutionCodeValue:constitutionCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientEntityConstants.LOOKUP_CONSTITUTION_COL,row,
constitutionCodeValue.getName()+"-"+constitutionCodeValue.getId());
}
rowIndex=0;
for (CodeValueData mainBusinessCodeValue:mainBusinesslineCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE,row,
mainBusinessCodeValue.getName()+"-"+mainBusinessCodeValue.getId());
}
rowIndex=0;
for (CodeValueData addressTypeCodeValue:addressTypesCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientEntityConstants.LOOKUP_ADDRESS_TYPE,row,
addressTypeCodeValue.getName()+"-"+addressTypeCodeValue.getId());
}
rowIndex=0;
for (CodeValueData stateCodeValue:stateProvinceCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientEntityConstants.LOOKUP_STATE_PROVINCE,row,
stateCodeValue.getName()+"-"+stateCodeValue.getId());
}
rowIndex=0;
for (CodeValueData countryCodeValue: countryCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientEntityConstants.LOOKUP_COUNTRY,row,
countryCodeValue.getName()+"-"+countryCodeValue.getId());
}
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
worksheet.setColumnWidth(ClientEntityConstants.NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(ClientEntityConstants.NAME_COL, rowHeader, "Name*");
worksheet.setColumnWidth(ClientEntityConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.STAFF_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.INCOPORATION_DATE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.INCOPORATION_VALID_TILL_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.MOBILE_NO_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.CLIENT_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.CLIENT_CLASSIFICATION_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.INCOPORATION_NUMBER_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.MAIN_BUSINESS_LINE,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.CONSTITUTION_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.REMARKS_COL,TemplatePopulateImportConstants.LARGE_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.SUBMITTED_ON_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.ACTIVE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_ENABLED,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.STREET_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_LINE_1_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_LINE_2_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_LINE_3_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.CITY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.STATE_PROVINCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.COUNTRY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.POSTAL_CODE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.IS_ACTIVE_ADDRESS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.WARNING_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.RELATIONAL_OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.RELATIONAL_OFFICE_OPENING_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_CONSTITUTION_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_CLIENT_TYPES,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_ADDRESS_TYPE,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_STATE_PROVINCE,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_COUNTRY,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(ClientEntityConstants.NAME_COL,rowHeader,"Name");
writeString(ClientEntityConstants.OFFICE_NAME_COL, rowHeader, "Office Name*");
writeString(ClientEntityConstants.STAFF_NAME_COL, rowHeader, "Staff Name");
writeString(ClientEntityConstants.INCOPORATION_DATE_COL,rowHeader,"Incorporation Date");
writeString(ClientEntityConstants.INCOPORATION_VALID_TILL_COL,rowHeader,"Incorporation Validity Till Date");
writeString(ClientEntityConstants.MOBILE_NO_COL, rowHeader, "Mobile number");
writeString(ClientEntityConstants.CLIENT_TYPE_COL, rowHeader, "Client Type ");
writeString(ClientEntityConstants.CLIENT_CLASSIFICATION_COL, rowHeader, "Client Classification ");
writeString(ClientEntityConstants.INCOPORATION_NUMBER_COL,rowHeader,"Incorporation Number");
writeString(ClientEntityConstants.MAIN_BUSINESS_LINE,rowHeader,"Main Business Line");
writeString(ClientEntityConstants.CONSTITUTION_COL,rowHeader,"Constitution");
writeString(ClientEntityConstants.REMARKS_COL,rowHeader,"Remarks");
writeString(ClientEntityConstants.EXTERNAL_ID_COL, rowHeader, "External ID ");
writeString(ClientEntityConstants.SUBMITTED_ON_COL,rowHeader,"Submitted On Date");
writeString(ClientEntityConstants.ACTIVE_COL, rowHeader, "Active*");
writeString(ClientEntityConstants.ACTIVATION_DATE_COL, rowHeader, "Activation Date ");
writeString(ClientEntityConstants.ADDRESS_ENABLED,rowHeader,"Address Enabled ");
writeString(ClientEntityConstants.ADDRESS_TYPE_COL, rowHeader, "Address Type ");
writeString(ClientEntityConstants.STREET_COL, rowHeader, "Street ");
writeString(ClientEntityConstants.ADDRESS_LINE_1_COL, rowHeader, "Address Line 1");
writeString(ClientEntityConstants.ADDRESS_LINE_2_COL, rowHeader, "Address Line 2");
writeString(ClientEntityConstants.ADDRESS_LINE_3_COL, rowHeader, "Address Line 3");
writeString(ClientEntityConstants.CITY_COL, rowHeader, "City");
writeString(ClientEntityConstants.STATE_PROVINCE_COL, rowHeader, "State/ Province");
writeString(ClientEntityConstants.COUNTRY_COL, rowHeader, "Country");
writeString(ClientEntityConstants.POSTAL_CODE_COL, rowHeader, "Postal Code");
writeString(ClientEntityConstants.IS_ACTIVE_ADDRESS_COL, rowHeader, "Is active Address ? ");
writeString(ClientEntityConstants.WARNING_COL, rowHeader, "All * marked fields are compulsory.");
writeString(ClientEntityConstants.RELATIONAL_OFFICE_NAME_COL, rowHeader, "Lookup office Name ");
writeString(ClientEntityConstants.RELATIONAL_OFFICE_OPENING_DATE_COL, rowHeader, "Lookup Office Opened Date ");
writeString(ClientEntityConstants.LOOKUP_CONSTITUTION_COL, rowHeader, "Lookup Constitution ");
writeString(ClientEntityConstants.LOOKUP_CLIENT_TYPES, rowHeader, "Lookup Client Types ");
writeString(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION, rowHeader, "Lookup Client Classification ");
writeString(ClientEntityConstants.LOOKUP_ADDRESS_TYPE, rowHeader, "Lookup AddressType ");
writeString(ClientEntityConstants.LOOKUP_STATE_PROVINCE, rowHeader, "Lookup State/Province ");
writeString(ClientEntityConstants.LOOKUP_COUNTRY, rowHeader, "Lookup Country ");
writeString(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE,rowHeader,"Lookup Business Line");
}
private void setRules(Sheet worksheet,String dateFormat) {
CellRangeAddressList officeNameRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.OFFICE_NAME_COL,
ClientEntityConstants.OFFICE_NAME_COL);
CellRangeAddressList staffNameRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.STAFF_NAME_COL, ClientEntityConstants.STAFF_NAME_COL);
CellRangeAddressList submittedOnDateRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.SUBMITTED_ON_COL,ClientEntityConstants. SUBMITTED_ON_COL);
CellRangeAddressList dateRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. ACTIVATION_DATE_COL,ClientEntityConstants. ACTIVATION_DATE_COL);
CellRangeAddressList activeRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. ACTIVE_COL,ClientEntityConstants. ACTIVE_COL);
CellRangeAddressList clientTypeRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. CLIENT_TYPE_COL,ClientEntityConstants. CLIENT_TYPE_COL);
CellRangeAddressList constitutionRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.CONSTITUTION_COL,ClientEntityConstants. CONSTITUTION_COL);
CellRangeAddressList mainBusinessLineRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. MAIN_BUSINESS_LINE,ClientEntityConstants. MAIN_BUSINESS_LINE);
CellRangeAddressList clientClassificationRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.CLIENT_CLASSIFICATION_COL,
ClientEntityConstants.CLIENT_CLASSIFICATION_COL);
CellRangeAddressList enabledAddressRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.ADDRESS_ENABLED, ClientEntityConstants.ADDRESS_ENABLED);
CellRangeAddressList addressTypeRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.ADDRESS_TYPE_COL,ClientEntityConstants. ADDRESS_TYPE_COL);
CellRangeAddressList stateProvinceRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.STATE_PROVINCE_COL,ClientEntityConstants. STATE_PROVINCE_COL);
CellRangeAddressList countryRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. COUNTRY_COL,ClientEntityConstants. COUNTRY_COL);
CellRangeAddressList activeAddressRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. IS_ACTIVE_ADDRESS_COL,ClientEntityConstants. IS_ACTIVE_ADDRESS_COL);
CellRangeAddressList incorporateDateRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.INCOPORATION_DATE_COL,ClientEntityConstants.INCOPORATION_DATE_COL);
CellRangeAddressList incorporateDateTillRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.INCOPORATION_VALID_TILL_COL,
ClientEntityConstants.INCOPORATION_VALID_TILL_COL);
DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet);
List<OfficeData> offices = officeSheetPopulator.getOffices();
setNames(worksheet, offices);
DataValidationConstraint officeNameConstraint =
validationHelper.createFormulaListConstraint("Office");
DataValidationConstraint staffNameConstraint =
validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$B1))");
DataValidationConstraint submittedOnDateConstraint =
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL,
"=$O1" ,null, dateFormat);
DataValidationConstraint activationDateConstraint =
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN,
"=VLOOKUP($B1,$AJ$2:$AK" + (offices.size() + 1) + ",2,FALSE)", "=TODAY()", dateFormat);
DataValidationConstraint activeConstraint =
validationHelper.createExplicitListConstraint(new String[] {"True", "False"});
DataValidationConstraint clientTypesConstraint =
validationHelper.createFormulaListConstraint("ClientTypes");
DataValidationConstraint constitutionConstraint =
validationHelper.createFormulaListConstraint("Constitution");
DataValidationConstraint mainBusinessLineConstraint =
validationHelper.createFormulaListConstraint("MainBusinessLine");
DataValidationConstraint clientClassificationConstraint =
validationHelper.createFormulaListConstraint("ClientClassification");
DataValidationConstraint enabledAddressConstraint =
validationHelper.createExplicitListConstraint(new String[] {"True", "False"});
DataValidationConstraint addressTypeConstraint =
validationHelper.createFormulaListConstraint("AddressType");
DataValidationConstraint stateProvinceConstraint =
validationHelper.createFormulaListConstraint("StateProvince");
DataValidationConstraint countryConstraint =
validationHelper.createFormulaListConstraint("Country");
DataValidationConstraint activeAddressConstraint =
validationHelper.createExplicitListConstraint(new String[] {"True", "False"});
DataValidationConstraint incorpDateConstraint=
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL,
"=TODAY()",null,dateFormat);
DataValidationConstraint incorpDateTillConstraint=
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL,
"=TODAY()",null,dateFormat);
DataValidation officeValidation =
validationHelper.createValidation(officeNameConstraint, officeNameRange);
DataValidation staffValidation =
validationHelper.createValidation(staffNameConstraint, staffNameRange);
DataValidation submittedOnDateValidation =
validationHelper.createValidation(submittedOnDateConstraint, submittedOnDateRange);
DataValidation activationDateValidation =
validationHelper.createValidation(activationDateConstraint, dateRange);
DataValidation activeValidation =
validationHelper.createValidation(activeConstraint, activeRange);
DataValidation clientTypeValidation =
validationHelper.createValidation(clientTypesConstraint, clientTypeRange);
DataValidation constitutionValidation =
validationHelper.createValidation(constitutionConstraint,constitutionRange);
DataValidation mainBusinessLineValidation =
validationHelper.createValidation(mainBusinessLineConstraint,mainBusinessLineRange);
DataValidation clientClassificationValidation =
validationHelper.createValidation(clientClassificationConstraint, clientClassificationRange);
DataValidation enabledAddressValidation=
validationHelper.createValidation(enabledAddressConstraint,enabledAddressRange);
DataValidation addressTypeValidation =
validationHelper.createValidation(addressTypeConstraint, addressTypeRange);
DataValidation stateProvinceValidation =
validationHelper.createValidation(stateProvinceConstraint, stateProvinceRange);
DataValidation countryValidation =
validationHelper.createValidation(countryConstraint, countryRange);
DataValidation activeAddressValidation =
validationHelper.createValidation(activeAddressConstraint,activeAddressRange);
DataValidation incorporateDateValidation=validationHelper.createValidation(incorpDateConstraint,incorporateDateRange);
DataValidation incorporateDateTillValidation=validationHelper.createValidation(incorpDateTillConstraint,incorporateDateTillRange);
worksheet.addValidationData(activeValidation);
worksheet.addValidationData(officeValidation);
worksheet.addValidationData(staffValidation);
worksheet.addValidationData(activationDateValidation);
worksheet.addValidationData(submittedOnDateValidation);
worksheet.addValidationData(clientTypeValidation);
worksheet.addValidationData(constitutionValidation);
worksheet.addValidationData(mainBusinessLineValidation);
worksheet.addValidationData(clientClassificationValidation);
worksheet.addValidationData(enabledAddressValidation);
worksheet.addValidationData(addressTypeValidation);
worksheet.addValidationData(stateProvinceValidation);
worksheet.addValidationData(countryValidation);
worksheet.addValidationData(activeAddressValidation);
worksheet.addValidationData(incorporateDateValidation);
worksheet.addValidationData(incorporateDateTillValidation);
}
private void setNames(Sheet worksheet, List<OfficeData> offices) {
Workbook clientWorkbook = worksheet.getWorkbook();
Name officeGroup = clientWorkbook.createName();
officeGroup.setNameName("Office");
officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (offices.size() + 1));
Name clientTypeGroup = clientWorkbook.createName();
clientTypeGroup.setNameName("ClientTypes");
clientTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AN$2:$AN$" +
(clientTypeCodeValues.size() + 1));
Name constitutionGroup = clientWorkbook.createName();
constitutionGroup.setNameName("Constitution");
constitutionGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AL$2:$AL$" +
(constitutionCodeValues.size() + 1));
Name mainBusinessLineGroup = clientWorkbook.createName();
mainBusinessLineGroup.setNameName("MainBusinessLine");
mainBusinessLineGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AR$2:$AR$" +
(mainBusinesslineCodeValues.size() + 1));
Name clientClassficationGroup = clientWorkbook.createName();
clientClassficationGroup.setNameName("ClientClassification");
clientClassficationGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AM$2:$AM$" +
(clientClassificationCodeValues.size() + 1));
Name addressTypeGroup = clientWorkbook.createName();
addressTypeGroup.setNameName("AddressType");
addressTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+
"!$AO$2:$AO$" + (addressTypesCodeValues.size() + 1));
Name stateProvinceGroup = clientWorkbook.createName();
stateProvinceGroup.setNameName("StateProvince");
stateProvinceGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+
"!$AP$2:$AP$" + (stateProvinceCodeValues.size() + 1));
Name countryGroup = clientWorkbook.createName();
countryGroup.setNameName("Country");
countryGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AQ$2:$AQ$" +
(countryCodeValues.size() + 1));
for (Integer i = 0; i < offices.size(); i++) {
Integer[] officeNameToBeginEndIndexesOfStaff =
personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i);
if (officeNameToBeginEndIndexesOfStaff != null) {
Name name = clientWorkbook.createName();
name.setNameName("Staff_" + offices.get(i).name().trim().replaceAll("[ )(]", "_"));
name.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" +
officeNameToBeginEndIndexesOfStaff[0] + ":$B$"
+ officeNameToBeginEndIndexesOfStaff[1]);
}
}
}
}
@@ -0,0 +1,370 @@
/**
* 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.bulkimport.populator.client;
import org.apache.fineract.infrastructure.bulkimport.constants.ClientPersonConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator;
import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator;
import org.apache.fineract.infrastructure.bulkimport.populator.PersonnelSheetPopulator;
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import java.util.List;
public class ClientPersonWorkbookPopulator extends AbstractWorkbookPopulator {
private OfficeSheetPopulator officeSheetPopulator;
private PersonnelSheetPopulator personnelSheetPopulator;
private List<CodeValueData>clientTypeCodeValues;
private List<CodeValueData>genderCodeValues;
private List<CodeValueData>clientClassificationCodeValues;
private List<CodeValueData>addressTypesCodeValues;
private List<CodeValueData>stateProvinceCodeValues;
private List<CodeValueData>countryCodeValues;
public ClientPersonWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator,
PersonnelSheetPopulator personnelSheetPopulator,List<CodeValueData>clientTypeCodeValues,
List<CodeValueData>genderCodeValues, List<CodeValueData>clientClassification,List<CodeValueData>addressTypesCodeValues,
List<CodeValueData>stateProvinceCodeValues,List<CodeValueData>countryCodeValues ) {
this.officeSheetPopulator = officeSheetPopulator;
this.personnelSheetPopulator = personnelSheetPopulator;
this.clientTypeCodeValues=clientTypeCodeValues;
this.genderCodeValues=genderCodeValues;
this.clientClassificationCodeValues=clientClassification;
this.addressTypesCodeValues=addressTypesCodeValues;
this.stateProvinceCodeValues=stateProvinceCodeValues;
this.countryCodeValues=countryCodeValues;
}
@Override
public void populate(Workbook workbook,String dateFormat) {
Sheet clientSheet = workbook.createSheet(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME);
personnelSheetPopulator.populate(workbook,dateFormat);
officeSheetPopulator.populate(workbook,dateFormat);
setLayout(clientSheet);
setOfficeDateLookupTable(clientSheet, officeSheetPopulator.getOffices(),
ClientPersonConstants.RELATIONAL_OFFICE_NAME_COL, ClientPersonConstants.RELATIONAL_OFFICE_OPENING_DATE_COL,dateFormat);
setClientDataLookupTable(clientSheet);
setRules(clientSheet,dateFormat);
}
private void setClientDataLookupTable(Sheet clientSheet) {
int rowIndex=0;
for (CodeValueData clientTypeCodeValue:clientTypeCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientPersonConstants.LOOKUP_CLIENT_TYPES_COL,row,clientTypeCodeValue.getName()+
"-"+clientTypeCodeValue.getId());
}
rowIndex=0;
for (CodeValueData clientClassificationCodeValue:clientClassificationCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientPersonConstants.LOOKUP_CLIENT_CLASSIFICATION_COL,row,
clientClassificationCodeValue.getName()+"-"+clientClassificationCodeValue.getId());
}
rowIndex=0;
for (CodeValueData genderCodeValue:genderCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientPersonConstants.LOOKUP_GENDER_COL,row,genderCodeValue.getName()+"-"+genderCodeValue.getId());
}
rowIndex=0;
for (CodeValueData addressTypeCodeValue:addressTypesCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientPersonConstants.LOOKUP_ADDRESS_TYPE_COL,row,
addressTypeCodeValue.getName()+"-"+addressTypeCodeValue.getId());
}
rowIndex=0;
for (CodeValueData stateCodeValue:stateProvinceCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientPersonConstants.LOOKUP_STATE_PROVINCE_COL,row,stateCodeValue.getName()+"-"+stateCodeValue.getId());
}
rowIndex=0;
for (CodeValueData countryCodeValue: countryCodeValues) {
Row row =clientSheet.getRow(++rowIndex);
if(row==null)
row=clientSheet.createRow(rowIndex);
writeString(ClientPersonConstants.LOOKUP_COUNTRY_COL,row,countryCodeValue.getName()+"-"+countryCodeValue.getId());
}
}
private void setLayout(Sheet worksheet) {
Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT);
worksheet.setColumnWidth(ClientPersonConstants.FIRST_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.LAST_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.MIDDLE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
writeString(ClientPersonConstants.FIRST_NAME_COL, rowHeader, "First Name*");
writeString(ClientPersonConstants.LAST_NAME_COL, rowHeader, "Last Name*");
writeString(ClientPersonConstants.MIDDLE_NAME_COL, rowHeader, "Middle Name");
worksheet.setColumnWidth(ClientPersonConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.STAFF_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.SUBMITTED_ON_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.ACTIVE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.MOBILE_NO_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.DOB_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.CLIENT_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.GENDER_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.CLIENT_CLASSIFICATION_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.IS_STAFF_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_ENABLED_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.STREET_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_LINE_1_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_LINE_2_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_LINE_3_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.CITY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.STATE_PROVINCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.COUNTRY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.POSTAL_CODE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.IS_ACTIVE_ADDRESS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.WARNING_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.RELATIONAL_OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.RELATIONAL_OFFICE_OPENING_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_GENDER_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_CLIENT_TYPES_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_CLIENT_CLASSIFICATION_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_ADDRESS_TYPE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_STATE_PROVINCE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_COUNTRY_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE);
writeString(ClientPersonConstants.OFFICE_NAME_COL, rowHeader, "Office Name*");
writeString(ClientPersonConstants.STAFF_NAME_COL, rowHeader, "Staff Name");
writeString(ClientPersonConstants.EXTERNAL_ID_COL, rowHeader, "External ID ");
writeString(ClientPersonConstants.SUBMITTED_ON_COL,rowHeader,"Submitted On Date");
writeString(ClientPersonConstants.ACTIVATION_DATE_COL, rowHeader, "Activation date");
writeString(ClientPersonConstants.ACTIVE_COL, rowHeader, "Active*");
writeString(ClientPersonConstants.MOBILE_NO_COL, rowHeader, "Mobile number");
writeString(ClientPersonConstants.DOB_COL, rowHeader, "Date of Birth ");
writeString(ClientPersonConstants.CLIENT_TYPE_COL, rowHeader, "Client Type ");
writeString(ClientPersonConstants.IS_STAFF_COL, rowHeader, "Is a staff memeber ");
writeString(ClientPersonConstants.GENDER_COL, rowHeader, "Gender ");
writeString(ClientPersonConstants.ADDRESS_ENABLED_COL,rowHeader,"Address Enabled *");
writeString(ClientPersonConstants.CLIENT_CLASSIFICATION_COL, rowHeader, "Client Classification ");
writeString(ClientPersonConstants.ADDRESS_TYPE_COL, rowHeader, "Address Type ");
writeString(ClientPersonConstants.STREET_COL, rowHeader, "Street ");
writeString(ClientPersonConstants.ADDRESS_LINE_1_COL, rowHeader, "Address Line 1");
writeString(ClientPersonConstants.ADDRESS_LINE_2_COL, rowHeader, "Address Line 2");
writeString(ClientPersonConstants.ADDRESS_LINE_3_COL, rowHeader, "Address Line 3 ");
writeString(ClientPersonConstants.CITY_COL, rowHeader, "City ");
writeString(ClientPersonConstants.STATE_PROVINCE_COL, rowHeader, "State/ Province ");
writeString(ClientPersonConstants.COUNTRY_COL, rowHeader, "Country ");
writeString(ClientPersonConstants.POSTAL_CODE_COL, rowHeader, "Postal Code ");
writeString(ClientPersonConstants.IS_ACTIVE_ADDRESS_COL, rowHeader, "Is active Address ? ");
writeString(ClientPersonConstants.WARNING_COL, rowHeader, "All * marked fields are compulsory.");
writeString(ClientPersonConstants.RELATIONAL_OFFICE_NAME_COL, rowHeader, "Lookup office Name ");
writeString(ClientPersonConstants.RELATIONAL_OFFICE_OPENING_DATE_COL, rowHeader, "Lookup Office Opened Date ");
writeString(ClientPersonConstants.LOOKUP_GENDER_COL, rowHeader, "Lookup Gender ");
writeString(ClientPersonConstants.LOOKUP_CLIENT_TYPES_COL, rowHeader, "Lookup Client Types ");
writeString(ClientPersonConstants.LOOKUP_CLIENT_CLASSIFICATION_COL, rowHeader, "Lookup Client Classification ");
writeString(ClientPersonConstants.LOOKUP_ADDRESS_TYPE_COL, rowHeader, "Lookup AddressType ");
writeString(ClientPersonConstants.LOOKUP_STATE_PROVINCE_COL, rowHeader, "Lookup State/Province ");
writeString(ClientPersonConstants.LOOKUP_COUNTRY_COL, rowHeader, "Lookup Country ");
}
private void setRules(Sheet worksheet,String dateformat) {
CellRangeAddressList officeNameRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.OFFICE_NAME_COL, ClientPersonConstants.OFFICE_NAME_COL);
CellRangeAddressList staffNameRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. STAFF_NAME_COL,ClientPersonConstants. STAFF_NAME_COL);
CellRangeAddressList submittedOnDateRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. SUBMITTED_ON_COL, ClientPersonConstants.SUBMITTED_ON_COL);
CellRangeAddressList activationDateRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.ACTIVATION_DATE_COL, ClientPersonConstants.ACTIVATION_DATE_COL);
CellRangeAddressList activeRange = new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.ACTIVE_COL,ClientPersonConstants. ACTIVE_COL);
CellRangeAddressList clientTypeRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. CLIENT_TYPE_COL,ClientPersonConstants. CLIENT_TYPE_COL);
CellRangeAddressList dobRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. DOB_COL,ClientPersonConstants. DOB_COL);
CellRangeAddressList isStaffRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. IS_STAFF_COL,ClientPersonConstants. IS_STAFF_COL);
CellRangeAddressList genderRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.GENDER_COL,ClientPersonConstants. GENDER_COL);
CellRangeAddressList clientClassificationRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.CLIENT_CLASSIFICATION_COL, ClientPersonConstants.CLIENT_CLASSIFICATION_COL);
CellRangeAddressList enabledAddressRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.ADDRESS_ENABLED_COL, ClientPersonConstants.ADDRESS_ENABLED_COL);
CellRangeAddressList addressTypeRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. ADDRESS_TYPE_COL, ClientPersonConstants.ADDRESS_TYPE_COL);
CellRangeAddressList stateProvinceRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. STATE_PROVINCE_COL, ClientPersonConstants.STATE_PROVINCE_COL);
CellRangeAddressList countryRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.COUNTRY_COL, ClientPersonConstants.COUNTRY_COL);
CellRangeAddressList activeAddressRange=new CellRangeAddressList(1,
SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. IS_ACTIVE_ADDRESS_COL,ClientPersonConstants. IS_ACTIVE_ADDRESS_COL);
DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet);
List<OfficeData> offices = officeSheetPopulator.getOffices();
setNames(worksheet, offices);
DataValidationConstraint officeNameConstraint =
validationHelper.createFormulaListConstraint("Office");
DataValidationConstraint staffNameConstraint =
validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$D1))");
DataValidationConstraint submittedOnDateConstraint =
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL,
"=$I1" ,null,dateformat);
DataValidationConstraint activationDateConstraint =
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN,
"=VLOOKUP($D1,$AJ$2:$AK" + (offices.size() + 1) + ",2,FALSE)", "=TODAY()", dateformat);
DataValidationConstraint dobDateConstraint =
validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL,
"=TODAY()",null, dateformat);
DataValidationConstraint activeConstraint =
validationHelper.createExplicitListConstraint(new String[] {"True", "False"});
DataValidationConstraint clientTypesConstraint =
validationHelper.createFormulaListConstraint("ClientTypes");
DataValidationConstraint isStaffConstraint =
validationHelper.createExplicitListConstraint(new String[] {"True", "False"});
DataValidationConstraint genderConstraint =
validationHelper.createFormulaListConstraint("Gender");
DataValidationConstraint clientClassificationConstraint =
validationHelper.createFormulaListConstraint("ClientClassification");
DataValidationConstraint enabledAddressConstraint =
validationHelper.createExplicitListConstraint(new String[] {"True", "False"});
DataValidationConstraint addressTypeConstraint =
validationHelper.createFormulaListConstraint("AddressType");
DataValidationConstraint stateProvinceConstraint =
validationHelper.createFormulaListConstraint("StateProvince");
DataValidationConstraint countryConstraint =
validationHelper.createFormulaListConstraint("Country");
DataValidationConstraint activeAddressConstraint =
validationHelper.createExplicitListConstraint(new String[] {"True", "False"});
DataValidation officeValidation =
validationHelper.createValidation(officeNameConstraint, officeNameRange);
DataValidation staffValidation =
validationHelper.createValidation(staffNameConstraint, staffNameRange);
DataValidation submittedOnDateValidation =
validationHelper.createValidation(submittedOnDateConstraint, submittedOnDateRange);
DataValidation activationDateValidation =
validationHelper.createValidation(activationDateConstraint, activationDateRange);
DataValidation dobDateValidation =
validationHelper.createValidation(dobDateConstraint, dobRange);
DataValidation activeValidation =
validationHelper.createValidation(activeConstraint, activeRange);
DataValidation clientTypeValidation =
validationHelper.createValidation(clientTypesConstraint, clientTypeRange);
DataValidation isStaffValidation =
validationHelper.createValidation(isStaffConstraint, isStaffRange);
DataValidation genderValidation =
validationHelper.createValidation(genderConstraint, genderRange);
DataValidation clientClassificationValidation =
validationHelper.createValidation(clientClassificationConstraint, clientClassificationRange);
DataValidation enabledAddressValidation=
validationHelper.createValidation(enabledAddressConstraint,enabledAddressRange);
DataValidation addressTypeValidation =
validationHelper.createValidation(addressTypeConstraint, addressTypeRange);
DataValidation stateProvinceValidation =
validationHelper.createValidation(stateProvinceConstraint, stateProvinceRange);
DataValidation countryValidation =
validationHelper.createValidation(countryConstraint, countryRange);
DataValidation activeAddressValidation =
validationHelper.createValidation(activeAddressConstraint,activeAddressRange);
worksheet.addValidationData(activeValidation);
worksheet.addValidationData(officeValidation);
worksheet.addValidationData(staffValidation);
worksheet.addValidationData(activationDateValidation);
worksheet.addValidationData(submittedOnDateValidation);
worksheet.addValidationData(dobDateValidation);
worksheet.addValidationData(clientTypeValidation);
worksheet.addValidationData(isStaffValidation);
worksheet.addValidationData(genderValidation);
worksheet.addValidationData(clientClassificationValidation);
worksheet.addValidationData(enabledAddressValidation);
worksheet.addValidationData(addressTypeValidation);
worksheet.addValidationData(stateProvinceValidation);
worksheet.addValidationData(countryValidation);
worksheet.addValidationData(activeAddressValidation);
}
private void setNames(Sheet worksheet, List<OfficeData> offices) {
Workbook clientWorkbook = worksheet.getWorkbook();
Name officeGroup = clientWorkbook.createName();
officeGroup.setNameName("Office");
officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (offices.size() + 1));
Name clientTypeGroup = clientWorkbook.createName();
clientTypeGroup.setNameName("ClientTypes");
clientTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AN$2:$AN$" +
(clientTypeCodeValues.size() + 1));
Name genderGroup = clientWorkbook.createName();
genderGroup.setNameName("Gender");
genderGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AL$2:$AL$" + (genderCodeValues.size() + 1));
Name clientClassficationGroup = clientWorkbook.createName();
clientClassficationGroup.setNameName("ClientClassification");
clientClassficationGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AM$2:$AM$" +
(clientClassificationCodeValues.size() + 1));
Name addressTypeGroup = clientWorkbook.createName();
addressTypeGroup.setNameName("AddressType");
addressTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AO$2:$AO$" +
(addressTypesCodeValues.size() + 1));
Name stateProvinceGroup = clientWorkbook.createName();
stateProvinceGroup.setNameName("StateProvince");
stateProvinceGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AP$2:$AP$" +
(stateProvinceCodeValues.size() + 1));
Name countryGroup = clientWorkbook.createName();
countryGroup.setNameName("Country");
countryGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AQ$2:$AQ$" +
(countryCodeValues.size() + 1));
for (Integer i = 0; i < offices.size(); i++) {
Integer[] officeNameToBeginEndIndexesOfStaff =
personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i);
if (officeNameToBeginEndIndexesOfStaff != null) {
Name name = clientWorkbook.createName();
name.setNameName("Staff_" + offices.get(i).name().trim().replaceAll("[ )(]", "_"));
name.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" +
officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + officeNameToBeginEndIndexesOfStaff[1]);
}
}
}
}
@@ -0,0 +1,52 @@
/**
* 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.bulkimport.populator.comparator;
import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData;
import java.util.Comparator;
/**
* Sorting the loan values based on loan status giving priority to active loans
* */
public class LoanComparatorByStatusActive implements Comparator<LoanAccountData> {
@Override
public int compare(LoanAccountData o1, LoanAccountData o2) {
boolean isData1StatusActive = o1.getStatusStringValue().equals("Active");
boolean isData2StatusActive = o2.getStatusStringValue().equals("Active");
// if both status active, these have the same rank
if (isData1StatusActive && isData2StatusActive){
return 0;
}
if (isData1StatusActive){
return -1;
}
if (isData2StatusActive){
return 1;
}
// if no status active, these have the same rank
return 0;
}
}

Some files were not shown because too many files have changed in this diff Show More