You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by vo...@apache.org on 2020/06/03 20:25:45 UTC

[fineract] branch develop updated: FINERACT-1017: Fixing LoanImport integration tests

This is an automated email from the ASF dual-hosted git repository.

vorburger pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 14b14ae  FINERACT-1017: Fixing LoanImport integration tests
14b14ae is described below

commit 14b14aecac2538a6e12fa018a2f8cae504bb7a74
Author: Petri Tuomola <pe...@tuomola.org>
AuthorDate: Tue Jun 2 23:24:04 2020 +0300

    FINERACT-1017: Fixing LoanImport integration tests
---
 .../importhandler/loan/LoanImportHandlerTest.java  | 144 +++++++++++++--------
 .../importhandler/loan/LoanImportHandler.java      |  24 ++--
 .../bulkimport/populator/ExtrasSheetPopulator.java |   2 +-
 .../service/BulkImportWorkbookServiceImpl.java     |  18 +--
 .../main/resources/META-INF/spring/appContext.xml  |  10 ++
 5 files changed, 117 insertions(+), 81 deletions(-)

diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java
index 666eac7..b136646 100644
--- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java
@@ -18,9 +18,11 @@
  */
 package org.apache.fineract.integrationtests.bulkimport.importhandler.loan;
 
+import com.google.gson.Gson;
 import io.restassured.builder.RequestSpecBuilder;
 import io.restassured.builder.ResponseSpecBuilder;
 import io.restassured.http.ContentType;
+import io.restassured.path.json.JsonPath;
 import io.restassured.specification.RequestSpecification;
 import io.restassured.specification.ResponseSpecification;
 import java.io.File;
@@ -31,14 +33,20 @@ import java.io.OutputStream;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants;
 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.OfficeDomain;
 import org.apache.fineract.integrationtests.common.OfficeHelper;
+import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
 import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.integrationtests.common.funds.FundsHelper;
+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;
@@ -47,10 +55,16 @@ 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.Ignore;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class LoanImportHandlerTest {
+
+    private final static Logger LOG = LoggerFactory.getLogger(LoanImportHandlerTest.class);
+    private static final String CREATE_CLIENT_URL = "/fineract-provider/api/v1/clients?" + Utils.TENANT_IDENTIFIER;
+    public static final String DATE_FORMAT = "dd MMMM yyyy";
+
     private ResponseSpecification responseSpec;
     private RequestSpecification requestSpec;
 
@@ -63,49 +77,65 @@ public class LoanImportHandlerTest {
     }
 
     @Test
-    @Ignore
     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);
+        OfficeDomain office = officeHelper.retrieveOfficeByID(outcome_office_creation);
+        Assert.assertNotNull("Could not retrieve created office", office);
+
+        String firstName = Utils.randomNameGenerator("Client_FirstName_", 5);
+        String lastName = Utils.randomNameGenerator("Client_LastName_", 4);
+        String externalId = Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+
+        final HashMap<String, String> clientMap = new HashMap<>();
+        clientMap.put("officeId", outcome_office_creation.toString());
+        clientMap.put("firstname", firstName);
+        clientMap.put("lastname", lastName);
+        clientMap.put("externalId", externalId);
+        clientMap.put("dateFormat", DATE_FORMAT);
+        clientMap.put("locale", "en");
+        clientMap.put("active", "true");
+        clientMap.put("activationDate", "04 March 2011");
+
+        Integer outcome_client_creation= Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL,
+                new Gson().toJson(clientMap), "clientId");
         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);
+        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);
+        Integer outcome_staff_creation = StaffHelper.createStaff(requestSpec,responseSpec);
         Assert.assertNotNull("Could not create staff",outcome_staff_creation);
 
