http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientPersonImportHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientPersonImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientPersonImportHandler.java new file mode 100644 index 0000000..34e0fae --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientPersonImportHandler.java @@ -0,0 +1,197 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.client; + +import com.google.gson.GsonBuilder; +import org.apache.fineract.commands.domain.CommandWrapper; +import org.apache.fineract.commands.service.CommandWrapperBuilder; +import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; +import org.apache.fineract.infrastructure.bulkimport.constants.ClientPersonConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.Count; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.fineract.portfolio.address.data.AddressData; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.poi.ss.usermodel.*; +import org.joda.time.LocalDate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ClientPersonImportHandler implements ImportHandler { + + private Workbook workbook; + private List<ClientData> clients; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public ClientPersonImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook = workbook; + this.clients=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME); + Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(clientSheet,0); + for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){ + Row row; + row=clientSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, ClientPersonConstants.STATUS_COL)){ + clients.add(readClient(row,locale,dateFormat)); + } + } + } + + private ClientData readClient(Row row,final String locale, final String dateFormat) { + Long legalFormId=1L; + String firstName = ImportHandlerUtils.readAsString(ClientPersonConstants.FIRST_NAME_COL, row); + String lastName = ImportHandlerUtils.readAsString(ClientPersonConstants.LAST_NAME_COL, row); + String middleName = ImportHandlerUtils.readAsString(ClientPersonConstants.MIDDLE_NAME_COL, row); + String officeName = ImportHandlerUtils.readAsString(ClientPersonConstants.OFFICE_NAME_COL, row); + Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName); + String staffName = ImportHandlerUtils.readAsString(ClientPersonConstants.STAFF_NAME_COL, row); + Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName); + String externalId = ImportHandlerUtils.readAsString(ClientPersonConstants.EXTERNAL_ID_COL, row); + LocalDate submittedOn=ImportHandlerUtils.readAsDate(ClientPersonConstants.SUBMITTED_ON_COL,row); + LocalDate activationDate = ImportHandlerUtils.readAsDate(ClientPersonConstants.ACTIVATION_DATE_COL, row); + Boolean active = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.ACTIVE_COL, row); + if (!active){ + activationDate=submittedOn; + } + String mobileNo=null; + if (ImportHandlerUtils.readAsLong(ClientPersonConstants.MOBILE_NO_COL, row)!=null) + mobileNo = ImportHandlerUtils.readAsLong(ClientPersonConstants.MOBILE_NO_COL, row).toString(); + LocalDate dob = ImportHandlerUtils.readAsDate(ClientPersonConstants.DOB_COL, row); + + String clientType=ImportHandlerUtils.readAsString(ClientPersonConstants.CLIENT_TYPE_COL, row); + Long clientTypeId = null; + if (clientType!=null) { + String clientTypeAr[] = clientType.split("-"); + if (clientTypeAr[1] != null) { + clientTypeId = Long.parseLong(clientTypeAr[1]); + } + } + String gender=ImportHandlerUtils.readAsString(ClientPersonConstants.GENDER_COL, row); + Long genderId = null; + if (gender!=null) { + String genderAr[] = gender.split("-"); + if (genderAr[1] != null) + genderId = Long.parseLong(genderAr[1]); + } + String clientClassification= ImportHandlerUtils.readAsString(ClientPersonConstants.CLIENT_CLASSIFICATION_COL, row); + Long clientClassicationId = null; + if (clientClassification!=null) { + String clientClassificationAr[] = clientClassification.split("-"); + if (clientClassificationAr[1] != null) + clientClassicationId = Long.parseLong(clientClassificationAr[1]); + } + Boolean isStaff = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.IS_STAFF_COL, row); + + AddressData addressDataObj=null; + if (ImportHandlerUtils.readAsBoolean(ClientPersonConstants.ADDRESS_ENABLED_COL,row)) { + String addressType=ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_TYPE_COL, row); + Long addressTypeId = null; + if (addressType!=null) { + String addressTypeAr[] = addressType.split("-"); + + if (addressTypeAr[1] != null) + addressTypeId = Long.parseLong(addressTypeAr[1]); + } + String street = ImportHandlerUtils.readAsString(ClientPersonConstants.STREET_COL, row); + String addressLine1 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_1_COL, row); + String addressLine2 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_2_COL, row); + String addressLine3 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_3_COL, row); + String city = ImportHandlerUtils.readAsString(ClientPersonConstants.CITY_COL, row); + + String postalCode = ImportHandlerUtils.readAsString(ClientPersonConstants.POSTAL_CODE_COL, row); + Boolean isActiveAddress = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.IS_ACTIVE_ADDRESS_COL, row); + + String stateProvince=ImportHandlerUtils.readAsString(ClientPersonConstants.STATE_PROVINCE_COL, row); + Long stateProvinceId = null; + if (stateProvince!=null) { + String stateProvinceAr[] = stateProvince.split("-"); + if (stateProvinceAr[1] != null) + stateProvinceId = Long.parseLong(stateProvinceAr[1]); + } + String country=ImportHandlerUtils.readAsString(ClientPersonConstants.COUNTRY_COL, row); + Long countryId=null; + if (country!=null) { + String countryAr[] = country.split("-"); + if (countryAr[1] != null) + countryId = Long.parseLong(countryAr[1]); + } + addressDataObj = new AddressData(addressTypeId, street, addressLine1, addressLine2, addressLine3, + city, postalCode, isActiveAddress, stateProvinceId, countryId); + } + return ClientData.importClientPersonInstance(legalFormId,row.getRowNum(),firstName,lastName,middleName,submittedOn,activationDate,active,externalId, + officeId,staffId,mobileNo,dob,clientTypeId,genderId,clientClassicationId,isStaff,addressDataObj,locale,dateFormat); + + } + + public Count importEntity(String dateFormat) { + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + for (ClientData client: clients) { + try { + String payload=gsonBuilder.create().toJson(client); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createClient() // + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = clientSheet.getRow(client.getRowIndex()).createCell(ClientPersonConstants.STATUS_COL); + statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN)); + }catch (RuntimeException ex){ + errorCount++; + ex.printStackTrace(); + errorMessage=ImportHandlerUtils.getErrorMessage(ex); + ImportHandlerUtils.writeErrorMessage(clientSheet,client.getRowIndex(),errorMessage,ClientPersonConstants.STATUS_COL); + } + } + clientSheet.setColumnWidth(ClientPersonConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(ClientPersonConstants.STATUS_COL, clientSheet. + getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), TemplatePopulateImportConstants.STATUS_COLUMN_HEADER); + + return Count.instance(successCount,errorCount); + } + + +}
http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositImportHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositImportHandler.java new file mode 100644 index 0000000..10118a5 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositImportHandler.java @@ -0,0 +1,390 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.fixeddeposits; + +import com.google.gson.*; +import org.apache.fineract.commands.domain.CommandWrapper; +import org.apache.fineract.commands.service.CommandWrapperBuilder; +import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; +import org.apache.fineract.infrastructure.bulkimport.constants.FixedDepositConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.Count; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataIdSerializer; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.data.EnumOptionData; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.fineract.portfolio.savings.data.*; +import org.apache.poi.ss.usermodel.*; +import org.joda.time.LocalDate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +@Service +public class FixedDepositImportHandler implements ImportHandler { + + private Workbook workbook; + + private List<FixedDepositAccountData> savings; + private List<SavingsApproval> approvalDates; + private List<SavingsActivation> activationDates; + private List<ClosingOfSavingsAccounts> closedOnDate; + private List<String> statuses; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public FixedDepositImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook = workbook; + savings=new ArrayList<>(); + approvalDates=new ArrayList<>(); + activationDates=new ArrayList<>(); + closedOnDate=new ArrayList<>(); + statuses=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = savingsSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, FixedDepositConstants.STATUS_COL)) { + savings.add(readSavings(row,locale,dateFormat)); + approvalDates.add(readSavingsApproval(row,locale,dateFormat)); + activationDates.add(readSavingsActivation(row,locale,dateFormat)); + closedOnDate.add(readSavingsClosed(row,locale,dateFormat)); + } + } + + } + + private ClosingOfSavingsAccounts readSavingsClosed(Row row,String locale,String dateFormat) { + LocalDate closedOnDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.CLOSED_ON_DATE, row); + Long onAccountClosureId = ImportHandlerUtils.readAsLong(FixedDepositConstants.ON_ACCOUNT_CLOSURE_ID, row); + Long toSavingsAccountId = ImportHandlerUtils.readAsLong(FixedDepositConstants.TO_SAVINGS_ACCOUNT_ID, row); + if (closedOnDate!=null) + return ClosingOfSavingsAccounts.importInstance(null, closedOnDate,onAccountClosureId,toSavingsAccountId, null, + row.getRowNum(),locale,dateFormat); + else + return null; + } + + private SavingsActivation readSavingsActivation(Row row,String locale,String dateFormat) { + LocalDate activationDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.ACTIVATION_DATE_COL, row); + if (activationDate!=null) + return SavingsActivation.importInstance(activationDate, row.getRowNum(),locale,dateFormat); + else + return null; + } + + private SavingsApproval readSavingsApproval(Row row,String locale,String dateFormat) { + LocalDate approvalDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.APPROVED_DATE_COL, row); + if (approvalDate!=null) + return SavingsApproval.importInstance(approvalDate, row.getRowNum(),locale,dateFormat); + else + return null; + } + + private FixedDepositAccountData readSavings(Row row,String locale,String dateFormat) { + + String productName = ImportHandlerUtils.readAsString(FixedDepositConstants.PRODUCT_COL, row); + Long productId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName); + String fieldOfficerName = ImportHandlerUtils.readAsString(FixedDepositConstants.FIELD_OFFICER_NAME_COL, row); + Long fieldOfficerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), fieldOfficerName); + LocalDate submittedOnDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.SUBMITTED_ON_DATE_COL, row); + String interestCompoundingPeriodType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, row); + Long interestCompoundingPeriodTypeId = null; + EnumOptionData interestCompoundingPeriodTypeEnum=null; + if (interestCompoundingPeriodType!=null) { + if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_DAILY)) + interestCompoundingPeriodTypeId = 1L; + else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_MONTHLY)) + interestCompoundingPeriodTypeId = 4L; + else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_QUARTERLY)) + interestCompoundingPeriodTypeId = 5L; + else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_SEMI_ANNUALLY)) + interestCompoundingPeriodTypeId = 6L; + else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY)) + interestCompoundingPeriodTypeId = 7L; + interestCompoundingPeriodTypeEnum = new EnumOptionData(interestCompoundingPeriodTypeId, null, null); + } + String interestPostingPeriodType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_POSTING_PERIOD_COL, row); + Long interestPostingPeriodTypeId = null; + + EnumOptionData interestPostingPeriodTypeEnum=null; + if (interestCompoundingPeriodType!=null) { + if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_MONTHLY)) + interestPostingPeriodTypeId = 4L; + else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_QUARTERLY)) + interestPostingPeriodTypeId = 5L; + else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY)) + interestPostingPeriodTypeId = 7L; + else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_BIANUALLY)) + interestPostingPeriodTypeId = 6L; + interestPostingPeriodTypeEnum = new EnumOptionData(interestPostingPeriodTypeId, null, null); + } + String interestCalculationType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_CALCULATION_COL, row); + EnumOptionData interestCalculationTypeEnum=null; + if (interestCalculationType!=null) { + Long interestCalculationTypeId = null; + if (interestCalculationType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAILY_BALANCE)) + interestCalculationTypeId = 1L; + else if (interestCalculationType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_AVG_BALANCE)) + interestCalculationTypeId = 2L; + interestCalculationTypeEnum = new EnumOptionData(interestCalculationTypeId, null, null); + } + String interestCalculationDaysInYearType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row); + Long interestCalculationDaysInYearTypeId = null; + EnumOptionData interestCalculationDaysInYearTypeEnum=null; + if (interestCalculationDaysInYearType!=null) { + if (interestCalculationDaysInYearType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_360)) + interestCalculationDaysInYearTypeId = 360L; + else if (interestCalculationDaysInYearType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_365)) + interestCalculationDaysInYearTypeId = 365L; + interestCalculationDaysInYearTypeEnum = new EnumOptionData(interestCalculationDaysInYearTypeId, null, null); + } + Integer lockinPeriodFrequency = ImportHandlerUtils.readAsInt(FixedDepositConstants.LOCKIN_PERIOD_COL, row); + String lockinPeriodFrequencyType = ImportHandlerUtils.readAsString(FixedDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, row); + + Long lockinPeriodFrequencyTypeId =null; + EnumOptionData lockinPeriodFrequencyTypeEnum=null; + if (lockinPeriodFrequencyType!=null) { + if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_DAYS)) + lockinPeriodFrequencyTypeId = 0L; + else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_WEEKS)) + lockinPeriodFrequencyTypeId = 1L; + else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_MONTHS)) + lockinPeriodFrequencyTypeId = 2L; + else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_YEARS)) + lockinPeriodFrequencyTypeId = 3L; + lockinPeriodFrequencyTypeEnum = new EnumOptionData(lockinPeriodFrequencyTypeId, null, null); + } + BigDecimal depositAmount=null; + if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.DEPOSIT_AMOUNT_COL, row)!=null) { + depositAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.DEPOSIT_AMOUNT_COL, row)); + } + Integer depositPeriod = ImportHandlerUtils.readAsInt(FixedDepositConstants.DEPOSIT_PERIOD_COL, row); + + String depositPeriodFrequency = ImportHandlerUtils.readAsString(FixedDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, row); + Long depositPeriodFrequencyId = null; + if (depositPeriodFrequency!=null) { + if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_DAYS)) + depositPeriodFrequencyId = 0L; + else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_WEEKS)) + depositPeriodFrequencyId = 1L; + else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_MONTHS)) + depositPeriodFrequencyId = 2L; + else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_YEARS)) + depositPeriodFrequencyId = 3L; + } + String externalId = ImportHandlerUtils.readAsString(FixedDepositConstants.EXTERNAL_ID_COL, row); + String clientName = ImportHandlerUtils.readAsString(FixedDepositConstants.CLIENT_NAME_COL, row); + + List<SavingsAccountChargeData> charges = new ArrayList<SavingsAccountChargeData>(); + + String charge1 = ImportHandlerUtils.readAsString(FixedDepositConstants.CHARGE_ID_1, row); + String charge2 = ImportHandlerUtils.readAsString(FixedDepositConstants.CHARGE_ID_2, row); + + if (charge1!=null) { + if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_1, row)!=null) + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_1, row), + BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_1, row)), + ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_1, row))); + }else { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_1, row), + null, + ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_1, row))); + } + + if (charge2!=null) { + if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_2, row)!=null) { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_2, row), + BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_2, row)), + ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_2, row))); + }else { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_2, row), + null, + ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_2, row))); + } + } + String status = ImportHandlerUtils.readAsString(FixedDepositConstants.STATUS_COL, row); + statuses.add(status); + Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName); + return FixedDepositAccountData.importInstance (clientId, productId, fieldOfficerId, submittedOnDate, + interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum, + interestCalculationDaysInYearTypeEnum, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum, + depositAmount, depositPeriod, depositPeriodFrequencyId, externalId, charges,row.getRowNum(),locale,dateFormat); + } + + public Count importEntity(String dateFormat) { + Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + int progressLevel = 0; + Long savingsId=null; + for (int i = 0; i < savings.size(); i++) { + Row row = savingsSheet.getRow(savings.get(i).getRowIndex()); + Cell statusCell = row.createCell(FixedDepositConstants.STATUS_COL); + Cell errorReportCell = row.createCell(FixedDepositConstants.FAILURE_REPORT_COL); + try { + String status = statuses.get(i); + progressLevel = getProgressLevel(status); + + if (progressLevel == 0) { + CommandProcessingResult result= importSavings(i,dateFormat); + savingsId = result.getSavingsId(); + progressLevel = 1; + } else + savingsId = ImportHandlerUtils.readAsLong(FixedDepositConstants.SAVINGS_ID_COL, savingsSheet.getRow(savings.get(i).getRowIndex())); + + if (progressLevel <= 1) progressLevel = importSavingsApproval(savingsId, i,dateFormat); + + if (progressLevel <= 2) progressLevel = importSavingsActivation(savingsId, i,dateFormat); + + if (progressLevel <= 3) progressLevel = importSavingsClosing(savingsId, i,dateFormat); + + successCount++; + statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN)); + }catch (RuntimeException ex){ + errorCount++; + ex.printStackTrace(); + errorMessage=ImportHandlerUtils.getErrorMessage(ex); + writeFixedDepositErrorMessage(savingsId,errorMessage,progressLevel,statusCell,errorReportCell,row); + } + + } + setReportHeaders(savingsSheet); + return Count.instance(successCount,errorCount); + } + private void writeFixedDepositErrorMessage(Long savingsId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){ + String status = ""; + if (progressLevel == 0) + status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED; + else if (progressLevel == 1) + status = TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED; + else if (progressLevel == 2) status = TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED; + statusCell.setCellValue(status); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED)); + + if (progressLevel > 0) row.createCell(FixedDepositConstants.SAVINGS_ID_COL).setCellValue(savingsId); + errorReportCell.setCellValue(errorMessage); + } + + private int importSavingsClosing(Long savingsId, int i,String dateFormat) { + if(closedOnDate.get(i)!=null) { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + String payload = gsonBuilder.create().toJson(closedOnDate.get(i)); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .closeFixedDepositAccount(savingsId)// + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + } + return 4; + } + + private CommandProcessingResult importSavings(int i,String dateFormat) { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataIdSerializer()); + JsonObject savingsJsonob=gsonBuilder.create().toJsonTree(savings.get(i)).getAsJsonObject(); + savingsJsonob.remove("withdrawalFeeForTransfers"); + JsonArray chargesJsonAr=savingsJsonob.getAsJsonArray("charges"); + for (int j=0;j<chargesJsonAr.size();j++){ + JsonElement chargesJsonElement=chargesJsonAr.get(j); + JsonObject chargeJsonOb =chargesJsonElement.getAsJsonObject(); + chargeJsonOb.remove("penalty"); + } + if (chargesJsonAr.get(0).getAsJsonObject().toString().equals("{}")) + savingsJsonob.remove("charges"); + String payload=savingsJsonob.toString(); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createFixedDepositAccount() // + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + return result; + } + + private int importSavingsApproval(Long savingsId, int i,String dateFormat) { + if(approvalDates.get(i)!=null) { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + String payload = gsonBuilder.create().toJson(approvalDates.get(i)); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .approveFixedDepositAccountApplication(savingsId)// + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + } + return 2; + } + + private int importSavingsActivation(Long savingsId, int i, String dateFormat) { + if(activationDates.get(i)!=null) { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + String payload = gsonBuilder.create().toJson(activationDates.get(i)); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .fixedDepositAccountActivation(savingsId)// + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + } + return 3; + } + + private int getProgressLevel(String status) { + if (status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED)) + return 0; + else if (status.equals(TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED)) + return 1; + else if (status.equals(TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED)) return 2; + return 0; + } + + private void setReportHeaders(Sheet savingsSheet) { + savingsSheet.setColumnWidth(FixedDepositConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + Row rowHeader = savingsSheet.getRow(0); + ImportHandlerUtils.writeString(FixedDepositConstants.STATUS_COL, rowHeader, TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(FixedDepositConstants.SAVINGS_ID_COL, rowHeader, TemplatePopulateImportConstants.SAVINGS_ID_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(FixedDepositConstants.FAILURE_REPORT_COL, rowHeader, TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER); + } + + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositTransactionImportHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositTransactionImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositTransactionImportHandler.java new file mode 100644 index 0000000..41b59ea --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositTransactionImportHandler.java @@ -0,0 +1,150 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE multipartFile + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this multipartFile + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this multipartFile except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.fixeddeposits; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import org.apache.fineract.commands.domain.CommandWrapper; +import org.apache.fineract.commands.service.CommandWrapperBuilder; +import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants; +import org.apache.fineract.infrastructure.bulkimport.data.Count; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.SavingsAccountTransactionEnumValueSerialiser; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionData; +import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData; +import org.apache.poi.ss.usermodel.*; +import org.joda.time.LocalDate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +@Service +public class FixedDepositTransactionImportHandler implements ImportHandler { + private Workbook workbook; + private List<SavingsAccountTransactionData> savingsTransactions; + private String savingsAccountId = ""; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + @Autowired + public FixedDepositTransactionImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.savingsTransactions=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_TRANSACTION_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsTransactionSheet, TransactionConstants.AMOUNT_COL); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = savingsTransactionSheet.getRow(rowIndex); + if(ImportHandlerUtils.isNotImported(row, TransactionConstants.STATUS_COL)) + savingsTransactions.add(readSavingsTransaction(row,locale,dateFormat)); + } + } + + private SavingsAccountTransactionData readSavingsTransaction(Row row,String locale,String dateFormat) { + String savingsAccountIdCheck=null; + if (ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row)!=null) + savingsAccountIdCheck = ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row).toString(); + if(savingsAccountIdCheck!=null) + savingsAccountId = savingsAccountIdCheck; + String transactionType = ImportHandlerUtils.readAsString(TransactionConstants.TRANSACTION_TYPE_COL, row); + SavingsAccountTransactionEnumData savingsAccountTransactionEnumData=new SavingsAccountTransactionEnumData(null,null,transactionType); + + BigDecimal amount=null; + if (ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)!=null) + amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)); + + LocalDate transactionDate = ImportHandlerUtils.readAsDate(TransactionConstants.TRANSACTION_DATE_COL, row); + String paymentType = ImportHandlerUtils.readAsString(TransactionConstants.PAYMENT_TYPE_COL, row); + Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), paymentType); + String accountNumber = ImportHandlerUtils.readAsString(TransactionConstants.ACCOUNT_NO_COL, row); + String checkNumber = ImportHandlerUtils.readAsString(TransactionConstants.CHECK_NO_COL, row); + String routingCode = ImportHandlerUtils.readAsString(TransactionConstants.ROUTING_CODE_COL, row); + String receiptNumber = ImportHandlerUtils.readAsString(TransactionConstants.RECEIPT_NO_COL, row); + String bankNumber = ImportHandlerUtils.readAsString(TransactionConstants.BANK_NO_COL, row); + return SavingsAccountTransactionData.importInstance(amount, transactionDate, paymentTypeId, accountNumber, + checkNumber, routingCode, receiptNumber, bankNumber, Long.parseLong(savingsAccountId), savingsAccountTransactionEnumData, row.getRowNum(),locale,dateFormat); + + } + + public Count importEntity(String dateFormat) { + Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_TRANSACTION_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + gsonBuilder.registerTypeAdapter(SavingsAccountTransactionEnumData.class + ,new SavingsAccountTransactionEnumValueSerialiser()); + + for (SavingsAccountTransactionData transaction : savingsTransactions) { + try { + JsonObject savingsTransactionJsonob=gsonBuilder.create().toJsonTree(transaction).getAsJsonObject(); + savingsTransactionJsonob.remove("transactionType"); + savingsTransactionJsonob.remove("reversed"); + savingsTransactionJsonob.remove("interestedPostedAsOn"); + String payload= savingsTransactionJsonob.toString(); + CommandWrapper commandRequest=null; + if (transaction.getTransactionType().getValue().equals("Withdrawal")) { + commandRequest = new CommandWrapperBuilder() // + .fixedDepositAccountWithdrawal(transaction.getSavingsAccountId()) // + .withJson(payload) // + .build(); // + + }else if (transaction.getTransactionType().getValue().equals("Deposit")){ + commandRequest = new CommandWrapperBuilder() // + .fixedDepositAccountDeposit(transaction.getSavingsAccountId()) // + .withJson(payload) // + .build(); + } + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(TransactionConstants.STATUS_COL); + statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN)); + }catch (RuntimeException ex){ + errorCount++; + ex.printStackTrace(); + errorMessage=ImportHandlerUtils.getErrorMessage(ex); + ImportHandlerUtils.writeErrorMessage(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL); + } + } + savingsTransactionSheet.setColumnWidth(TransactionConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(TransactionConstants.STATUS_COL, savingsTransactionSheet.getRow(TransactionConstants.STATUS_COL), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + return Count.instance(successCount,errorCount); + } + + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/group/GroupImportHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/group/GroupImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/group/GroupImportHandler.java new file mode 100644 index 0000000..9fc91b4 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/group/GroupImportHandler.java @@ -0,0 +1,257 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE multipartFile + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this multipartFile + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this multipartFile except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.group; + +import com.google.common.reflect.TypeToken; +import com.google.gson.GsonBuilder; +import org.apache.fineract.commands.domain.CommandWrapper; +import org.apache.fineract.commands.service.CommandWrapperBuilder; +import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; +import org.apache.fineract.infrastructure.bulkimport.constants.GroupConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.Count; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.ClientIdSerializer; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataValueSerializer; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.data.EnumOptionData; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.fineract.portfolio.calendar.data.CalendarData; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.group.data.GroupGeneralData; +import org.apache.poi.ss.usermodel.*; +import org.joda.time.LocalDate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@Service +public class GroupImportHandler implements ImportHandler { + private List<GroupGeneralData> groups; + private List<CalendarData> meetings; + private Workbook workbook; + private List<String>statuses; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public GroupImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + groups=new ArrayList<>(); + meetings=new ArrayList<>(); + statuses=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(String locale, String dateFormat) { + Sheet groupsSheet = workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(groupsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = groupsSheet.getRow(rowIndex); + if(ImportHandlerUtils.isNotImported(row, GroupConstants.STATUS_COL)) { + groups.add(readGroup(row,locale,dateFormat)); + meetings.add(readMeeting(row,locale,dateFormat)); + } + } + } + + private CalendarData readMeeting(Row row,String locale,String dateFormat) { + LocalDate meetingStartDate = ImportHandlerUtils.readAsDate(GroupConstants.MEETING_START_DATE_COL, row); + Boolean isRepeating = ImportHandlerUtils.readAsBoolean(GroupConstants.IS_REPEATING_COL, row); + String frequency = ImportHandlerUtils.readAsString(GroupConstants.FREQUENCY_COL, row); + EnumOptionData frequencyEnum=new EnumOptionData(null,null,ImportHandlerUtils.getFrequencyId(frequency)); + Integer interval = ImportHandlerUtils.readAsInt(GroupConstants.INTERVAL_COL, row); + String repeatsOnDay = ImportHandlerUtils.readAsString(GroupConstants.REPEATS_ON_DAY_COL, row); + EnumOptionData repeatsOnDayEnum=new EnumOptionData(null,null,ImportHandlerUtils.getRepeatsOnDayId(repeatsOnDay)); + if(meetingStartDate==null) + return null; + else { + if(repeatsOnDay==null) + return CalendarData.importInstanceNoRepeatsOnDay(meetingStartDate, isRepeating, frequencyEnum, interval, row.getRowNum(),locale,dateFormat); + else + return CalendarData.importInstanceWithRepeatsOnDay(meetingStartDate, isRepeating, frequencyEnum, interval, repeatsOnDayEnum, row.getRowNum(),locale,dateFormat); + } + } + private GroupGeneralData readGroup(Row row,String locale,String dateFormat) { + String status = ImportHandlerUtils.readAsString(GroupConstants.STATUS_COL, row); + String officeName = ImportHandlerUtils.readAsString(GroupConstants.OFFICE_NAME_COL, row); + Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName); + String staffName = ImportHandlerUtils.readAsString(GroupConstants.STAFF_NAME_COL, row); + Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName); + String centerName = ImportHandlerUtils.readAsString(GroupConstants.CENTER_NAME_COL, row); + Long centerId=null; + if(centerName!=null) + centerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME), centerName); + String externalId = ImportHandlerUtils.readAsString(GroupConstants.EXTERNAL_ID_COL, row); + Boolean active = ImportHandlerUtils.readAsBoolean(GroupConstants.ACTIVE_COL, row); + LocalDate submittedOnDate=ImportHandlerUtils.readAsDate(GroupConstants.SUBMITTED_ON_DATE_COL,row); + LocalDate activationDate=null; + if(active) { + activationDate = ImportHandlerUtils.readAsDate(GroupConstants.ACTIVATION_DATE_COL, row); + }else { + activationDate=submittedOnDate; + } + String groupName = ImportHandlerUtils.readAsString(GroupConstants.NAME_COL, row); + if (groupName == null || groupName.equals("")) { + throw new IllegalArgumentException("Name is blank"); + } + List<ClientData> clientMembers = new ArrayList<>(); + for (int cellNo = GroupConstants.CLIENT_NAMES_STARTING_COL; cellNo <GroupConstants.CLIENT_NAMES_ENDING_COL; cellNo++) { + String clientName = ImportHandlerUtils.readAsString(cellNo, row); + if (clientName==null) + break; + Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName); + ClientData clientData = new ClientData(clientId); + if (!containsClientId(clientMembers,clientId)) { + clientMembers.add(clientData); + } + } + statuses.add(status); + return GroupGeneralData.importInstance(groupName, clientMembers, activationDate, submittedOnDate,active, externalId, + officeId, staffId, centerId, row.getRowNum(),locale,dateFormat); + } + + private boolean containsClientId(List<ClientData> clientMembers,Long clientId){ + for (ClientData client: clientMembers) { + if (client.getId()==clientId){ + return true; + } + } + return false; + } + + public Count importEntity(String dateFormat) { + Sheet groupSheet = workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + int successCount=0; + int errorCount=0; + int progressLevel = 0; + String groupId = ""; + String errorMessage=""; + for (int i = 0; i < groups.size(); i++) { + Row row = groupSheet.getRow(groups.get(i).getRowIndex()); + Cell errorReportCell = row.createCell(GroupConstants.FAILURE_COL); + Cell statusCell = row.createCell(GroupConstants.STATUS_COL); + CommandProcessingResult result=null; + try { + String status = statuses.get(i); + progressLevel = getProgressLevel(status); + + if(progressLevel == 0) + { + result = importGroup(i,dateFormat); + groupId = result.getGroupId().toString(); + progressLevel = 1; + } else + groupId = ImportHandlerUtils.readAsInt(GroupConstants.GROUP_ID_COL, groupSheet.getRow(groups.get(i).getRowIndex())).toString(); + + if(meetings.get(i) != null && groups.get(i).getCenterId() == null) + progressLevel = importGroupMeeting(result, i,dateFormat); + + statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN)); + }catch (RuntimeException ex){ + errorCount++; + ex.printStackTrace(); + errorMessage=ImportHandlerUtils.getErrorMessage(ex); + writeGroupErrorMessage(groupId,errorMessage,progressLevel,statusCell,errorReportCell,row); + } + } + setReportHeaders(groupSheet); + return Count.instance(successCount,errorCount); + } + private void writeGroupErrorMessage(String groupId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){ + String status = ""; + if(progressLevel == 0) + status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED; + else if(progressLevel == 1) + status =TemplatePopulateImportConstants.STATUS_MEETING_FAILED ; + statusCell.setCellValue(status); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED)); + + if(progressLevel>0) + row.createCell(GroupConstants.GROUP_ID_COL).setCellValue(Integer.parseInt(groupId)); + errorReportCell.setCellValue(errorMessage); + } + private void setReportHeaders(Sheet groupSheet) { + ImportHandlerUtils.writeString(GroupConstants.STATUS_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(GroupConstants.GROUP_ID_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.GROUP_ID_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(GroupConstants.FAILURE_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER); + } + + private Integer importGroupMeeting(CommandProcessingResult result, int rowIndex, String dateFormat) { + CalendarData calendarData=meetings.get(rowIndex); + calendarData.setTitle("group_" + result.getGroupId().toString() + "_CollectionMeeting"); + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataValueSerializer()); + + String payload = gsonBuilder.create().toJson(calendarData); + CommandWrapper commandWrapper=new CommandWrapper(result.getOfficeId(),result.getGroupId(), + result.getClientId(),result.getLoanId(),result.getSavingsId(),null, + null,null,null,null,payload,result.getTransactionId(), + result.getProductId(),null,null,null); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createCalendar(commandWrapper,TemplatePopulateImportConstants.CENTER_ENTITY_TYPE,result.getGroupId()) // + .withJson(payload) // + .build(); // + final CommandProcessingResult meetingresult = commandsSourceWritePlatformService.logCommandSource(commandRequest); + return 2; + } + + private CommandProcessingResult importGroup(int rowIndex, String dateFormat) { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + Type clientCollectionType = new TypeToken<Collection<ClientData>>() {}.getType(); + gsonBuilder.registerTypeAdapter(clientCollectionType,new ClientIdSerializer()); + String payload= gsonBuilder.create().toJson(groups.get(rowIndex));; + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createGroup() // + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + return result; + } + + private int getProgressLevel(String status) { + if(status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED)) + return 0; + else if(status.equals(TemplatePopulateImportConstants.STATUS_MEETING_FAILED)) + return 1; + return 0; + } + + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java new file mode 100644 index 0000000..e97443f --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java @@ -0,0 +1,151 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.guarantor; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import org.apache.fineract.commands.domain.CommandWrapper; +import org.apache.fineract.commands.service.CommandWrapperBuilder; +import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; +import org.apache.fineract.infrastructure.bulkimport.constants.GuarantorConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.Count; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils; +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.fineract.portfolio.loanaccount.guarantor.data.GuarantorData; +import org.apache.poi.ss.usermodel.*; +import org.joda.time.LocalDate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +@Service +public class GuarantorImportHandler implements ImportHandler { + private Workbook workbook; + private List<GuarantorData> guarantors; + private Long loanAccountId ; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + +@Autowired + public GuarantorImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.guarantors=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet addGuarantorSheet = workbook.getSheet(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(addGuarantorSheet, GuarantorConstants.LOAN_ACCOUNT_NO_COL); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = addGuarantorSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, GuarantorConstants.STATUS_COL)) + guarantors.add(ReadGuarantor(row,locale,dateFormat)); + + } + } + + private GuarantorData ReadGuarantor(Row row,String locale,String dateFormat) { + String loanaccountInfo=ImportHandlerUtils.readAsString(GuarantorConstants.LOAN_ACCOUNT_NO_COL, row); + if (loanaccountInfo!=null){ + String loanAccountAr[]=loanaccountInfo.split("-"); + loanAccountId=Long.parseLong(loanAccountAr[0]); + } + String guarantorType = ImportHandlerUtils.readAsString(GuarantorConstants.GUARANTO_TYPE_COL, row); + + Integer guarantorTypeId = null; + if (guarantorType!=null) { + if (guarantorType.equalsIgnoreCase(TemplatePopulateImportConstants.GUARANTOR_INTERNAL)) + guarantorTypeId = 1; + else if (guarantorType.equalsIgnoreCase(TemplatePopulateImportConstants.GUARANTOR_EXTERNAL)) + guarantorTypeId = 3; + } + String clientName = ImportHandlerUtils.readAsString(GuarantorConstants.ENTITY_ID_COL, row); + Long entityId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName); + String clientRelationshipTypeInfo=ImportHandlerUtils.readAsString(GuarantorConstants.CLIENT_RELATIONSHIP_TYPE_COL, row); + Integer clientRelationshipTypeId=null; + if (clientRelationshipTypeInfo!=null){ + String clientRelationshipTypeAr[]=clientRelationshipTypeInfo.split("-"); + clientRelationshipTypeId=Integer.parseInt(clientRelationshipTypeAr[1]); + } + String firstname = ImportHandlerUtils.readAsString(GuarantorConstants.FIRST_NAME_COL, row); + String lastname = ImportHandlerUtils.readAsString(GuarantorConstants.LAST_NAME_COL, row); + String addressLine1 = ImportHandlerUtils.readAsString(GuarantorConstants.ADDRESS_LINE_1_COL, row); + String addressLine2 = ImportHandlerUtils.readAsString(GuarantorConstants.ADDRESS_LINE_2_COL, row); + String city = ImportHandlerUtils.readAsString(GuarantorConstants.CITY_COL, row); + LocalDate dob = ImportHandlerUtils.readAsDate(GuarantorConstants.DOB_COL, row); + String zip = ImportHandlerUtils.readAsString(GuarantorConstants.ZIP_COL, row); + Integer savingsId = ImportHandlerUtils.readAsInt(GuarantorConstants.SAVINGS_ID_COL, row); + BigDecimal amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(GuarantorConstants.AMOUNT, row)); + + return GuarantorData.importInstance(guarantorTypeId,clientRelationshipTypeId,entityId,firstname, + lastname,addressLine1, addressLine2,city,dob,zip,savingsId,amount, row.getRowNum(), loanAccountId,locale,dateFormat); + } + + public Count importEntity(String dateFormat) { + Sheet addGuarantorSheet = workbook.getSheet(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder=new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + for (GuarantorData guarantor : guarantors) { + try { + JsonObject guarantorJsonob=gsonBuilder.create().toJsonTree(guarantor).getAsJsonObject(); + guarantorJsonob.remove("status"); + String payload = guarantorJsonob.toString(); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createGuarantor(guarantor.getAccountId()) // + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = addGuarantorSheet.getRow(guarantor.getRowIndex()).createCell(GuarantorConstants.STATUS_COL); + statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN)); + }catch (RuntimeException ex){ + errorCount++; + ex.printStackTrace(); + errorMessage=ImportHandlerUtils.getErrorMessage(ex); + ImportHandlerUtils.writeErrorMessage(addGuarantorSheet,guarantor.getRowIndex(),errorMessage,GuarantorConstants.STATUS_COL); + } + + } + addGuarantorSheet.setColumnWidth(GuarantorConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(GuarantorConstants.STATUS_COL, addGuarantorSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + return Count.instance(successCount,errorCount); + } + + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/ClientIdSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/ClientIdSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/ClientIdSerializer.java new file mode 100644 index 0000000..0dbe28c --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/ClientIdSerializer.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.helper; + +import com.google.gson.*; +import org.apache.fineract.portfolio.client.data.ClientData; + +import java.lang.reflect.Type; +import java.util.Collection; + +public class ClientIdSerializer implements JsonSerializer<Collection<ClientData>> { + + @Override + public JsonElement serialize(Collection<ClientData> src, Type typeOfSrc, JsonSerializationContext context) { + JsonArray clientIdJsonArray=new JsonArray(); + for (ClientData client:src) { + JsonElement clientIdElment=new JsonPrimitive(client.id().toString()); + clientIdJsonArray.add(clientIdElment); + } + return clientIdJsonArray; + } +} \ 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/importhandler/helper/CodeValueDataIdSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CodeValueDataIdSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CodeValueDataIdSerializer.java new file mode 100644 index 0000000..d5f4ef0 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CodeValueDataIdSerializer.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.infrastructure.codes.data.CodeValueData; + +import java.lang.reflect.Type; + +public class CodeValueDataIdSerializer implements JsonSerializer<CodeValueData> { + @Override + public JsonElement serialize(CodeValueData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getId()); + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CurrencyDateCodeSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CurrencyDateCodeSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CurrencyDateCodeSerializer.java new file mode 100644 index 0000000..c784bae --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CurrencyDateCodeSerializer.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.organisation.monetary.data.CurrencyData; + +import java.lang.reflect.Type; + +public class CurrencyDateCodeSerializer implements JsonSerializer<CurrencyData>{ + @Override + public JsonElement serialize(CurrencyData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.code()); + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/DateSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/DateSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/DateSerializer.java new file mode 100644 index 0000000..c7b7bc5 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/DateSerializer.java @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.joda.time.LocalDate; + +import java.lang.reflect.Type; + +public class DateSerializer implements JsonSerializer<LocalDate> { + + private final String dateFormat; + + public DateSerializer(String dateFormat) { + this.dateFormat = dateFormat; + } + + @Override + public JsonElement serialize(LocalDate src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toString(dateFormat)); + } +} \ 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/importhandler/helper/EnumOptionDataIdSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataIdSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataIdSerializer.java new file mode 100644 index 0000000..e95e2cb --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataIdSerializer.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.infrastructure.core.data.EnumOptionData; + +import java.lang.reflect.Type; + +public class EnumOptionDataIdSerializer implements JsonSerializer<EnumOptionData> { + @Override + public JsonElement serialize(EnumOptionData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getId()); + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataValueSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataValueSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataValueSerializer.java new file mode 100644 index 0000000..41b6ce3 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataValueSerializer.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.infrastructure.core.data.EnumOptionData; + +import java.lang.reflect.Type; + +public class EnumOptionDataValueSerializer implements JsonSerializer<EnumOptionData> { + @Override + public JsonElement serialize(EnumOptionData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getValue()); + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/GroupIdSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/GroupIdSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/GroupIdSerializer.java new file mode 100644 index 0000000..071a112 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/GroupIdSerializer.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE multipartFile + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this multipartFile + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this multipartFile except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.helper; + +import com.google.gson.*; +import org.apache.fineract.portfolio.group.data.GroupGeneralData; + +import java.lang.reflect.Type; +import java.util.Collection; + +public class GroupIdSerializer implements JsonSerializer<Collection<GroupGeneralData>> { + @Override + public JsonElement serialize(Collection<GroupGeneralData> src, Type typeOfSrc, JsonSerializationContext context) { + JsonArray groupIdJsonArray=new JsonArray(); + for (GroupGeneralData group:src) { + JsonElement groupIdElement=new JsonPrimitive(group.getId().toString()); + groupIdJsonArray.add(groupIdElement); + } + return groupIdJsonArray; + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/SavingsAccountTransactionEnumValueSerialiser.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/SavingsAccountTransactionEnumValueSerialiser.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/SavingsAccountTransactionEnumValueSerialiser.java new file mode 100644 index 0000000..4942d2d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/SavingsAccountTransactionEnumValueSerialiser.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.bulkimport.importhandler.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData; + +import java.lang.reflect.Type; + +public class SavingsAccountTransactionEnumValueSerialiser implements JsonSerializer<SavingsAccountTransactionEnumData> { + + @Override + public JsonElement serialize(SavingsAccountTransactionEnumData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getValue()); + } +}