Fix use try-with-resources issues in asdctool

Fix sonar issues in ArtifactValidatorExecuter.java,ExportImportTitanServlet.java

Issue-ID: SDC-1672
Change-Id: I39a6376ea61de135bfb824e121adff37b631fdf2
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
index 089e972..34696b3 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
@@ -44,7 +44,7 @@
 		   Map<String, List<Component>> result = new HashMap<>();
 	        Either<List<GraphVertex>, TitanOperationStatus> resultsEither = titanDao.getByCriteria(type, hasProps);
 	        if (resultsEither.isRight()) {
-	            System.out.println("getVerticesToValidate failed "+ resultsEither.right().value());
+	        	log.error("getVerticesToValidate failed "+ resultsEither.right().value());
 	            return result;
 	        }
 	        System.out.println("getVerticesToValidate: "+resultsEither.left().value().size()+" vertices to scan");
@@ -62,7 +62,7 @@
 				
 				Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(vertex.getUniqueId(), filter);
 				if (toscaElement.isRight()) {
-					System.out.println("getVerticesToValidate: failed to find element"+ vertex.getUniqueId()+" staus is" + toscaElement.right().value());
+					log.error("getVerticesToValidate: failed to find element"+ vertex.getUniqueId()+" staus is" + toscaElement.right().value());
 				}else{
 					compList.add(toscaElement.left().value());
 				}
@@ -76,9 +76,7 @@
 		   boolean result = true;
 		   long time = System.currentTimeMillis();
 		   String fileName = ValidationConfigManager.getOutputFilePath() + this.getName() + "_"+ time + ".csv";
-		   Writer writer = null;
-		   try {
-			writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
+		   try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
 			writer.write("name, UUID, invariantUUID, state, version\n");
 			Collection<List<Component>> collection = vertices.values();
 			for(List<Component> compList: collection ){
@@ -100,15 +98,10 @@
 			}
 			
 		   } catch (Exception e) {
-				log.info("Failed to fetch vf resources ", e);
+				log.error("Failed to fetch vf resources ", e);
 				return false;
 			} finally {
 				titanDao.commit();
-				try {
-					writer.flush();
-					writer.close();
-				} catch (Exception ex) {
-					/* ignore */}
 			}
 			return result;
 	    }
@@ -124,8 +117,7 @@
 					writer.write(sb.toString());
 				}
 			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
+				log.error("Failed to write module result to file ", e);
 			}
 		}
 
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
index c1f9335..31b1b1f 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
@@ -70,39 +70,30 @@
 
 		conf.setProperty("storage.machine-id-appendix", System.currentTimeMillis() % 1000);
 
-		TitanGraph openGraph = Utils.openGraph(conf);
-		if (openGraph == null) {
-			Response buildErrorResponse = Utils.buildOkResponse(500, "failed to open graph", null);
-			return buildErrorResponse;
+		try(TitanGraph openGraph = Utils.openGraph(conf)){
+			
+			if (openGraph == null) {
+				Response buildErrorResponse = Utils.buildOkResponse(500, "failed to open graph", null);
+				return buildErrorResponse;
+			}
+	
+			// Open Titan Graph
+	
+			Response buildOkResponse = Utils.buildOkResponse(200, "ok man", null);
+	
+			return buildOkResponse;
 		}
-
-		// Open Titan Graph
-
-		Response buildOkResponse = Utils.buildOkResponse(200, "ok man", null);
-
-		return buildOkResponse;
 	}
 
 	private Properties convertFileToProperties(File titanPropertiesFile) {
 
 		Properties properties = new Properties();
 
-		FileReader fileReader = null;
-		try {
-			fileReader = new FileReader(titanPropertiesFile);
+		try (FileReader fileReader = new FileReader(titanPropertiesFile)){
 			properties.load(fileReader);
-
 		} catch (Exception e) {
 			log.error("Failed to convert file to properties", e);
 			return null;
-		} finally {
-			if (fileReader != null) {
-				try {
-					fileReader.close();
-				} catch (IOException e) {
-					log.error("Failed to close file", e);
-				}
-			}
 		}
 
 		return properties;