-       // LoanTransactionHelper ltHelper=new LoanTransactionHelper(requestSpec,responseSpec);
-       // LoanProductTestBuilder loanProductTestBuilder=new LoanProductTestBuilder();
-       // String jsonLoanProduct=loanProductTestBuilder.build(null);
-       // Integer outcome_lp_creaion=ltHelper.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);
+        Map<String, Object> staffMap = StaffHelper.getStaff(requestSpec, responseSpec, outcome_staff_creation);
+        Assert.assertNotNull("Could not retrieve created staff", staffMap);
+
+        LoanTransactionHelper ltHelper=new LoanTransactionHelper(requestSpec,responseSpec);
+        LoanProductTestBuilder loanProductTestBuilder=new LoanProductTestBuilder();
+        String jsonLoanProduct=loanProductTestBuilder.build(null);
+        Integer outcome_lp_creation=ltHelper.getLoanProductId(jsonLoanProduct);
+        Assert.assertNotNull("Could not create Loan Product" ,outcome_lp_creation);
+
+        String loanProductStr = ltHelper.getLoanProductDetails(requestSpec, responseSpec, outcome_lp_creation);
+        Assert.assertNotNull("Could not get created Loan Product" , loanProductStr);
+        JsonPath loanProductJson = JsonPath.from(loanProductStr);
+
+        String fundName = Utils.randomNameGenerator("",9);
+        FundsHelper fh = FundsHelper.create(fundName).externalId("fund-" + fundName).build();
+        Integer outcome_fund_creation= FundsResourceHandler.createFund(new Gson().toJson(fh),requestSpec,responseSpec);
+        Assert.assertNotNull("Could not create Fund" ,outcome_fund_creation);
+
+        String paymentTypeName = PaymentTypeHelper.randomNameGenerator("P_T", 5);
+        String paymentTypeDescription = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
+        Integer outcome_payment_creation= PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, paymentTypeName, paymentTypeDescription, true,1);
+        Assert.assertNotNull("Could not create payment type" ,outcome_payment_creation);
 
         LoanTransactionHelper loanTransactionHelper=new LoanTransactionHelper(requestSpec,responseSpec);
         Workbook workbook=loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy");
@@ -113,43 +143,39 @@ public class LoanImportHandlerTest {
         //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.OFFICE_NAME_COL).setCellValue(office.getName());
         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());
+        firstLoanRow.createCell(LoanConstants.CLIENT_NAME_COL).setCellValue(firstName + " " + lastName + "(" + outcome_client_creation + ")");
+        firstLoanRow.createCell(LoanConstants.CLIENT_EXTERNAL_ID).setCellValue(externalId);
+        firstLoanRow.createCell(LoanConstants.PRODUCT_COL).setCellValue(loanProductJson.getString("name"));
+        firstLoanRow.createCell(LoanConstants.LOAN_OFFICER_NAME_COL).setCellValue((String) staffMap.get("displayName"));
         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(60);
-        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.DISBURSED_PAYMENT_TYPE_COL).setCellValue(paymentTypeName);
+        firstLoanRow.createCell(LoanConstants.FUND_NAME_COL).setCellValue(fundName);
+        firstLoanRow.createCell(LoanConstants.PRINCIPAL_COL).setCellValue(loanProductJson.getFloat("principal"));
+        firstLoanRow.createCell(LoanConstants.NO_OF_REPAYMENTS_COL).setCellValue(loanProductJson.getInt("numberOfRepayments"));
+        firstLoanRow.createCell(LoanConstants.REPAID_EVERY_COL).setCellValue(loanProductJson.getInt("repaymentEvery"));
+        firstLoanRow.createCell(LoanConstants.REPAID_EVERY_FREQUENCY_COL).setCellValue(loanProductJson.getString("repaymentFrequencyType.value"));
+        firstLoanRow.createCell(LoanConstants.LOAN_TERM_COL).setCellValue(loanProductJson.getInt("repaymentEvery") * loanProductJson.getInt("numberOfRepayments"));
+        firstLoanRow.createCell(LoanConstants.LOAN_TERM_FREQUENCY_COL).setCellValue(loanProductJson.getString("repaymentFrequencyType.value"));
+        firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_COL).setCellValue(loanProductJson.getDouble("interestRatePerPeriod"));
+        firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL).setCellValue(loanProductJson.getString("interestRateFrequencyType.value"));
+        firstLoanRow.createCell(LoanConstants.AMORTIZATION_COL).setCellValue(loanProductJson.getString("amortizationType.value"));
+        firstLoanRow.createCell(LoanConstants.INTEREST_METHOD_COL).setCellValue(loanProductJson.getString("interestType.value"));
+        firstLoanRow.createCell(LoanConstants.INTEREST_CALCULATION_PERIOD_COL).setCellValue(loanProductJson.getString("interestCalculationPeriodType.value"));
         firstLoanRow.createCell(LoanConstants.ARREARS_TOLERANCE_COL).setCellValue(0);
-        firstLoanRow.createCell(LoanConstants.REPAYMENT_STRATEGY_COL).setCellValue(loanProductSheet.getRow(1).getCell(19).getStringCellValue());
+        firstLoanRow.createCell(LoanConstants.REPAYMENT_STRATEGY_COL).setCellValue(loanProductJson.getString("transactionProcessingStrategyName"));
         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());
