diff src/main/java/de/mpiwg/gazetteer/utils/FileManager.java @ 54:a00efd5d9e77

new: adding delete saved table function
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 04 Feb 2016 11:30:46 +0100
parents cf747a960516
children b8ad346e39a0
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java	Mon Feb 01 15:49:48 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java	Thu Feb 04 11:30:46 2016 +0100
@@ -4,6 +4,7 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -246,6 +247,40 @@
 		return new String(encoded, "UTF8");
 		
 	}
+
+
+	
+	protected static void deleteFileFromFileSystemByAbsolutePath(String absolutePath) {
+		try{	
+    		File file = new File(absolutePath);
+        	
+    		if(file.delete()){
+    			System.out.println(file.getName() + " is deleted!");
+    		}else{
+    			System.out.println("Delete operation is failed.");
+    		}
+    	   
+    	}catch(Exception e){
+    		
+    		e.printStackTrace();
+    		
+    	}
+	}
+	
+	public static void deleteFullTextSearchFileCsv(LGFullTextSearchFile file) throws IOException {
+		// csv file is in LGMap/datasets/
+		String absolutePath = PropertiesUtils.getPropValue("lgmap_datasets") + "/" + file.getUserId() + "_" + file.getFileName() + ".csv";
+		
+		deleteFileFromFileSystemByAbsolutePath(absolutePath);
+	}
+
+
+	public static void deleteFullTextSearchFileHtml(LGFullTextSearchFile file) throws IOException {
+		// html file is in ftsearch-data/... 
+		String absolutePath = PropertiesUtils.getPropValue("ftsearch_root") + "/html/"  + file.getUserId().toString() + "/" + file.getFileName() + ".html";
+
+		deleteFileFromFileSystemByAbsolutePath(absolutePath);
+	}
 	
 	
 }