aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
committerSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
commitc72d565bb58226b20625b2bce5f0019046bee649 (patch)
tree8658e49595705b02e47ddc14afa20d6bb7123547 /vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java
parentef8a6b47847012fd59ea20da21d8d3d7c4a301ed (diff)
Merge 1806 code of vid-common
Change-Id: I75d52abed4a24dfe3827d79edc4a2938726aa87a Issue-ID: VID-208 Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java45
1 files changed, 24 insertions, 21 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java
index e0100e5be..6f5f4f732 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java
@@ -8,7 +8,6 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.ws.rs.BadRequestException;
-import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -25,7 +24,7 @@ public class CsvServiceImpl implements CsvService{
/** The logger. */
static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CsvServiceImpl.class);
- private static final String arrayRegex = "\\[(.*?)\\]";
+ private static final String ARRAY_REGEX = "\\[(.*?)\\]";
/**
@@ -216,33 +215,37 @@ public class CsvServiceImpl implements CsvService{
String key = currentRow[j];
if (j == length-1) {
json = putJson(json,currentRow[j],null);
+ }
+ else
+ {
+ json = buildJsonRow(myEntries, i, j, json, currentRow, length, currentDuplicateRows, key);
+ }
+ i += currentDuplicateRows;
+ }
+ logger.debug(EELFLoggerDelegate.debugLogger, "end {} json = {}", getMethodName(), json);
+ return json;
+ }
+ private <T> T buildJsonRow(List<String[]> myEntries, int i, int j, T json, String[] currentRow, int length, int currentDuplicateRows, String key) throws IllegalAccessException, InstantiationException {
+ if (key.matches(ARRAY_REGEX)){
+ JSONArray arrayObjects = buildJSON(myEntries, i, j + 1, currentDuplicateRows, JSONArray.class);
+ json = putJson(json,key.replaceAll("\\[","").replaceAll("]",""),arrayObjects);
+ }
+ else {
+ if (j < length - 2) {
+ json = putJson(json, currentRow[j], buildJSON(myEntries, i, j + 1, currentDuplicateRows, JSONObject.class));
}
else
{
- if (key.matches(arrayRegex)){
- JSONArray arrayObjects = buildJSON(myEntries, i, j + 1, currentDuplicateRows, JSONArray.class);
- json = putJson(json,key.replaceAll("\\[","").replaceAll("]",""),arrayObjects);
- }
- else {
- if (j < length - 2) {
- json = putJson(json, currentRow[j], buildJSON(myEntries, i, j + 1, currentDuplicateRows, JSONObject.class));
- }
- else
- {
- if (j == length - 2)//last object
- {
- if(currentDuplicateRows > 1) {
- throw new BadRequestException("Invalid csv file");
- }
- json = putJson(json, currentRow[j], currentRow[j + 1]);
- }
+ if (j == length - 2)//last object
+ {
+ if(currentDuplicateRows > 1) {
+ throw new BadRequestException("Invalid csv file");
}
+ json = putJson(json, currentRow[j], currentRow[j + 1]);
}
}
- i += currentDuplicateRows;
}
- logger.debug(EELFLoggerDelegate.debugLogger, "end {} json = {}", getMethodName(), json);
return json;
}