Package com.evernote.edam.notestore

Examples of com.evernote.edam.notestore.SyncState


    }

    @Override
    protected void updateConnectorData(final UpdateInfo updateInfo) throws Exception {
        final NoteStoreClient noteStore = getNoteStoreClient(updateInfo);
        final SyncState syncState = noteStore.getSyncState();
        final String lastSyncTimeAtt = guestService.getApiKeyAttribute(updateInfo.apiKey, LAST_SYNC_TIME);
        long lastSyncTime = Long.valueOf(lastSyncTimeAtt);
        final String lastUpdateCountAtt = guestService.getApiKeyAttribute(updateInfo.apiKey, LAST_UPDATE_COUNT);
        long lastUpdateCount = Long.valueOf(lastUpdateCountAtt);
        if (syncState.getFullSyncBefore()>lastSyncTime) {
            // according to the edam sync spec, fullSyncBefore is "the cut-off date for old caching clients
            // to perform an incremental (vs. full) synchronization. This value may correspond to the point
            // where historic data (e.g. regarding expunged objects) was wiped from the account, or possibly
            // the time of a serious server issue that would invalidate client USNs"
            // This means that we are may leave items that the user actually deleted in the database, and thus
            // we need to basically do a history update again
            apiDataService.eraseApiData(updateInfo.apiKey);
            guestService.removeApiKeyAttribute(updateInfo.apiKey.getId(), LAST_SYNC_TIME);
            guestService.removeApiKeyAttribute(updateInfo.apiKey.getId(), LAST_UPDATE_COUNT);
            // let's properly log this
            logger.info("FullSync required for evernote connector, apiKeyId=" + updateInfo.apiKey.getId());
            performSync(updateInfo, noteStore, true);
        }
        else if (syncState.getUpdateCount()==lastUpdateCount)
            // nothing happened since we last updated
            return;
        else
            performSync(updateInfo, noteStore, false);
    }
View Full Code Here


        }
        return chunks;
    }

    private void saveSyncState(final UpdateInfo updateInfo, NoteStoreClient noteStore) throws TException, EDAMUserException, EDAMSystemException {
        final SyncState syncState = noteStore.getSyncState();
        int serviceLastUpdateCount = syncState.getUpdateCount();
        final long serviceLastSyncTime = syncState.getCurrentTime();
        final String lastUpdateCountAtt = String.valueOf(serviceLastUpdateCount);
        guestService.setApiKeyAttribute(updateInfo.apiKey, LAST_UPDATE_COUNT, lastUpdateCountAtt);
        final String lastSyncTimeAtt = String.valueOf(serviceLastSyncTime);
        guestService.setApiKeyAttribute(updateInfo.apiKey, LAST_SYNC_TIME, lastSyncTimeAtt);
    }
