OSDN Git Service

feat: Auto update process added
authorhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Wed, 21 Jul 2021 01:52:12 +0000 (10:52 +0900)
committerhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Wed, 21 Jul 2021 01:52:12 +0000 (10:52 +0900)
database.json
src/com/ranfa/lib/Scraping.java
src/com/ranfa/main/DelesteRandomSelector.java

index d08926b..8aa0ff5 100644 (file)
     "difficulty" : "WITCH",
     "level" : 25,
     "notes" : 481
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "Life is HaRMONY",
+    "difficulty" : "MASTER+",
+    "level" : 28,
+    "notes" : 886
+  }, {
+    "attribute" : "クール",
+    "name" : "あこがれステッチ",
+    "difficulty" : "MASTER+",
+    "level" : 27,
+    "notes" : 757
+  }, {
+    "attribute" : "パッション",
+    "name" : "パ・リ・ラ",
+    "difficulty" : "DEBUT",
+    "level" : 7,
+    "notes" : 117
+  }, {
+    "attribute" : "パッション",
+    "name" : "パ・リ・ラ",
+    "difficulty" : "REGULAR",
+    "level" : 13,
+    "notes" : 199
+  }, {
+    "attribute" : "パッション",
+    "name" : "パ・リ・ラ",
+    "difficulty" : "PRO",
+    "level" : 19,
+    "notes" : 449
+  }, {
+    "attribute" : "パッション",
+    "name" : "パ・リ・ラ",
+    "difficulty" : "MASTER",
+    "level" : 26,
+    "notes" : 668
+  }, {
+    "attribute" : "パッション",
+    "name" : "パ・リ・ラ",
+    "difficulty" : "MASTER+",
+    "level" : 29,
+    "notes" : 999
   } ]
 }
\ No newline at end of file
index f7450ab..a5f5b5c 100644 (file)
@@ -42,6 +42,10 @@ public class Scraping {
                return Files.exists(path);
        }
 
