Search in sources :

Example 1 with NotesMetadataList

use of com.evernote.edam.notestore.NotesMetadataList in project Notes by lguipeng.

the class EvernoteSearchHelper method findAllNotes.

protected List<NotesMetadataList> findAllNotes(Search search, EvernoteNoteStoreClient client, NoteFilter filter) throws Exception {
    List<NotesMetadataList> result = new ArrayList<>();
    final int maxNotes = search.getMaxNotes();
    int offset = search.getOffset();
    int remaining = maxNotes - offset;
    while (remaining > 0) {
        try {
            NotesMetadataList notesMetadata = client.findNotesMetadata(filter, offset, maxNotes, search.getResultSpec());
            remaining = notesMetadata.getTotalNotes() - (notesMetadata.getStartIndex() + notesMetadata.getNotesSize());
            result.add(notesMetadata);
        } catch (EDAMUserException | EDAMSystemException | TException | EDAMNotFoundException e) {
            maybeRethrow(search, e);
            remaining -= search.getPageSize();
        }
        offset += search.getPageSize();
    }
    return result;
}
Also used : TException(com.evernote.thrift.TException) EDAMNotFoundException(com.evernote.edam.error.EDAMNotFoundException) EDAMSystemException(com.evernote.edam.error.EDAMSystemException) ArrayList(java.util.ArrayList) NotesMetadataList(com.evernote.edam.notestore.NotesMetadataList) EDAMUserException(com.evernote.edam.error.EDAMUserException)

Example 2 with NotesMetadataList

use of com.evernote.edam.notestore.NotesMetadataList in project Notes by lguipeng.

the class EverNoteUtils method pullNotes.

public void pullNotes() throws Exception {
    NotesLog.d("");
    NoteFilter noteFilter = new NoteFilter();
    noteFilter.setOrder(NoteSortOrder.UPDATED.getValue());
    String guid = mPreferenceUtils.getStringParam(PreferenceUtils.EVERNOTE_NOTEBOOK_GUID_KEY);
    noteFilter.setNotebookGuid(guid);
    NotesMetadataResultSpec spec = new NotesMetadataResultSpec();
    spec.setIncludeUpdated(true);
    spec.setIncludeCreated(true);
    NoteCollectionCounts counts = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient().findNoteCounts(noteFilter, false);
    List<SNote> sNoteList = mFinalDb.findAllByWhere(SNote.class, "type != " + SNote.NoteType.TRASH.getValue());
    List<String> guids = new ArrayList<>();
    for (SNote note : sNoteList) {
        guids.add(note.getGuid());
    }
    if (counts == null || counts.getNotebookCounts() == null) {
        for (String deleteGuid : guids) {
            deleteLocalNote(deleteGuid);
        }
        return;
    }
    int maxCount = counts.getNotebookCounts().get(guid);
    NotesMetadataList list = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient().findNotesMetadata(noteFilter, 0, maxCount, spec);
    for (NoteMetadata data : list.getNotes()) {
        guids.remove(data.getGuid());
        List<SNote> sNotes = mFinalDb.findAllByWhere(SNote.class, "guid = '" + data.getGuid() + "'");
        if (sNotes != null && sNotes.size() > 0) {
            //update
            SNote sNote = sNotes.get(0);
            if (data.getUpdated() > sNote.getLastOprTime())
                pullUpdateNote(sNote);
        } else {
            //pull
            loadEverNote(data.getGuid());
        }
    }
    if (guids.size() > 0) {
        for (String deleteGuid : guids) {
            deleteLocalNote(deleteGuid);
        }
    }
    NotesLog.d("");
}
Also used : NoteFilter(com.evernote.edam.notestore.NoteFilter) SNote(com.lguipeng.notes.model.SNote) ArrayList(java.util.ArrayList) NotesMetadataList(com.evernote.edam.notestore.NotesMetadataList) NoteMetadata(com.evernote.edam.notestore.NoteMetadata) NoteCollectionCounts(com.evernote.edam.notestore.NoteCollectionCounts) NotesMetadataResultSpec(com.evernote.edam.notestore.NotesMetadataResultSpec)

Aggregations

NotesMetadataList (com.evernote.edam.notestore.NotesMetadataList)2 ArrayList (java.util.ArrayList)2 EDAMNotFoundException (com.evernote.edam.error.EDAMNotFoundException)1 EDAMSystemException (com.evernote.edam.error.EDAMSystemException)1 EDAMUserException (com.evernote.edam.error.EDAMUserException)1 NoteCollectionCounts (com.evernote.edam.notestore.NoteCollectionCounts)1 NoteFilter (com.evernote.edam.notestore.NoteFilter)1 NoteMetadata (com.evernote.edam.notestore.NoteMetadata)1 NotesMetadataResultSpec (com.evernote.edam.notestore.NotesMetadataResultSpec)1 TException (com.evernote.thrift.TException)1 SNote (com.lguipeng.notes.model.SNote)1