aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authorshrek2000 <orenkle@amdocs.com>2018-01-09 16:00:28 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-01-10 13:50:33 +0000
commit38cf5fed407ed0aa5e7adb72c90b82bccccfe3e0 (patch)
treeb1da18c7547b084d07dd632189fb3a311dba4876 /openecomp-be
parentdf348f9866e922122c7eb9c48210e18da3679913 (diff)
Fail to Export VLM
Timestamps had null value, invalid json caused exceptions Issue-ID: SDC-892 Change-Id: Iab117dd76cd51c3cd5fa62a59f55b18e265c58bf Signed-off-by: shrek2000 <orenkle@amdocs.com>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java68
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java12
-rw-r--r--openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java6
3 files changed, 52 insertions, 34 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java
index 0098f21eb2..f4710fbae5 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java
@@ -8,6 +8,8 @@ import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.openecomp.core.tools.importinfo.ImportProperties;
import org.openecomp.core.tools.model.ColumnDefinition;
@@ -22,6 +24,7 @@ import java.nio.ByteBuffer;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Base64;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -32,14 +35,14 @@ import static org.openecomp.core.tools.importinfo.ImportSingleTable.dataTypesMap
public class ExportSerializer {
- private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
+ private static final Logger logger = LoggerFactory.getLogger(ExportSerializer.class);
private static final String ELEMENT_TABLE_NAME = "element";
private static final String ELEMENT_INFO_COLUMN_NAME = "info";
public void serializeResult(final ResultSet resultSet, final Set<String> filteredItems, final String filteredColumn, Set<String> vlms) {
try {
TableData tableData = new TableData();
- tableData.definitions = resultSet.getColumnDefinitions().asList().stream().map(column -> new ColumnDefinition(column)).collect(Collectors.toList());
+ tableData.definitions = resultSet.getColumnDefinitions().asList().stream().map(ColumnDefinition::new).collect(Collectors.toList());
String table = tableData.definitions.iterator().next().getTable();
boolean isElementTable = table.equals(ELEMENT_TABLE_NAME);
Iterator<Row> iterator = resultSet.iterator();
@@ -78,9 +81,9 @@ public class ExportSerializer {
if (string == null) {
string = "";
}
- if (checkForVLM && vlms != null){
+ if (checkForVLM && vlms != null) {
String vlm = extractVlm(string);
- if (vlm!= null) {
+ if (vlm != null) {
vlms.add(vlm);
}
}
@@ -94,7 +97,12 @@ public class ExportSerializer {
data = Base64.getEncoder().encodeToString(bytes.array());
break;
case TIMESTAMP:
- data = row.getDate(i).getTime();
+ Date rowDate = row.getDate(i);
+ if (rowDate != null) {
+ data = rowDate.getTime();
+ } else {
+ data = "";
+ }
break;
case BOOLEAN:
data = row.getBool(i);
@@ -109,14 +117,14 @@ public class ExportSerializer {
data = row.getFloat(i);
break;
case SET:
- Set set = row.getSet(i, Object.class);
- Object joined = set.stream().map(o -> o.toString()).collect(Collectors.joining(ExportDataCommand.JOIN_DELIMITER));
+ Set<Object> set = row.getSet(i, Object.class);
+ Object joined = set.stream().map(Object::toString).collect(Collectors.joining(ExportDataCommand.JOIN_DELIMITER));
data = Base64.getEncoder().encodeToString(joined.toString().getBytes());
break;
case MAP:
- Map<Object,Object> map = row.getMap(i, Object.class, Object.class);
- Set<Map.Entry<Object,Object>> entrySet = map.entrySet();
- Object mapAsString = entrySet.parallelStream().map(entry -> entry.getKey().toString() + ExportDataCommand.MAP_DELIMITER +entry.getValue().toString())
+ Map<Object, Object> map = row.getMap(i, Object.class, Object.class);
+ Set<Map.Entry<Object, Object>> entrySet = map.entrySet();
+ Object mapAsString = entrySet.parallelStream().map(entry -> entry.getKey().toString() + ExportDataCommand.MAP_DELIMITER + entry.getValue().toString())
.collect(Collectors.joining(ExportDataCommand.MAP_DELIMITER));
data = Base64.getEncoder().encodeToString(mapAsString.toString().getBytes());
break;
@@ -126,22 +134,28 @@ public class ExportSerializer {
return data;
}
- protected String extractVlm(String injson) {
- if (injson == null){
- return null;
- }
- JsonElement root = new JsonParser().parse(injson);
- if (root == null){
- return null;
- }
- JsonElement properties = root.getAsJsonObject().get("properties");
- if (properties == null){
- return null;
- }
- JsonElement vendorId = properties.getAsJsonObject().get("vendorId");
- if (vendorId == null){
- return null;
- }
- return vendorId.getAsString();
+ protected String extractVlm(String inJson) {
+ if (StringUtils.isEmpty(inJson.trim())) {
+ return null;
+ }
+ JsonElement root;
+ try {
+ root = new JsonParser().parse(inJson);
+ } catch (JsonSyntaxException e) {
+ Utils.logError(logger, "Failed to parse json " + inJson, e);
+ return null;
+ }
+ if (root == null) {
+ return null;
+ }
+ JsonElement properties = root.getAsJsonObject().get("properties");
+ if (properties == null) {
+ return null;
+ }
+ JsonElement vendorId = properties.getAsJsonObject().get("vendorId");
+ if (vendorId == null) {
+ return null;
+ }
+ return vendorId.getAsString();
}
}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java
index 8a671c5f8d..922e5c7d00 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java
@@ -36,8 +36,8 @@ public class ImportSingleTable {
private static final Logger logger = LoggerFactory.getLogger(ImportSingleTable.class);
- public static final String INSERT_INTO = "INSERT INTO ";
- public static final String VALUES = " VALUES ";
+ private static final String INSERT_INTO = "INSERT INTO ";
+ private static final String VALUES = " VALUES ";
private static final Map<String, PreparedStatement> statementsCache = new HashMap<>();
public void importFile(Path file) {
@@ -96,7 +96,11 @@ public class ImportSingleTable {
bind.setBytes(i, ByteBuffer.wrap(Base64.getDecoder().decode(rowData.getBytes())));
break;
case TIMESTAMP:
- bind.setDate(i, new Date(Long.parseLong(rowData)));
+ if (StringUtils.isEmpty(rowData)){
+ bind.setSet(i, null);
+ } else {
+ bind.setDate(i, new Date(Long.parseLong(rowData)));
+ }
break;
case BOOLEAN:
bind.setBool(i, Boolean.parseBoolean(rowData));
@@ -147,7 +151,7 @@ public class ImportSingleTable {
ColumnDefinition def = tableData.definitions.iterator().next();
StringBuilder sb = new StringBuilder();
sb.append(INSERT_INTO).append(def.getKeyspace()).append(".").append(def.getTable());
- sb.append(tableData.definitions.stream().map(definition -> definition.getName()).collect(Collectors.joining(" , ", " ( ", " ) ")));
+ sb.append(tableData.definitions.stream().map(ColumnDefinition::getName).collect(Collectors.joining(" , ", " ( ", " ) ")));
sb.append(VALUES).append(tableData.definitions.stream().map(definition -> "?").collect(Collectors.joining(" , ", " ( ", " ) "))).append(";");
return sb.toString();
}
diff --git a/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java b/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java
index a5a1ff2cbc..ed1ad2b2f4 100644
--- a/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java
+++ b/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java
@@ -36,12 +36,12 @@ public class VLMExtractTest {
@Test(expectedExceptions = IllegalStateException.class)
public void failToExtractVLMBecauseJsonIsCorrupted(){
String elemenet_info_string = "gfhhhghgh";
- new CustomExportSerializer().extractVlm(elemenet_info_string);
+ assertNull(new CustomExportSerializer().extractVlm(elemenet_info_string));
}
private static final class CustomExportSerializer extends ExportSerializer{
- public String extractVlm(String injson) {
- return super.extractVlm(injson);
+ public String extractVlm(String inJson) {
+ return super.extractVlm(inJson);
}
}
}