aboutsummaryrefslogtreecommitdiffstats
path: root/aai-core/src
diff options
context:
space:
mode:
authorDileep Ranganathan <dileep.ranganathan@intel.com>2017-08-30 19:36:12 -0700
committerDileep Ranganathan <dileep.ranganathan@intel.com>2017-08-30 20:22:02 -0700
commitab726b4ca4019f308168a21895e9199fa5f9718c (patch)
tree0ec46bec1a652a7d34c7dcb51ae7d54da501e9ef /aai-core/src
parent2220bc4b234ba7c4a19ef77be861052ee824e394 (diff)
Fix Blocker and Critical Sonar issues/bugs.
Includes ad-hoc fixes for sonar issues within the files modified. Change-Id: Ide181bbe3e05cbc969706a3d798cd99c5609a0b2 Issue-id: AAI-246 Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
Diffstat (limited to 'aai-core/src')
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/db/schema/ScriptDriver.java40
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/dbgen/DataGrooming.java18
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/dbmap/AAIGraph.java66
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java5
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/parsers/uri/URIParser.java3
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java2
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/serialization/db/DBSerializer.java2
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/util/GenerateXsd.java2
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/util/swagger/GenerateSwagger.java4
9 files changed, 76 insertions, 66 deletions
diff --git a/aai-core/src/main/java/org/openecomp/aai/db/schema/ScriptDriver.java b/aai-core/src/main/java/org/openecomp/aai/db/schema/ScriptDriver.java
index 458c4c90..9a90ea28 100644
--- a/aai-core/src/main/java/org/openecomp/aai/db/schema/ScriptDriver.java
+++ b/aai-core/src/main/java/org/openecomp/aai/db/schema/ScriptDriver.java
@@ -36,7 +36,7 @@ import com.thinkaurelius.titan.core.TitanGraph;
public class ScriptDriver {
-
+
/**
* The main method.
*
@@ -46,7 +46,7 @@ public class ScriptDriver {
* @throws JsonMappingException the json mapping exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- public static void main (String[] args) throws AAIException, JsonGenerationException, JsonMappingException, IOException {
+ public static void main (String[] args) throws AAIException, IOException {
CommandLineArgs cArgs = new CommandLineArgs();
new JCommander(cArgs, args);
@@ -56,26 +56,24 @@ public class ScriptDriver {
}
String config = cArgs.config;
AAIConfig.init();
- TitanGraph graph = TitanFactory.open(config);
- if (!(cArgs.type.equals("oxm") || cArgs.type.equals("graph"))) {
- System.out.println("type: " + cArgs.type + " not recognized.");
- System.exit(1);
- }
-
- Auditor a = null;
- if (cArgs.type.equals("oxm")) {
- a = AuditorFactory.getOXMAuditor(Version.v8);
- } else if (cArgs.type.equals("graph")) {
- a = AuditorFactory.getGraphAuditor(graph);
+ try (TitanGraph graph = TitanFactory.open(config)) {
+ if (!("oxm".equals(cArgs.type) || "graph".equals(cArgs.type))) {
+ System.out.println("type: " + cArgs.type + " not recognized.");
+ System.exit(1);
+ }
+
+ AuditDoc doc = null;
+ if ("oxm".equals(cArgs.type)) {
+ doc = AuditorFactory.getOXMAuditor(Version.v8).getAuditDoc();
+ } else if ("graph".equals(cArgs.type)) {
+ doc = AuditorFactory.getGraphAuditor(graph).getAuditDoc();
+ }
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(doc);
+ System.out.println(json);
}
-
- AuditDoc doc = a.getAuditDoc();
-
- ObjectMapper mapper = new ObjectMapper();
-
- String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(doc);
- System.out.println(json);
-
}
}
diff --git a/aai-core/src/main/java/org/openecomp/aai/dbgen/DataGrooming.java b/aai-core/src/main/java/org/openecomp/aai/dbgen/DataGrooming.java
index f0aaf607..8dca75c5 100644
--- a/aai-core/src/main/java/org/openecomp/aai/dbgen/DataGrooming.java
+++ b/aai-core/src/main/java/org/openecomp/aai/dbgen/DataGrooming.java
@@ -395,8 +395,7 @@ public class DataGrooming {
}
LOGGER.info(" Will write to " + fullOutputFileName );
- FileWriter fw = new FileWriter(groomOutFile.getAbsoluteFile());
- bw = new BufferedWriter(fw);
+ bw = new BufferedWriter(new FileWriter(groomOutFile.getAbsoluteFile()));
ErrorLogHelper.loadProperties();
LOGGER.info(" ---- NOTE --- about to open graph (takes a little while)--------\n");
@@ -1273,7 +1272,7 @@ public class DataGrooming {
LOGGER.warn("Got an IOException trying to close bufferedWriter() \n", iox);
}
}
-
+
if (g != null && g.tx().isOpen()) {
// Any changes that worked correctly should have already done
// their commits.
@@ -1424,13 +1423,11 @@ public class DataGrooming {
// Vertex Id's to delete on this run
Set<String> delList = new LinkedHashSet<>();
String fullFileName = targetDir + AAIConstants.AAI_FILESEP + fileName;
- BufferedReader br = null;
-
- try {
- br = new BufferedReader(new FileReader(fullFileName));
+
+ try(BufferedReader br = new BufferedReader(new FileReader(fullFileName))) {
String line = br.readLine();
while (line != null) {
- if (!line.equals("") && line.startsWith("DeleteCandidate")) {
+ if (!"".equals(line) && line.startsWith("DeleteCandidate")) {
if (edgesOnlyFlag && (!line.contains("Bad Edge"))) {
// We're not going to process edge guys
} else if (dontFixOrphans && line.contains("Orphan")) {
@@ -1554,7 +1551,8 @@ public class DataGrooming {
try {
keyProps = loader.introspectorFromName(vtxANodeType).getKeys();
} catch (AAIUnknownObjectException e) {
- throw new AAIException("AAI_6105", "Required Property name(s) not found for nodeType = " + vtxANodeType + ")");
+ LOGGER.warn("Required property not found", e);
+ throw new AAIException("AAI_6105", "Required Property name(s) not found for nodeType = " + vtxANodeType + ")");
}
Iterator<String> keyPropI = keyProps.iterator();
@@ -2310,7 +2308,7 @@ public class DataGrooming {
return 0;
}
long unixTimeNow = System.currentTimeMillis();
- long windowInMillis = timeWindowMinutes * 60 * 1000;
+ long windowInMillis = timeWindowMinutes * 60L * 1000;
long startTimeStamp = unixTimeNow - windowInMillis;
diff --git a/aai-core/src/main/java/org/openecomp/aai/dbmap/AAIGraph.java b/aai-core/src/main/java/org/openecomp/aai/dbmap/AAIGraph.java
index b3cc8994..2ee8baf5 100644
--- a/aai-core/src/main/java/org/openecomp/aai/dbmap/AAIGraph.java
+++ b/aai-core/src/main/java/org/openecomp/aai/dbmap/AAIGraph.java
@@ -54,11 +54,12 @@ import com.thinkaurelius.titan.core.schema.TitanManagement;
*/
public class AAIGraph {
- protected Map<String, TitanGraph> graphs = new HashMap<>();
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIGraph.class);
protected static final String COMPONENT = "aaidbmap";
+ protected Map<String, TitanGraph> graphs = new HashMap<>();
private final String REALTIME_DB = "realtime";
private final String CACHED_DB = "cached";
- private final EELFLogger logger = EELFManager.getInstance().getLogger(this.getClass().getSimpleName());
+
/**
@@ -95,38 +96,22 @@ public class AAIGraph {
}
private void loadGraph(String name, String configPath) throws AAIException {
- try {
- final TitanGraph graph = TitanFactory.open(configPath);
- InputStream is = new FileInputStream(configPath);
- Properties graphProps = new Properties();
- graphProps.load(is);
-
- if (graphProps.get("storage.backend").equals("inmemory")) {
+ try (TitanGraph graph = TitanFactory.open(configPath);
+ InputStream is = new FileInputStream(configPath)) {
+
+ Properties graphProps = new Properties();
+ graphProps.load(is);
+
+ if ("inmemory".equals(graphProps.get("storage.backend"))) {
// Load the propertyKeys, indexes and edge-Labels into the DB
loadSchema(graph);
- if (graphProps.containsKey("load.snapshot.file")) {
- String value = graphProps.getProperty("load.snapshot.file");
- if ("true".equals(value)) {
- try {
- String location = System.getProperty("snapshot.location");
- logAndPrint(logger, "Loading snapshot to inmemory graph.");
- Graph transaction = graph.newTransaction();
- transaction.io(IoCore.graphson()).readGraph(location);
- transaction.tx().commit();
- logAndPrint(logger, "Snapshot loaded to inmemory graph.");
- } catch (IOException e) {
- graph.close();
- logAndPrint(logger, "ERROR: Could not load datasnapshot to in memory graph. \n" + ExceptionUtils.getFullStackTrace(e));
- System.exit(0);
- }
- }
- }
+ loadSnapShotToInMemoryGraph(graph, graphProps);
}
-
+
if (graph == null) {
throw new AAIException("AAI_5102");
}
-
+
graphs.put(name, graph);
} catch (FileNotFoundException fnfe) {
throw new AAIException("AAI_4001");
@@ -135,7 +120,30 @@ public class AAIGraph {
}
}
-
+
+ private void loadSnapShotToInMemoryGraph(TitanGraph graph, Properties graphProps) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Load Snapshot to InMemory Graph");
+ }
+ if (graphProps.containsKey("load.snapshot.file")) {
+ String value = graphProps.getProperty("load.snapshot.file");
+ if ("true".equals(value)) {
+ try (Graph transaction = graph.newTransaction()) {
+ String location = System.getProperty("snapshot.location");
+ logAndPrint(logger, "Loading snapshot to inmemory graph.");
+ transaction.io(IoCore.graphson()).readGraph(location);
+ transaction.tx().commit();
+ logAndPrint(logger, "Snapshot loaded to inmemory graph.");
+ } catch (Exception e) {
+ logAndPrint(logger,
+ "ERROR: Could not load datasnapshot to in memory graph. \n"
+ + ExceptionUtils.getFullStackTrace(e));
+ System.exit(0);
+ }
+ }
+ }
+ }
+
private void loadSchema(TitanGraph graph) {
// Load the propertyKeys, indexes and edge-Labels into the DB
TitanManagement graphMgt = graph.openManagement();
diff --git a/aai-core/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java b/aai-core/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java
index a30ebc0d..8acb954e 100644
--- a/aai-core/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java
+++ b/aai-core/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java
@@ -52,13 +52,11 @@ public class AAIDmaapEventJMSConsumer implements MessageListener {
public AAIDmaapEventJMSConsumer() throws org.apache.commons.configuration.ConfigurationException {
super();
- try {
+ try(FileReader reader = new FileReader(new File(AAIConstants.AAI_EVENT_DMAAP_PROPS))) {
if (this.httpClient == null) {
- FileReader reader = new FileReader(new File(AAIConstants.AAI_EVENT_DMAAP_PROPS));
aaiEventProps = new Properties();
aaiEventProps.load(reader);
- reader.close();
String host = aaiEventProps.getProperty("host");
String topic = aaiEventProps.getProperty("topic");
@@ -70,6 +68,7 @@ public class AAIDmaapEventJMSConsumer implements MessageListener {
} catch (IOException e) {
ErrorLogHelper.logError("AAI_4000", "Error updating dmaap config file for aai event.");
+ LOGGER.error(e.getMessage(), e);
}
}
diff --git a/aai-core/src/main/java/org/openecomp/aai/parsers/uri/URIParser.java b/aai-core/src/main/java/org/openecomp/aai/parsers/uri/URIParser.java
index b4d5ee80..27a5145a 100644
--- a/aai-core/src/main/java/org/openecomp/aai/parsers/uri/URIParser.java
+++ b/aai-core/src/main/java/org/openecomp/aai/parsers/uri/URIParser.java
@@ -141,6 +141,9 @@ public class URIParser {
throw new AAIException("AAI_3000", uri + " not a valid path. Cannot end in " + RestTokens.COUSIN);
}
introspector = loader.introspectorFromName(parts[i+1]);
+ if(null == previousObj) {
+ throw new AAIException("AAI_3001");
+ }
if (previousObj.isContainer() && introspector.isContainer()) {
throw new AAIException("AAI_3000", uri + " not a valid path. Cannot chain plurals together");
}
diff --git a/aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java b/aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java
index 73b57d06..d0a7098f 100644
--- a/aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java
+++ b/aai-core/src/main/java/org/openecomp/aai/query/builder/GraphTraversalBuilder.java
@@ -221,7 +221,7 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> {
prop = metadata.get();
}
//this is because the index is registered as an Integer
- if (val != null && val.getClass().equals(Long.class)) {
+ if (val.getClass().equals(Long.class)) {
traversal.has(prop,new Integer(val.toString()));
} else {
traversal.has(prop, val);
diff --git a/aai-core/src/main/java/org/openecomp/aai/serialization/db/DBSerializer.java b/aai-core/src/main/java/org/openecomp/aai/serialization/db/DBSerializer.java
index c04c460a..bf70b690 100644
--- a/aai-core/src/main/java/org/openecomp/aai/serialization/db/DBSerializer.java
+++ b/aai-core/src/main/java/org/openecomp/aai/serialization/db/DBSerializer.java
@@ -744,7 +744,7 @@ public class DBSerializer {
Introspector argumentObject = obj.newIntrospectorInstanceOfNestedProperty(property);
Object result = dbToObject(argumentObject, childVertex, seen, depth, nodeOnly, cleanUp);
- if (result != null) {
+ if (result != null && getList != null) {
getList.add(argumentObject.getUnderlyingObject());
}
diff --git a/aai-core/src/main/java/org/openecomp/aai/util/GenerateXsd.java b/aai-core/src/main/java/org/openecomp/aai/util/GenerateXsd.java
index 76c954e7..99a06f49 100644
--- a/aai-core/src/main/java/org/openecomp/aai/util/GenerateXsd.java
+++ b/aai-core/src/main/java/org/openecomp/aai/util/GenerateXsd.java
@@ -1763,7 +1763,7 @@ public class GenerateXsd {
Object nodeset = expr.evaluate(element, XPathConstants.NODESET);
if (nodeset != null) {
NodeList nodes = (NodeList) nodeset;
- if (nodes != null && nodes.getLength() > 0) {
+ if (nodes.getLength() > 0) {
Element xmlProperty = (Element)nodes.item(0);
result = xmlProperty.getElementsByTagName("xml-property");
}
diff --git a/aai-core/src/main/java/org/openecomp/aai/util/swagger/GenerateSwagger.java b/aai-core/src/main/java/org/openecomp/aai/util/swagger/GenerateSwagger.java
index 07f201e7..5731485e 100644
--- a/aai-core/src/main/java/org/openecomp/aai/util/swagger/GenerateSwagger.java
+++ b/aai-core/src/main/java/org/openecomp/aai/util/swagger/GenerateSwagger.java
@@ -76,6 +76,10 @@ public class GenerateSwagger {
ex.printStackTrace();
}
+ if(null == swaggerMap) {
+ throw new IOException();
+ }
+
Map<String, Object> map = (Map<String, Object>) swaggerMap.get("paths");
Map<String, Object> schemaDefinitionmap = (Map<String, Object>) swaggerMap.get("definitions");
Map<String, Object> infoMap = (Map<String, Object>) swaggerMap.get("info");