OSDN Git Service

Added logic to download all linked & shared data structures.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / threads / SyncRunner.java
index 89f9271..2581725 100644 (file)
@@ -39,10 +39,12 @@ import com.evernote.edam.notestore.NoteStore;
 import com.evernote.edam.notestore.SyncChunk;\r
 import com.evernote.edam.notestore.SyncState;\r
 import com.evernote.edam.type.Data;\r
+import com.evernote.edam.type.LinkedNotebook;\r
 import com.evernote.edam.type.Note;\r
 import com.evernote.edam.type.Notebook;\r
 import com.evernote.edam.type.Resource;\r
 import com.evernote.edam.type.SavedSearch;\r
+import com.evernote.edam.type.SharedNotebook;\r
 import com.evernote.edam.type.Tag;\r
 import com.evernote.edam.type.User;\r
 import com.evernote.edam.userstore.AuthenticationResult;\r
@@ -307,7 +309,16 @@ public class SyncRunner extends QObject implements Runnable {
                                updateSequenceNumber = 0;\r
                                conn.getSyncTable().setUpdateSequenceNumber(0);\r
                        }\r
-\r
+                       // Check for "special" sync instructions\r
+                       String syncLinked = conn.getSyncTable().getRecord("FullLinkedNotebookSync");\r
+                       String syncShared = conn.getSyncTable().getRecord("FullLinkedNotebookSync");\r
+                       if (syncLinked != null) {\r
+                               downloadAllLinkedNotebooks();\r
+                       }\r
+                       if (syncShared != null) {\r
+                               downloadAllSharedNotebooks();\r
+                       }\r
+                       \r
                        // If there are remote changes\r
                        logger.log(logger.LOW, "Update Count: " +syncState.getUpdateCount());\r
                        logger.log(logger.LOW, "Last Update Count: " +updateSequenceNumber);\r
@@ -1422,4 +1433,68 @@ public class SyncRunner extends QObject implements Runnable {
        n.setContent(conn.getNoteTable().getNoteContentBinary(n.getGuid()));\r
        return n;\r
     }\r
+\r
+\r
+\r
+    //*********************************************************\r
+    //* Special download instructions.  Used for DB upgrades\r
+    //*********************************************************\r
+    private void downloadAllSharedNotebooks() {\r
+       try {\r
+                       List<SharedNotebook> books = noteStore.listSharedNotebooks(authToken);\r
+                       logger.log(logger.LOW, "Shared notebooks found = " +books.size());\r
+                       for (int i=0; i<books.size(); i++) {\r
+                               conn.getSharedNotebookTable().updateNotebook(books.get(i), false);\r
+                       }\r
+                       conn.getSyncTable().deleteRecord("FullSharedNotebookSync");\r
+               } catch (EDAMUserException e1) {\r
+                       e1.printStackTrace();\r
+                       status.message.emit(tr("User exception Listing shared notebooks."));\r
+                       logger.log(logger.LOW, e1.getMessage());\r
+                       return;\r
+               } catch (EDAMSystemException e1) {\r
+                       e1.printStackTrace();\r
+                       status.message.emit(tr("System exception Listing shared notebooks."));\r
+                       logger.log(logger.LOW, e1.getMessage());\r
+                       return;\r
+               } catch (TException e1) {\r
+                       e1.printStackTrace();\r
+                       status.message.emit(tr("Transaction exception Listing shared notebooks."));\r
+                       logger.log(logger.LOW, e1.getMessage());\r
+                       return;\r
+               } catch (EDAMNotFoundException e1) {\r
+                       e1.printStackTrace();\r
+                       status.message.emit(tr("EDAM Not Found exception Listing shared notebooks."));\r
+                       logger.log(logger.LOW, e1.getMessage());\r
+               }\r
+    }\r
+    private void downloadAllLinkedNotebooks() {\r
+       try {\r
+                       List<LinkedNotebook> books = noteStore.listLinkedNotebooks(authToken);\r
+                       logger.log(logger.LOW, "Linked notebooks found = " +books.size());\r
+                       for (int i=0; i<books.size(); i++) {\r
+                               conn.getLinkedNotebookTable().updateNotebook(books.get(i), false);\r
+                       }\r
+                       conn.getSyncTable().deleteRecord("FullLinkedNotebookSync");\r
+               } catch (EDAMUserException e1) {\r
+                       e1.printStackTrace();\r
+                       status.message.emit(tr("User exception Listing linked notebooks."));\r
+                       logger.log(logger.LOW, e1.getMessage());\r
+                       return;\r
+               } catch (EDAMSystemException e1) {\r
+                       e1.printStackTrace();\r
+                       status.message.emit(tr("System exception Listing linked notebooks."));\r
+                       logger.log(logger.LOW, e1.getMessage());\r
+                       return;\r
+               } catch (TException e1) {\r
+                       e1.printStackTrace();\r
+                       status.message.emit(tr("Transaction exception Listing lineked notebooks."));\r
+                       logger.log(logger.LOW, e1.getMessage());\r
+                       return;\r
+               } catch (EDAMNotFoundException e1) {\r
+                       e1.printStackTrace();\r
+                       status.message.emit(tr("EDAM Not Found exception Listing linked notebooks."));\r
+                       logger.log(logger.LOW, e1.getMessage());\r
+               }\r
+    }\r
 }\r