OSDN Git Service

Correct error trying to expunge items on Evernote servers that were never created.
authorRandy Baumgarte <randy@fbn.cx>
Tue, 24 Jul 2012 13:08:23 +0000 (09:08 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Tue, 24 Jul 2012 13:08:23 +0000 (09:08 -0400)
src/cx/fbn/nevernote/gui/TagTreeWidget.java
src/cx/fbn/nevernote/oauth/OAuthTokenizer.java
src/cx/fbn/nevernote/sql/NotebookTable.java
src/cx/fbn/nevernote/sql/SavedSearchTable.java
src/cx/fbn/nevernote/sql/TagTable.java
src/cx/fbn/nevernote/threads/SyncRunner.java

index 0633557..d8c8378 100644 (file)
@@ -444,7 +444,7 @@ public class TagTreeWidget extends QTreeWidget {
        }\r
 \r
 \r
-       public void selectSavedSearch(QTreeWidgetItem item) {\r
+       public void selectTag(QTreeWidgetItem item) {\r
                MatchFlags flags = new MatchFlags();\r
                flags.set(MatchFlag.MatchWildcard);\r
                flags.set(MatchFlag.MatchRecursive);\r
index 505857e..0e745ee 100644 (file)
@@ -56,7 +56,6 @@ public class OAuthTokenizer {
                                decoded="";
                        }
                }
-               System.out.println("Tokens found:" +tokens.size());
                String oauth_tokenString = "oauth_token=";
                String edam_shardString = "edam_shard=";
                String edam_userIdString = "edam_userid=";
index 43cf18b..25e4819 100644 (file)
@@ -190,6 +190,8 @@ public class NotebookTable {
        // Delete the notebook based on a guid\r
        public void expungeNotebook(String guid, boolean needsSync) {\r
                boolean check;\r
+               Notebook n;\r
+               n = getNotebook(guid);\r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
 \r
                check = query.prepare("delete from "+dbName+" where guid=:guid");\r
@@ -203,7 +205,7 @@ public class NotebookTable {
                        logger.log(logger.MEDIUM, dbName+" delete failed.");\r
                \r
                // Signal the parent that work needs to be done\r
-               if  (needsSync) {\r
+               if  (needsSync && n!=null && n.getUpdateSequenceNum() > 0) {\r
                        DeletedTable deletedTable = new DeletedTable(logger, db);\r
                        deletedTable.addDeletedItem(guid, dbName);\r
                }\r
@@ -520,6 +522,54 @@ public class NotebookTable {
                }       \r
                return index;   \r
        }\r
+       // Get a list of notes that need to be updated\r
+       public Notebook getNotebook(String guid) {\r
+               Notebook tempNotebook;\r
+               boolean check;\r
+                                               \r
+        NSqlQuery query = new NSqlQuery(db.getConnection());\r
+                                       \r
+               query.prepare("Select guid, sequence, name, defaultNotebook, " +\r
+                               "serviceCreated, serviceUpdated, published, stack, "+\r
+                               "publishinguri, publishingascending, publishingPublicDescription, "+\r
+                               "publishingOrder " +\r
+                               "from "+dbName+" where guid=:guid");\r
+               query.bindValue(":guid", guid);\r
+               check  = query.exec();\r
+               if (!check) \r
+                       logger.log(logger.EXTREME, dbName+" SQL retrieve has failed.");\r
+               while (query.next()) {\r
+                       tempNotebook = new Notebook();\r
+                       tempNotebook.setGuid(query.valueString(0));\r
+                       int sequence = new Integer(query.valueString(1)).intValue();\r
+                       tempNotebook.setUpdateSequenceNum(sequence);\r
+                       tempNotebook.setName(query.valueString(2));\r
+                       \r
+                       DateFormat indfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");\r
+                       try {\r
+                               tempNotebook.setServiceCreated(indfm.parse(query.valueString(4)).getTime());\r
+                               tempNotebook.setServiceUpdated(indfm.parse(query.valueString(5)).getTime());\r
+                       } catch (ParseException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+                       tempNotebook.setPublished(new Boolean(query.valueString(6)));\r
+                       tempNotebook.setStack(query.valueString(7));\r
+                       \r
+                       if (tempNotebook.isPublished()) {\r
+                               Publishing p = new Publishing();\r
+                               p.setUri(query.valueString(8));\r
+                               p.setAscending(query.valueBoolean(9, false));\r
+                               p.setPublicDescription(query.valueString(10));\r
+                               p.setOrder(NoteSortOrder.findByValue(query.valueInteger(11)));\r
+                               if (p.getPublicDescription() != null && p.getPublicDescription().trim().equalsIgnoreCase(""))\r
+                                       p.setPublicDescription(null);\r
+                               tempNotebook.setPublishing(p);\r
+                       }\r
+                       \r
+                       return tempNotebook;\r
+               }       \r
+               return null;    \r
+       }\r
        // This is a convience method to check if a tag exists & update/create based upon it\r
        public void syncNotebook(Notebook notebook, boolean isDirty) {\r
                if (!exists(notebook.getGuid())) {\r
index b85dd65..2f9fea8 100644 (file)
@@ -111,7 +111,7 @@ public class SavedSearchTable {
                                tempSearch.setFormat(QueryFormat.USER);\r
                        else\r
                                tempSearch.setFormat(QueryFormat.SEXP);\r
-                       int sequence = new Integer(query.valueString(4)).intValue();\r
+                       int sequence = new Integer(query.valueInteger(4));\r
                        tempSearch.setUpdateSequenceNum(sequence);\r
                }\r
                return tempSearch;\r
@@ -148,6 +148,7 @@ public class SavedSearchTable {
        // Delete a tag\r
        public void expungeSavedSearch(String guid, boolean needsSync) {\r
                boolean check;\r
+               SavedSearch s = getSavedSearch(guid);\r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
 \r
                check = query.prepare("delete from SavedSearch "\r
@@ -164,7 +165,7 @@ public class SavedSearchTable {
                }\r
 \r
                // Add the work to the parent queue\r
-               if (needsSync) {\r
+               if (needsSync && s != null && s.getUpdateSequenceNum() > 0) {\r
                        DeletedTable del = new DeletedTable(logger, db);\r
                        del.addDeletedItem(guid, "SavedSearch");\r
                }\r
index b783578..7168e87 100644 (file)
@@ -178,6 +178,7 @@ public class TagTable {
        // Delete a tag\r
        public void expungeTag(String guid, boolean needsSync) {\r
                boolean check;\r
+               Tag t = getTag(guid);\r
                \r
                \r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
@@ -206,7 +207,7 @@ public class TagTable {
                        logger.log(logger.MEDIUM, "NoteTags delete failed.");\r
                \r
                // Add the work to the parent queue\r
-               if (needsSync) {\r
+               if (needsSync && t!= null && t.getUpdateSequenceNum() > 0) {\r
                        DeletedTable del = new DeletedTable(logger, db);\r
                        del.addDeletedItem(guid, "Tag");\r
                }\r
index d01faf6..4709e6d 100644 (file)
@@ -205,10 +205,6 @@ public class SyncRunner extends QObject implements Runnable {
                                }\r
                                idle=false;\r
                                error=false;\r
-//                             if (authRefreshNeeded == true || !isConnected) {\r
-//                                     logger.log(logger.EXTREME, "Refreshing connection");\r
-//                                     refreshConnection();\r
-//                             }\r
                                if (syncNeeded) {\r
                                        logger.log(logger.EXTREME, "SyncNeeded is true");\r
                                        refreshNeeded=false;\r
@@ -367,6 +363,8 @@ public class SyncRunner extends QObject implements Runnable {
                        // If we need to do a full sync.\r
                        logger.log(logger.LOW, "Full Sequence Before: " +syncState.getFullSyncBefore());\r
                        logger.log(logger.LOW, "Last Sequence Date: " +sequenceDate);\r
+                       logger.log(logger.LOW, "Var Last Sequence Number: " +updateSequenceNumber);\r
+                       logger.log(logger.LOW, "DB Last Sequence Number: " + conn.getSyncTable().getUpdateSequenceNumber());\r
                        if (syncState.getFullSyncBefore() > sequenceDate) {\r
                                logger.log(logger.EXTREME, "Full sequence date has expired");\r
                                sequenceDate = 0;\r
@@ -595,22 +593,18 @@ public class SyncRunner extends QObject implements Runnable {
                for (int i=0; i<notes.size() && keepRunning; i++) {\r
                        syncLocalNote(localNoteStore, notes.get(i), authToken);\r
                }\r
-               logger.log(logger.HIGH, "Entering SyncRunner.syncNotes");\r
+               logger.log(logger.HIGH, "Leaving SyncRunner.syncNotes");\r
 \r
        }\r
        // Sync notes with Evernote\r
        private void syncLocalNote(Client noteStore, Note enNote, String token) {\r
                logger.log(logger.HIGH, "Entering SyncRunner.syncNotes");\r
                status.message.emit(tr("Sending local notes."));\r
-\r
-//             if (authRefreshNeeded)\r
-//                     if (!refreshConnection())\r
-//                             return;\r
                        \r
                if (enNote.isActive()) {\r
                        try {\r
                                if (enNote.getUpdateSequenceNum() > 0) {\r
-                                       logger.log(logger.EXTREME, "Active dirty note found - non new" +enNote.getGuid());\r
+                                       logger.log(logger.EXTREME, "Active dirty note found - non new - " +enNote.getGuid());\r
                                        logger.log(logger.EXTREME, "Fetching note content");\r
                                        enNote = getNoteContent(enNote);\r
                                        logger.log(logger.MEDIUM, "Updating note : "+ enNote.getGuid() +" <title>" +enNote.getTitle()+"</title>");\r
@@ -972,7 +966,7 @@ public class SyncRunner extends QObject implements Runnable {
                                                enSearch = noteStore.createSearch(authToken, enSearch);\r
                                        sequence = enSearch.getUpdateSequenceNum();\r
                                        logger.log(logger.EXTREME, "Updating tag guid in local database");\r
-                                       conn.getTagTable().updateTagGuid(oldGuid, enSearch.getGuid());\r
+                                       conn.getSavedSearchTable().updateSavedSearchGuid(oldGuid, enSearch.getGuid());\r
                                }\r
                                logger.log(logger.EXTREME, "Updating tag sequence in local database");\r
                                conn.getSavedSearchTable().updateSavedSearchSequence(enSearch.getGuid(), sequence);\r
@@ -1034,6 +1028,7 @@ public class SyncRunner extends QObject implements Runnable {
 //                             conn.beginTransaction();\r
                                logger.log(logger.EXTREME, "Getting chunk from Evernote");\r
                                chunk = noteStore.getSyncChunk(authToken, sequence, chunkSize, fullSync);\r
+                               logger.log(logger.LOW, "Chunk High Sequence: " +chunk.getChunkHighUSN());\r
                        } catch (EDAMUserException e) {\r
                                error = true;\r
                                e.printStackTrace();\r