View Full Code Here

        enDisconnect();
        return;
      }
     
      // Get sync state
      SyncState syncState = null;
      try
        logger.log(logger.EXTREME, "Getting sync state");
        syncState = noteStore.getSyncState(authToken)
        syncSignal.saveUploadAmount.emit(syncState.getUploaded());
        syncSignal.saveEvernoteUpdateCount.emit(syncState.getUpdateCount());
        evernoteUpdateCount = syncState.getUpdateCount();
      } catch (EDAMUserException e) {
        e.printStackTrace();
        status.message.emit(tr("Error getting sync state! Aborting sync and disconnecting!"));
        syncSignal.errorDisconnect.emit();
        enDisconnect();
        return;
      } catch (EDAMSystemException e) {
        e.printStackTrace();
        status.message.emit(tr("Error getting sync state! Aborting sync and disconnecting!"));
        syncSignal.errorDisconnect.emit();
        enDisconnect();
        return;
      } catch (TException e) {
        e.printStackTrace();
        status.message.emit(tr("Error getting sync state! Aborting sync and disconnecting!"));
        syncSignal.errorDisconnect.emit();
        enDisconnect();
        return;
      }
     
      if (syncState == null) {
        logger.log(logger.EXTREME, "Sync State is null");
        status.message.emit(tr("Syncronization Error!"));
        return;
      }

      // Determine what to do.
      // If we need to do a full sync.
      logger.log(logger.LOW, "Full Sequence Before: " +syncState.getFullSyncBefore());
      logger.log(logger.LOW, "Last Sequence Date: " +sequenceDate);
      logger.log(logger.LOW, "Var Last Sequence Number: " +updateSequenceNumber);
      logger.log(logger.LOW, "DB Last Sequence Number: " + conn.getSyncTable().getUpdateSequenceNumber());
      if (syncState.getFullSyncBefore() > sequenceDate) {
        logger.log(logger.EXTREME, "Full sequence date has expired");
        sequenceDate = 0;
        conn.getSyncTable().setLastSequenceDate(0);
        updateSequenceNumber = 0;
        conn.getSyncTable().setUpdateSequenceNumber(0);
      }
      // Check for "special" sync instructions
      String syncLinked = conn.getSyncTable().getRecord("FullLinkedNotebookSync");
      String syncShared = conn.getSyncTable().getRecord("FullSharedNotebookSync");
      String syncNotebooks = conn.getSyncTable().getRecord("FullNotebookSync");
      String syncInkNoteImages = conn.getSyncTable().getRecord("FullInkNoteImageSync");
      if (syncLinked != null) {
        downloadAllLinkedNotebooks(localNoteStore);
      }
      if (syncShared != null) {
        downloadAllSharedNotebooks(localNoteStore);
      }
      if (syncNotebooks != null) {
        downloadAllNotebooks(localNoteStore);
      }
     
      if (syncInkNoteImages != null) {
        List<String> guids = conn.getNoteTable().noteResourceTable.findInkNotes();
        for (int i=0; i<guids.size(); i++) {
          downloadInkNoteImage(guids.get(i), authToken);
        }
        conn.getSyncTable().deleteRecord("FullInkNoteImageSync");
      }
     
      // If there are remote changes
      logger.log(logger.LOW, "Update Count: " +syncState.getUpdateCount());
      logger.log(logger.LOW, "Last Update Count: " +updateSequenceNumber);
     
      if (syncState.getUpdateCount() > updateSequenceNumber) {
        logger.log(logger.EXTREME, "Refresh needed is true");
        refreshNeeded = true;
        logger.log(logger.EXTREME, "Downloading changes");
        syncRemoteToLocal(localNoteStore);
      }
     
      //*****************************************
      //* Sync linked/shared notebooks
      //*****************************************
      //syncLinkedNotebooks();
      //conn.getNoteTable().getDirty();
      //disableUploads = true;   /// DELETE THIS LINE!!!!
      if (!disableUploads) {
        logger.log(logger.EXTREME, "Uploading changes");
        // Synchronize remote changes
        if (!error)
          syncExpunged(localNoteStore);
        if (!error)
          syncLocalTags(localNoteStore);
        if (!error)
          syncLocalNotebooks(localNoteStore);
        if (!error)
          syncLocalLinkedNotebooks(localNoteStore);
        if (!error)
          syncDeletedNotes(localNoteStore);
        if (!error)
          syncLocalNotes();
        if (!error)
          syncLocalSavedSearches(localNoteStore);
      }
     
      status.message.emit(tr("Cleaning up"));
      List<String> notes = conn.getNoteTable().expungeIgnoreSynchronizedNotes(conn.getSyncTable().getIgnoreRecords("NOTEBOOK"),
          conn.getSyncTable().getIgnoreRecords("TAG"), conn.getSyncTable().getIgnoreRecords("LINKEDNOTEBOOK"));
      if (notes.size() > 0)
        syncSignal.refreshLists.emit();
     
      //*****************************************
      //* End of synchronization
      //*****************************************
      if (refreshNeeded)
        syncSignal.refreshLists.emit();
     
      if (!error) {
        logger.log(logger.LOW, "Sync completed.  Errors=" +error);
        if (!disableUploads)
          status.message.emit(tr("Synchronizing complete"));
        else
          status.message.emit(tr("Download syncronization complete.  Uploads have been disabled."));
       
        logger.log(logger.EXTREME, "Saving sync time");
        if (syncState.getCurrentTime() > sequenceDate)
          sequenceDate = syncState.getCurrentTime();
        if (syncState.getUpdateCount() > updateSequenceNumber)
          updateSequenceNumber = syncState.getUpdateCount();
        conn.getSyncTable().setLastSequenceDate(sequenceDate);
        conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);
      }
    }
    logger.log(logger.HIGH, "Leaving SyncRunner.evernoteSync");
View Full Code Here

           } else {
             logger.log(logger.EXTREME, "Share key is null");
             linkedAuthResult = new AuthenticationResult();
             linkedAuthResult.setAuthenticationToken("");
           }
           SyncState linkedSyncState =
             linkedNoteStore.getLinkedNotebookSyncState(linkedAuthResult.getAuthenticationToken(), books.get(i));
           if (linkedSyncState.getUpdateCount() > lastSequenceNumber) {
             logger.log(logger.EXTREME, "Remote changes found");
             if (lastSyncDate < linkedSyncState.getFullSyncBefore()) {
               lastSequenceNumber = 0;
             }
             logger.log(logger.EXTREME, "Calling syncLinkedNotebook for " +books.get(i).getShareName());
             syncLinkedNotebook(linkedNoteStore, books.get(i),
                 lastSequenceNumber, linkedSyncState.getUpdateCount(), authToken);
           }
         
          // Synchronize local changes
          syncLocalLinkedNoteChanges(linkedNoteStore, books.get(i));
       
View Full Code Here

TOP

Related Classes of com.evernote.edam.notestore.SyncState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.