+       public static String getDBPath() {
+               return DBPATH;
+       }
+
        public static ArrayList<Song> getWholeData() {
                // if(databaseExists())
                //      return null;
@@ -157,8 +161,14 @@ public class Scraping {
 
        }
 
-       public static ArrayList<Song> getFromJson() throws IOException {
-               SongJSONProperty property = new ObjectMapper().readValue(new File(DBPATH), SongJSONProperty.class);
+       public static ArrayList<Song> getFromJson() {
+               SongJSONProperty property = null;
+               try {
+                       property = new ObjectMapper().readValue(new File(DBPATH), SongJSONProperty.class);
+               } catch (IOException e) {
+                       // TODO 自動生成された catch ブロック
+                       e.printStackTrace();
+               }
                ArrayList<Song> res = new ArrayList<Song>();
                res.addAll(property.getList());
                return res;
index 1553060..6eb26ea 100644 (file)
@@ -6,10 +6,12 @@ import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Random;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -61,10 +63,6 @@ public class DelesteRandomSelector extends JFrame {
        private JLabel labelLvCaution;
        private JComboBox comboAttribute;
 
-       private ArrayList<Song> wholeDataList;
-
-       private ArrayList<Song> fromJsonList;
-
        private SettingJSONProperty property = new SettingJSONProperty();
 
        /**
@@ -118,83 +116,24 @@ public class DelesteRandomSelector extends JFrame {
                                JOptionPane.showMessageDialog(this, "Exception:NullPointerException\\nCannot Keep up! Please re-download this Application!");
                                throw new NullPointerException("FATAL: cannot continue!");
                        }
-               }
-               ExecutorService es = Executors.newWorkStealingPool();
-               CompletableFuture<ArrayList<Song>> getFromJsonFuture = CompletableFuture.supplyAsync(() -> {
+               } else if(Scraping.getFromJson().size() < Scraping.getWholeData().size()) {
+                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Update detected.Initiate update process...");
+                       Path path = Paths.get(Scraping.getDBPath());
                        try {
-                               return Scraping.getFromJson();
+                               Files.delete(path);
                        } catch (IOException e1) {
-                               // TODO 自動生成された catch ブロック
-                               e1.printStackTrace();
+                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + "Exception while updating library.\n" + e1.getLocalizedMessage());
+                               JOptionPane.showMessageDialog(null, "データベースファイルをアップデートできませんでした。ファイルの削除権限があるかどうか確認してください。\n" + e1.getLocalizedMessage());
                        }
-                       return null;
-               }, es);
+                       Scraping.writeToJson(Scraping.getWholeData());
+                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Library update completed.");
+               }
+               ExecutorService es = Executors.newWorkStealingPool();
+               CompletableFuture<ArrayList<Song>> getFromJsonFuture = CompletableFuture.supplyAsync(() -> Scraping.getFromJson(), es);
                CompletableFuture<ArrayList<Song>> getWholeDataFuture = CompletableFuture.supplyAsync(() -> Scraping.getWholeData(), es);
                getWholeDataFuture.thenAcceptAsync(list -> LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: Scraping data size:" + list.size()), es);
                getFromJsonFuture.thenAcceptAsync(list -> LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO] Currently database size:" + list.size()), es);
-               getWholeDataFuture.thenAcceptAsync(list -> {
-                       wholeDataList.addAll(list);
-               }, es);
-               getFromJsonFuture.thenAcceptAsync(list -> {
-                       fromJsonList.addAll(list);
-                       try {
-                               if(getWholeDataFuture.get().size() != list.size()) {
-                                       fromJsonList.clear();
-                                       fromJsonList.addAll(wholeDataList);
-                               }
-                       } catch (InterruptedException e1) {
-                               JOptionPane.showMessageDialog(null, "例外:InterruptedException\n非同期処理待機中に割り込みが発生しました。\n" + e1.getLocalizedMessage());
-                               e1.printStackTrace();
-                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e1.getLocalizedMessage());
-                       } catch (ExecutionException e1) {
-                               JOptionPane.showMessageDialog(null, "例外:ExecutionException\n非同期処理中に例外をキャッチしました。\n" + e1.getLocalizedMessage());
-                               e1.printStackTrace();
-                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e1.getLocalizedMessage());
-                       }
-               }, es);
                LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[DEBUG]: " + "Version:" + getVersion());
-               if(property.isCheckLibraryUpdates()) {
-                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Checking for library updates...");
-                       ArrayList<Song> updatesWebTmp = new ArrayList<Song>();
-                       ArrayList<Song> updatesLocalTmp = new ArrayList<Song>();
-                       if(getWholeDataFuture.isDone()) {
-                               updatesWebTmp = wholeDataList;
-                       } else {
-                               try {
-                                       updatesWebTmp = getWholeDataFuture.get();
-                               } catch (InterruptedException e) {
-                                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e.getLocalizedMessage());
-                                       JOptionPane.showMessageDialog(null, "[InterruptedException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage());
-                               } catch (ExecutionException e) {
-                                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e.getLocalizedMessage());
-                                       JOptionPane.showMessageDialog(null, "[ExecutionException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage());
-                               }
-                       }
-                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Web data scan completed.\nSize:" + updatesWebTmp.size());
-                       if(getFromJsonFuture.isDone()) {
-                               updatesLocalTmp = fromJsonList;
-                       } else {
-                               try {
-                                       updatesLocalTmp = getFromJsonFuture.get();
-                               } catch (InterruptedException e) {
-                                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e.getLocalizedMessage());
-                                       JOptionPane.showMessageDialog(null, "[InterruptedException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage());
-                               } catch (ExecutionException e) {
-                                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e.getLocalizedMessage());
-                                       JOptionPane.showMessageDialog(null, "[ExecutionException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage());
-                               }
-                       }
-                       LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Current json data scan completed.\nSize:" + updatesLocalTmp.size());
-                       if(updatesWebTmp.size() > updatesLocalTmp.size()) {
-                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Song update detected.\nInitiate update progress...");
-                               Scraping.writeToJson(updatesWebTmp);
-                               fromJsonList.clear();
-                               fromJsonList.addAll(updatesWebTmp);
-                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Update progress compeleted.Initiate GUI.");
-                       } else {
-                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "No updates found.Initiate GUI.");
-                       }
-               }
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setBounds(100, 100, 640, 360);
                contentPane = new JPanel();
@@ -294,18 +233,7 @@ public class DelesteRandomSelector extends JFrame {
                btnImport = new JButton("<html><body>楽曲<br>絞り込み</body></html>");
                btnImport.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
-                               ArrayList<Song> fromJson = new ArrayList<Song>();
-                                       try {
-                                               fromJson.addAll(getFromJsonFuture.get());
-                                       } catch (InterruptedException e1) {
-                                               JOptionPane.showMessageDialog(null, "例外:InterruptedException\n非同期処理待機中に割り込みが発生しました。\n" + e1.getLocalizedMessage());
-                                               e1.printStackTrace();
-                                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e1.getLocalizedMessage());
-                                       } catch (ExecutionException e1) {
-                                               JOptionPane.showMessageDialog(null, "例外:ExecutionException\n非同期処理中に例外をキャッチしました。\n" + e1.getLocalizedMessage());
-                                               e1.printStackTrace();
-                                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e1.getLocalizedMessage());
-                                       }
+                               ArrayList<Song> fromJson = Scraping.getFromJson();
                                        ArrayList<Song> specificlevelList = Scraping.getSpecificLevelSongs(fromJson, (Integer)spinnerLevel.getValue(), checkLessLv.isSelected(), checkMoreLv.isSelected());
                                        ArrayList<Song> specificDifficultyList = Scraping.getSpecificDifficultySongs(specificlevelList, comboDifficultySelect.getSelectedItem().toString());
                                        ArrayList<Song> specificAttributeList = Scraping.getSpecificAttributeSongs(specificDifficultyList, comboAttribute.getSelectedItem().toString());