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>
public class ScriptDriver {
-
+
/**
* The main method.
*
* @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);
}
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);
-
}
}
}
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");
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.
// 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")) {
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();
return 0;
}
long unixTimeNow = System.currentTimeMillis();
- long windowInMillis = timeWindowMinutes * 60 * 1000;
+ long windowInMillis = timeWindowMinutes * 60L * 1000;
long startTimeStamp = unixTimeNow - windowInMillis;
*/
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());
+
/**
}
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");
}
}
-
+
+ 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();
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");
} catch (IOException e) {
ErrorLogHelper.logError("AAI_4000", "Error updating dmaap config file for aai event.");
+ LOGGER.error(e.getMessage(), e);
}
}
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");
}
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);
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());
}
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");
}
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");