]> matita.cs.unibo.it Git - logicplayer.git/blobdiff - server/com/company/DirectoryWhatcer.java
Bug fixed: made robust against lost of connection with db.
[logicplayer.git] / server / com / company / DirectoryWhatcer.java
index 8b376a1a3557e5cdec54122e390834a1ac8cb760..630c9083f2dc77dbd9d54d43fa669951c90083d3 100644 (file)
@@ -39,9 +39,8 @@ class DirectoryWatcher implements Runnable {
                 xmlOperation es=new xmlOperation();
                 File car=new File(global.listaEsercizi);
                 if (car.exists()) {
-                    dbConnect db=new dbConnect();
                     try {
-                        ArrayList<String> esercizi=suString.stringToArrayList(db.dbQuery("4"));
+                        ArrayList<String> esercizi=suString.stringToArrayList(global.request.dbQuery("4"));
                         boolean add=true;
                         for(String esercizio : esercizi)
                         {
@@ -66,6 +65,35 @@ class DirectoryWatcher implements Runnable {
                 }
             }
         }
+        try {
+            String[] esercizi=suString.stringToVectorString(global.request.dbQuery("4"));
+            boolean delete=true;
+            for(String esercizio : esercizi)
+            {
+                for(String elemento : lista)
+                {
+                    if(esercizio.contentEquals(elemento))
+                        delete=false;
+                }
+                if(delete) {
+                    xmlOperation es = new xmlOperation();
+                    es.remove(esercizio);
+                }
+
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        } catch (ClassNotFoundException e) {
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+        } catch (InstantiationException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
     }
 
     // print the events and the affected file
@@ -78,7 +106,7 @@ class DirectoryWatcher implements Runnable {
             boolean check = EsNameParser.check(pathCreated.getFileName().toString());
             if(!check)
             {
-                File file = new File(global.locationEsercizi+pathCreated.getFileName().toString());
+                File file = new File("/var/www/html/esercizi/"+pathCreated.getFileName().toString());
                 if(file.delete())
                     System.out.println("eliminato");
                 else