Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 660C0200CDF for ; Thu, 17 Aug 2017 08:38:05 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 645CB16A5D8; Thu, 17 Aug 2017 06:38:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A8ABB16A5D3 for ; Thu, 17 Aug 2017 08:38:04 +0200 (CEST) Received: (qmail 89821 invoked by uid 500); 17 Aug 2017 06:38:03 -0000 Mailing-List: contact issues-help@fineract.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@fineract.apache.org Delivered-To: mailing list issues@fineract.apache.org Received: (qmail 89812 invoked by uid 99); 17 Aug 2017 06:38:03 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Aug 2017 06:38:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 85D9AE0014; Thu, 17 Aug 2017 06:38:02 +0000 (UTC) From: nazeer1100126 To: issues@fineract.apache.org Reply-To: issues@fineract.apache.org References: In-Reply-To: Subject: [GitHub] fineract pull request #403: Extend-mifos-data-import-tool chartOfAccounts po... Content-Type: text/plain Message-Id: <20170817063802.85D9AE0014@git1-us-west.apache.org> Date: Thu, 17 Aug 2017 06:38:02 +0000 (UTC) archived-at: Thu, 17 Aug 2017 06:38:05 -0000 Github user nazeer1100126 commented on a diff in the pull request: https://github.com/apache/fineract/pull/403#discussion_r133632867 --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/AbstractImportHandler.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; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.poi.ss.usermodel.*; +import org.joda.time.LocalDate; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Iterator; + +public abstract class AbstractImportHandler implements ImportHandler { + + protected Integer getNumberOfRows(Sheet sheet, int primaryColumn) { + Integer noOfEntries = 1; + // getLastRowNum and getPhysicalNumberOfRows showing false values + // sometimes + while (sheet.getRow(noOfEntries) !=null && sheet.getRow(noOfEntries).getCell(primaryColumn) != null) { + noOfEntries++; + } + + return noOfEntries; + } + + protected boolean isNotImported(Row row, int statusColumn) { + return !readAsString(statusColumn, row).equals("Imported"); + } + + protected Long readAsLong(int colIndex, Row row) { + try { + Cell c = row.getCell(colIndex); + if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) + return null; + FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { + CellValue val = null; + try { + val = eval.evaluate(c); + } catch (NullPointerException npe) { + return null; + } + return ((Double) val.getNumberValue()).longValue(); + } + return ((Double) c.getNumericCellValue()).longValue(); + } catch (RuntimeException re) { + return Long.parseLong(row.getCell(colIndex).getStringCellValue()); --- End diff -- if cell value is not numeric then in return it will throw exception. Handle the same scenario in other places also. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---