+        firstLoanRow.createCell(LoanConstants.REPAYMENT_TYPE_COL).setCellValue(paymentTypeName);
 
         String currentdirectory = new File("").getAbsolutePath();
         File directory=new File(currentdirectory+File.separator+"src"+File.separator+"integrationTest"+File.separator+
@@ -172,10 +198,14 @@ public class LoanImportHandlerTest {
         //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);
+        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());
 
+        LOG.info("Output location: {}", location);
+        LOG.info("Failure reason column: {}", row.getCell(LoanConstants.FAILURE_REPORT_COL).getStringCellValue());
+
+        Assert.assertEquals("Imported",row.getCell(LoanConstants.STATUS_COL).getStringCellValue());
+        outputworkbook.close();
     }
 }
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java
index a7e3e3c..71c6ea0 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java
@@ -111,9 +111,9 @@ public class LoanImportHandler implements ImportHandler {
         if (repaymentAmount!=null&&lastRepaymentDate!=null&&repaymentType!=null&&repaymentTypeId!=null) {
             return LoanTransactionData.importInstance(repaymentAmount, lastRepaymentDate, repaymentTypeId,
                     row.getRowNum(), locale, dateFormat);
-        } else {
-            return null;
         }
+
+        return null;
     }
 
     private DisbursementData readDisbursalData(Row row,String locale,String dateFormat) {
@@ -133,9 +133,9 @@ public class LoanImportHandler implements ImportHandler {
         LocalDate approvedDate = ImportHandlerUtils.readAsDate(LoanConstants.APPROVED_DATE_COL, row);
         if (approvedDate!=null) {
             return LoanApprovalData.importInstance(approvedDate, row.getRowNum(), locale, dateFormat);
-        } else {
-            return null;
         }
+
+        return null;
     }
 
     private LoanAccountData readLoan(Row row,String locale,String dateFormat) {
@@ -324,9 +324,9 @@ public class LoanImportHandler implements ImportHandler {
                         repaymentStrategyId, graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged,
                         interestChargedFromDate, firstRepaymentOnDate, row.getRowNum(), externalId, linkAccountId,locale,dateFormat);
             }
-        }else {
-            return null;
         }
+
+        return null;
     }
 
     public Count importEntity(String dateFormat) {
@@ -419,7 +419,8 @@ public class LoanImportHandler implements ImportHandler {
                 .loanRepaymentTransaction(result.getLoanId()) //
                 .withJson(payload) //
                 .build(); //
-        final CommandProcessingResult loanRepaymentResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+
+        commandsSourceWritePlatformService.logCommandSource(commandRequest);
         return 4;
     }
 
@@ -436,14 +437,15 @@ public class LoanImportHandler implements ImportHandler {
                         .disburseLoanToSavingsApplication(result.getLoanId()) //
                         .withJson(payload) //
                         .build(); //
-                final CommandProcessingResult loanDisburseToSavingsResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+                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);
+
+                commandsSourceWritePlatformService.logCommandSource(commandRequest);
             }
         }
         return 3;
@@ -458,7 +460,8 @@ public class LoanImportHandler implements ImportHandler {
                     .approveLoanApplication(result.getLoanId()) //
                     .withJson(payload) //
                     .build(); //
-            final CommandProcessingResult loanapprovalresult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+
+            commandsSourceWritePlatformService.logCommandSource(commandRequest);
         }
         return 2;
     }
