fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From av...@apache.org
Subject [11/19] fineract git commit: all modules populate & import
Date Wed, 13 Dec 2017 09:03:24 GMT
http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositTransactionImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositTransactionImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositTransactionImportHandler.java
new file mode 100644
index 0000000..3715dbd
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositTransactionImportHandler.java
@@ -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);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsImportHandler.java
new file mode 100644
index 0000000..13c0f54
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsImportHandler.java
@@ -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;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsTransactionImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsTransactionImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsTransactionImportHandler.java
new file mode 100644
index 0000000..dfd562f
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsTransactionImportHandler.java
@@ -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);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/sharedaccount/SharedAccountImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/sharedaccount/SharedAccountImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/sharedaccount/SharedAccountImportHandler.java
new file mode 100644
index 0000000..63ce1c2
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/sharedaccount/SharedAccountImportHandler.java
@@ -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);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/staff/StaffImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/staff/StaffImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/staff/StaffImportHandler.java
new file mode 100644
index 0000000..a203c0a
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/staff/StaffImportHandler.java
@@ -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);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/users/UserImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/users/UserImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/users/UserImportHandler.java
new file mode 100644
index 0000000..c1ec639
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/users/UserImportHandler.java
@@ -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);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java
new file mode 100644
index 0000000..d92b903
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java
@@ -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();
+            }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/CenterSheetPopulator.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/CenterSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/CenterSheetPopulator.java
new file mode 100644
index 0000000..bf828b4
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/CenterSheetPopulator.java
@@ -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;
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ClientSheetPopulator.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ClientSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ClientSheetPopulator.java
new file mode 100644
index 0000000..69c4ba4
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ClientSheetPopulator.java
@@ -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;
+	}
+}
\ No newline at end of file


Mime
View raw message