From 62535d81db2aa956d4a6e5220ed87980aa60b15f Mon Sep 17 00:00:00 2001 From: yamelsenih Date: Sat, 21 Dec 2024 19:05:33 -0400 Subject: [PATCH] Fixed error with parse data References: https://github.com/solop-develop/frontend-core/issues/67 --- .../ImportFileLoaderServiceLogic.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/spin/grpc/service/form/import_file_loader/ImportFileLoaderServiceLogic.java b/src/main/java/org/spin/grpc/service/form/import_file_loader/ImportFileLoaderServiceLogic.java index 76250eae..7dbb9d51 100644 --- a/src/main/java/org/spin/grpc/service/form/import_file_loader/ImportFileLoaderServiceLogic.java +++ b/src/main/java/org/spin/grpc/service/form/import_file_loader/ImportFileLoaderServiceLogic.java @@ -13,15 +13,15 @@ * along with this program. If not, see . * ************************************************************************************/ package org.spin.grpc.service.form.import_file_loader; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; import java.io.BufferedReader; +import java.io.InputStream; import java.io.InputStreamReader; import java.math.BigDecimal; import java.nio.charset.Charset; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.stream.Collectors; import org.adempiere.core.domains.models.I_AD_ImpFormat; @@ -582,27 +582,32 @@ public static ListEntitiesResponse.Builder listFilePreview(ListFilePreviewReques info = ""; } } - String entry = info; - + String entry = row.parse(info); + // TODO: Reuse ADempiere Parser Value.Builder valueBuilder = Value.newBuilder(); - if (row.isDate()) { - Timestamp dateValue = Timestamp.valueOf(entry); - valueBuilder = ValueManager.getValueFromTimestamp(dateValue); - } else if (row.isNumber()) { - BigDecimal numberValue = null; - if (!Util.isEmpty(entry, true)) { - numberValue = new BigDecimal(entry); - if (row.isDivideBy100()) { - numberValue = numberValue.divide( - BigDecimal.valueOf(100) - ); + if(!Util.isEmpty(entry)) { + try { + if (row.isDate()) { + Timestamp dateValue = Timestamp.valueOf(entry); + valueBuilder = ValueManager.getValueFromTimestamp(dateValue); + } else if (row.isNumber()) { + BigDecimal numberValue = null; + if (!Util.isEmpty(entry, true)) { + numberValue = new BigDecimal(entry); + if (row.isDivideBy100()) { + numberValue = numberValue.divide( + BigDecimal.valueOf(100) + ); + } + } + valueBuilder = ValueManager.getValueFromBigDecimal(numberValue); + } else { + valueBuilder = ValueManager.getValueFromString(entry); } + } catch (Exception e) { + e.printStackTrace(); } - valueBuilder = ValueManager.getValueFromBigDecimal(numberValue); - } else { - valueBuilder = ValueManager.getValueFromString(entry); } - lineValues.putFields( row.getColumnName(), valueBuilder.build()