@@ -471,6 +474,7 @@ public class LoanImportHandler implements ImportHandler {
         loanJsonOb.remove("isLoanProductLinkedToFloatingRate");
         loanJsonOb.remove("isInterestRecalculationEnabled");
         loanJsonOb.remove("isFloatingInterestRate");
+        loanJsonOb.remove("isRatesEnabled");
         JsonArray chargesJsonAr=loanJsonOb.getAsJsonArray("charges");
         if (chargesJsonAr!=null) {
             for (int i = 0; i < chargesJsonAr.size(); i++) {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ExtrasSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ExtrasSheetPopulator.java
index 95855ba..b54066e 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ExtrasSheetPopulator.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ExtrasSheetPopulator.java
@@ -72,7 +72,7 @@ public class ExtrasSheetPopulator extends AbstractWorkbookPopulator {
         int currencyCodeRowIndex = 1;
         for (CurrencyData currencies : currencies) {
             Row row;
-            if (currencyCodeRowIndex < paymentTypeRowIndex) {
+            if (currencyCodeRowIndex < paymentTypeRowIndex || currencyCodeRowIndex < fundRowIndex) {
                 row = extrasSheet.getRow(currencyCodeRowIndex++);
             } else {
                 row = extrasSheet.createRow(currencyCodeRowIndex++);
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookServiceImpl.java
index f25d1de..3f75f04 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookServiceImpl.java
@@ -18,7 +18,6 @@
  */
 package org.apache.fineract.infrastructure.bulkimport.service;
 
-import com.google.common.io.Files;
 import com.sun.jersey.core.header.FormDataContentDisposition;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -33,10 +32,8 @@ import javax.ws.rs.core.Response;
 import org.apache.fineract.infrastructure.bulkimport.data.BulkImportEvent;
 import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
 import org.apache.fineract.infrastructure.bulkimport.data.ImportData;
-import org.apache.fineract.infrastructure.bulkimport.data.ImportFormatType;
 import org.apache.fineract.infrastructure.bulkimport.domain.ImportDocument;
 import org.apache.fineract.infrastructure.bulkimport.domain.ImportDocumentRepository;
-import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
 import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
 import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
 import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
@@ -61,7 +58,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
-import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Service;
 
 @Service
@@ -102,8 +98,6 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
                 final Tika tika = new Tika();
                 final TikaInputStream tikaInputStream = TikaInputStream.get(clonedInputStream);
                 final String fileType = tika.detect(tikaInputStream);
-                final String fileExtension = Files.getFileExtension(fileDetail.getFileName()).toLowerCase();
-                ImportFormatType format = ImportFormatType.of(fileExtension);
                 if (!fileType.contains("msoffice") && !fileType.contains("application/vnd.ms-excel")) {
                     // We had a problem where we tried to upload the downloaded file from the import options, it was somehow changed the
                     // extension we use this fix.
@@ -114,7 +108,6 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
                 Workbook workbook = new HSSFWorkbook(clonedInputStreamWorkbook);
                 GlobalEntityType entityType=null;
                 int primaryColumn=0;
-                ImportHandler importHandler = null;
                 if (entity.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_PERSON.toString())) {
                     entityType = GlobalEntityType.CLIENTS_PERSON;
                     primaryColumn = 0;
@@ -173,14 +166,15 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
                     entityType = GlobalEntityType.USERS;
                     primaryColumn = 0;
                 }else{
+                    workbook.close();
                     throw new GeneralPlatformDomainRuleException("error.msg.unable.to.find.resource",
                             "Unable to find requested resource");
+
                 }
                 return publishEvent(primaryColumn, fileDetail, clonedInputStreamWorkbook, entityType,
                         workbook, locale, dateFormat);
-            }else {
-                throw new GeneralPlatformDomainRuleException("error.msg.null","One or more of the given parameters not found");
             }
+            throw new GeneralPlatformDomainRuleException("error.msg.null","One or more of the given parameters not found");
         } catch (IOException e) {
             LOG.error("Problem occurred in importWorkbook function",e);
             throw new GeneralPlatformDomainRuleException("error.msg.io.exception","IO exception occured with "+fileDetail.getFileName()+" "+e.getMessage());
@@ -196,8 +190,6 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
 
         final String fileName = fileDetail.getFileName();
 
-        SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
-
         final Long documentId = this.documentWritePlatformService.createInternalDocument(
                 DocumentWritePlatformServiceJpaRepositoryImpl.DocumentManagementEntity.IMPORT.name(),
                 this.securityContext.authenticatedUser().getId(), null, clonedInputStreamWorkbook,
@@ -280,7 +272,7 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
         String fileName="Output"+documentData.fileName();
         String fileLocation=documentData.fileLocation();
         File file=new File(fileLocation);
-        final Response.ResponseBuilder response = Response.ok((Object)file);
+        final Response.ResponseBuilder response = Response.ok(file);
         response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
         response.header("Content-Type", "application/vnd.ms-excel");
         return response.build();
@@ -295,7 +287,7 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
             return sql.toString();
         }
             @Override
-            public DocumentData mapRow (ResultSet rs,int rowNum) throws SQLException {
+            public DocumentData mapRow (ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
                 final String location = rs.getString("location");
                 final String fileName=rs.getString("file_name");
                 return new DocumentData(null,null,null,null,fileName,
diff --git a/fineract-provider/src/main/resources/META-INF/spring/appContext.xml b/fineract-provider/src/main/resources/META-INF/spring/appContext.xml
index 6e04144..af5e9c0 100644
--- a/fineract-provider/src/main/resources/META-INF/spring/appContext.xml
+++ b/fineract-provider/src/main/resources/META-INF/spring/appContext.xml
@@ -100,6 +100,16 @@
 			<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
 		</property>
 	</bean>
+	
+	<!--  The application events (for importing) rely on the inheritable thread local security context strategy
+		  This is NOT compatible with threadpools so if we use threadpools the below will need to be reworked -->
+	<bean
+        class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+        <property name="targetClass"
+            value="org.springframework.security.core.context.SecurityContextHolder" />
+        <property name="targetMethod" value="setStrategyName" />
+        <property name="arguments" value="MODE_INHERITABLETHREADLOCAL" />
+    </bean>
 
 	<import resource="spmContext.xml"/>