use of com.evernote.thrift.TException 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;
}
use of com.evernote.thrift.TException in project PhotoNoter by yydcdut.
the class RxUser method updateNote2Evernote.
public Observable<Boolean> updateNote2Evernote(String bigPhotoPathWithoutFile, String photoName, String noteTitle, String noteContent) {
return Observable.create(new Observable.OnSubscribe<List<Notebook>>() {
@Override
public void call(Subscriber<? super List<Notebook>> subscriber) {
if (mEvernoteSession == null) {
mEvernoteSession = new EvernoteSession.Builder(mContext).setLocale(Locale.SIMPLIFIED_CHINESE).setEvernoteService(EVERNOTE_SERVICE).setSupportAppLinkedNotebooks(SUPPORT_APP_LINKED_NOTEBOOKS).setForceAuthenticationInThirdPartyApp(true).build(BuildConfig.EVERNOTE_CONSUMER_KEY, BuildConfig.EVERNOTE_CONSUMER_SECRET).asSingleton();
}
EvernoteNoteStoreClient noteStoreClient = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient();
try {
List<Notebook> notebookList = noteStoreClient.listNotebooks();
subscriber.onNext(notebookList);
} catch (EDAMUserException e) {
YLog.e(e);
subscriber.onError(e);
} catch (EDAMSystemException e) {
YLog.e(e);
subscriber.onError(e);
} catch (TException e) {
YLog.e(e);
subscriber.onError(e);
}
subscriber.onCompleted();
}
}).subscribeOn(Schedulers.io()).flatMap(notebooks -> Observable.from(notebooks)).filter(notebook -> notebook.getName().equals(mContext.getResources().getString(R.string.app_name))).lift(new Observable.Operator<String, Notebook>() {
@Override
public Subscriber<? super Notebook> call(Subscriber<? super String> subscriber) {
return new Subscriber<Notebook>() {
private int mInTimes = 0;
@Override
public void onCompleted() {
if (mInTimes == 0) {
Notebook notebook = new Notebook();
notebook.setName(mContext.getResources().getString(R.string.app_name));
EvernoteNoteStoreClient noteStoreClient = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient();
try {
Notebook appNoteBook = noteStoreClient.createNotebook(notebook);
subscriber.onNext(appNoteBook.getGuid());
} catch (EDAMUserException e) {
YLog.e(e);
subscriber.onError(e);
} catch (EDAMSystemException e) {
YLog.e(e);
subscriber.onError(e);
} catch (TException e) {
YLog.e(e);
subscriber.onError(e);
}
}
subscriber.onCompleted();
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Notebook notebook) {
mInTimes++;
subscriber.onNext(notebook.getGuid());
}
};
}
}).map(s -> {
Note note = new Note();
note.setNotebookGuid(s);
return note;
}).lift(new Observable.Operator<Boolean, Note>() {
@Override
public Subscriber<? super Note> call(Subscriber<? super Boolean> subscriber) {
return new Subscriber<Note>() {
@Override
public void onCompleted() {
subscriber.onCompleted();
}
@Override
public void onError(Throwable e) {
subscriber.onError(e);
}
@Override
public void onNext(Note note) {
note.setTitle(noteTitle);
InputStream in = null;
// Hash the data in the image file. The hash is used to reference the file in the ENML note content.
try {
in = new BufferedInputStream(new FileInputStream(bigPhotoPathWithoutFile));
FileData data = new FileData(EvernoteUtil.hash(in), new File(bigPhotoPathWithoutFile));
ResourceAttributes attributes = new ResourceAttributes();
attributes.setFileName(photoName);
// Create a new Resource
Resource resource = new Resource();
resource.setData(data);
resource.setMime("image/jpeg");
resource.setAttributes(attributes);
note.addToResources(resource);
// Set the note's ENML content
String content = EvernoteUtil.NOTE_PREFIX + noteContent + EvernoteUtil.createEnMediaTag(resource) + EvernoteUtil.NOTE_SUFFIX;
note.setContent(content);
EvernoteNoteStoreClient noteStoreClient = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient();
noteStoreClient.createNote(note);
} catch (FileNotFoundException e) {
YLog.e(e);
subscriber.onError(e);
} catch (IOException e) {
YLog.e(e);
subscriber.onError(e);
} catch (EDAMNotFoundException e) {
YLog.e(e);
subscriber.onError(e);
} catch (TException e) {
YLog.e(e);
subscriber.onError(e);
} catch (EDAMUserException e) {
YLog.e(e);
subscriber.onError(e);
} catch (EDAMSystemException e) {
YLog.e(e);
subscriber.onError(e);
} finally {
FilePathUtils.closeStream(in);
}
subscriber.onNext(true);
}
};
}
});
}
use of com.evernote.thrift.TException in project PhotoNoter by yydcdut.
the class EditTextPresenterImpl method doUpdate2Evernote.
private boolean doUpdate2Evernote(String bigPhotoPathWithoutFile, String photoName) {
mRxUser.initEvernoteSession();
boolean isSuccess = true;
try {
EvernoteNoteStoreClient noteStoreClient = EvernoteSession.getInstance().getEvernoteClientFactory().getNoteStoreClient();
List<Notebook> notebookList = noteStoreClient.listNotebooks();
boolean hasNoteBook = false;
Notebook appNoteBook = null;
for (Notebook notebook : notebookList) {
if (notebook.getName().equals(mContext.getResources().getString(R.string.app_name))) {
hasNoteBook = true;
appNoteBook = notebook;
}
}
if (!hasNoteBook) {
Notebook notebook = new Notebook();
notebook.setName(mContext.getResources().getString(R.string.app_name));
appNoteBook = noteStoreClient.createNotebook(notebook);
}
Note note = new Note();
note.setTitle(mEditTextView.getNoteTitle());
if (appNoteBook != null) {
note.setNotebookGuid(appNoteBook.getGuid());
}
InputStream in = null;
try {
// Hash the data in the image file. The hash is used to reference the file in the ENML note content.
in = new BufferedInputStream(new FileInputStream(bigPhotoPathWithoutFile));
FileData data = null;
data = new FileData(EvernoteUtil.hash(in), new File(bigPhotoPathWithoutFile));
ResourceAttributes attributes = new ResourceAttributes();
attributes.setFileName(photoName);
// Create a new Resource
Resource resource = new Resource();
resource.setData(data);
resource.setMime("image/jpeg");
resource.setAttributes(attributes);
note.addToResources(resource);
// Set the note's ENML content
String content = EvernoteUtil.NOTE_PREFIX + mEditTextView.getNoteContent() + EvernoteUtil.createEnMediaTag(resource) + EvernoteUtil.NOTE_SUFFIX;
note.setContent(content);
try {
noteStoreClient.createNote(note);
} catch (EDAMNotFoundException e) {
YLog.e(e);
}
} catch (IOException e) {
YLog.e(e);
isSuccess = false;
} finally {
FilePathUtils.closeStream(in);
}
} catch (EDAMUserException e) {
YLog.e(e);
isSuccess = false;
} catch (EDAMSystemException e) {
YLog.e(e);
isSuccess = false;
} catch (TException e) {
YLog.e(e);
isSuccess = false;
}
return isSuccess;
}
use of com.evernote.thrift.TException in project Notes by lguipeng.
the class BootstrapManager method getBootstrapInfo.
/**
* Makes a web request to get the latest bootstrap information.
* This is a requirement during the oauth process
*
* @return {@link BootstrapInfoWrapper}
* @throws Exception
*/
BootstrapInfoWrapper getBootstrapInfo() throws Exception {
Log.d(LOGTAG, "getBootstrapInfo()");
BootstrapInfo bsInfo = null;
try {
if (mBootstrapServerUsed == null) {
initializeUserStoreAndCheckVersion();
}
bsInfo = mEvernoteSession.getEvernoteClientFactory().getUserStoreClient(getUserStoreUrl(mBootstrapServerUsed), null).getBootstrapInfo(mLocale.toString());
printBootstrapInfo(bsInfo);
} catch (TException e) {
Log.e(LOGTAG, "error getting bootstrap info", e);
}
return new BootstrapInfoWrapper(mBootstrapServerUsed, bsInfo);
}
use of com.evernote.thrift.TException in project Notes by lguipeng.
the class FileData method write.
@Override
public void write(TProtocol oprot) throws TException {
validate();
oprot.writeStructBegin(STRUCT_DESC);
if (this.getBodyHash() != null) {
if (isSetBodyHash()) {
oprot.writeFieldBegin(BODY_HASH_FIELD_DESC);
oprot.writeBinary(ByteBuffer.wrap(this.getBodyHash()));
oprot.writeFieldEnd();
}
}
oprot.writeFieldBegin(SIZE_FIELD_DESC);
oprot.writeI32(this.getSize());
oprot.writeFieldEnd();
if (this.mBodyFile != null && this.mBodyFile.isFile()) {
oprot.writeFieldBegin(BODY_FIELD_DESC);
InputStream s = null;
try {
s = new FileInputStream(mBodyFile);
oprot.writeStream(s, this.mBodyFile.length());
} catch (FileNotFoundException e) {
throw new TException("Failed to write binary body:" + mBodyFile, e);
} finally {
try {
if (s != null) {
s.close();
}
} catch (Exception e) {
}
}
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
Aggregations